flintlib / flint

FLINT (Fast Library for Number Theory)
http://www.flintlib.org
GNU Lesser General Public License v3.0
401 stars 235 forks source link

fmpz_mpoly_pfrac_init: internal error #1998

Closed F-Feng closed 1 month ago

F-Feng commented 1 month ago

Dear flint developers,

I encountered an internal error when calling fmpz_mpoly_factor on a polynomial. Here is an example to reproduce it.

#include "flint/fmpz.h"
#include "flint/fmpz_mpoly_factor.h"

int main() {
    fmpz_mpoly_ctx_t ctx;
    fmpz_mpoly_t p;
    fmpz_mpoly_factor_t f;

    //const char * vars[] = {"x1", "x2", "x3", "x4", "x5"}; // no error
    const char * vars[] = {"x1", "x5", "x3", "x4", "x2"}; // fmpz_mpoly_pfrac_init: internal error

    fmpz_mpoly_ctx_init(ctx, 5, ORD_LEX);
    fmpz_mpoly_init(p, ctx);
    fmpz_mpoly_factor_init(f, ctx);

    int nok = fmpz_mpoly_set_str_pretty(p, "-2*x1*x5^2*x3*x4*x2^3+24*x1^4*x5^2*x3^3*x4*x2-4*x5^2*x4^3*x2^3-40*x1^2*x5^2*x3^4*x4^2*x2-6*x1^4*x5^2*x4^2*x2^2-4*x5^2*x3*x4^2*x2^2+14*x1*x5^2*x3^3*x2^2+36*x1*x5^2*x3^5*x4^2*x2^2+10*x5^2*x3^2*x4*x2^3-64*x5^2*x3^5*x4*x2^3+17*x1^2*x5^2*x4^4*x2^3-36*x1*x5^2*x3^2*x4^2*x2^2+29*x1^2*x5^2*x4^5*x2^2-36*x1^4*x5^2*x3^2*x4^2-6*x1^4*x5^2*x3*x4*x2^2-14*x1^3*x5^2*x3*x4^2-6*x1^3*x5^2*x3^4*x2^2-33*x1^3*x5^2*x3^2*x4*x2^2-4*x1^2*x5^2*x3*x4^5*x2-44*x1^4*x5^2*x3^2*x4^3*x2-132*x1^3*x5^2*x3*x4^3*x2-120*x5^2*x3^3*x4^3*x2^3+8*x1^3*x5^2*x3*x4^2*x2^3+4*x1*x5^2*x4^2*x2^2+6*x1^5*x5^2*x3*x4+50*x1*x5^2*x3^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*x4^3*x2-13*x5^2*x3^6*x4*x2^2-2*x5^2*x3^7*x2^2-70*x1*x5^2*x3^5*x4*x2^2-36*x5^2*x3^2*x4^2*x2^3+16*x1^3*x5^2*x4^2*x2^2+44*x1^2*x5^2*x3^4*x4*x2-20*x1^2*x5^2*x3^2*x4^4*x2-26*x1^4*x5^2*x3^3*x4^2*x2-8*x5^2*x3*x4^6*x2^2+22*x1*x5^2*x3*x4^2*x2^3-2*x1^3*x5^2*x3*x4*x2^3-140*x1*x5^2*x3^3*x4^3*x2^2+2*x1^3*x5^2*x4^2-x1^2*x5^2*x3^2*x2^3+30*x1^4*x5^2*x3*x4^2+7*x1^2*x5^2*x3^3*x2+24*x1^3*x5^2*x3^2*x4^2+24*x1^4*x5^2*x3*x4^2*x2^2+108*x1^3*x5^2*x3^2*x4^2*x2^2-8*x1^4*x5^2*x4^5*x2+x1^2*x5^2*x3^2*x4+6*x1^3*x5^2*x3^3*x2^2+8*x1^6*x5^2*x3*x4^2+46*x1^2*x5^2*x3^3*x4^2*x2-4*x1^4*x5^2*x3^4*x4*x2+56*x1^3*x5^2*x3*x4^4*x2-14*x1*x5^2*x3^5*x2^3-13*x5^2*x3^6*x2^3-6*x5^2*x4^5*x2^2-13*x1^5*x5^2*x3^2*x4+45*x5^2*x3^3*x4^4*x2^3+80*x1^2*x5^2*x3*x4^2*x2^2+5*x1^2*x5^2*x4^2*x2+6*x5^2*x4^4*x2^3-6*x1^5*x5^2*x4^2*x2+60*x5^2*x3^4*x4^3*x2^3-32*x1*x5^2*x3^4*x2^2-16*x1^2*x5^2*x4^3*x2^3-10*x1^2*x5^2*x3^2*x4*x2^3", vars, ctx);
    if(nok) {
        flint_printf("fmpz_mpoly_set_str_pretty failed.\n");
        fflush(stdout);
        flint_abort();
    }

    if (!fmpz_mpoly_factor(f, p, ctx)) {
        flint_printf("fmpz_mpoly_factor failed.\n");
        fflush(stdout);
        flint_abort();
    }

    fmpz_mpoly_clear(p, ctx);
    fmpz_mpoly_factor_clear(f, ctx);
    fmpz_mpoly_ctx_clear(ctx);

    flint_cleanup_master();

    return 0;
}

PS: If I change the order of elements in the vars, no error occurs.

Best regards, Feng

albinahlback commented 1 month ago

That's a long polynomial! Can you print the exact error message you get? What version of FLINT are you using?

It shouldn't error inside fmpz_mpoly_pfrac_init. I suspect fmpz_mpoly_set_str_pretty is wrong in that case.

F-Feng commented 1 month ago

Apologies for the lengthy polynomial. I encountered this issue during my research, which is why I have included the entire polynomial here.

I am using flint-3.1.3, and the complete error message from the terminal appears as follows:

Flint exception (General error):
    fmpz_mpoly_pfrac_init: internal errorAborted (core dumped)

PS: The function fmpz_mpoly_set_str_pretty returns 0, indicating that fmpz_mpoly_set_str_pretty may work in this case.

albinahlback commented 1 month ago

Not sure if we will be able to solve this quickly. If you are able to answer these questions, it could be helpful in investigating this:

F-Feng commented 1 month ago

Thank you for your response. Please take your time. I hope the following information may be helpful.

F-Feng commented 1 month ago

By the way, here is the factorized output for the polynomial:

tthsqe12 commented 1 month ago

This one doesn't look too bad to fix. While I am installing 3.1.3, could you, @F-Feng, change the string in fmpz_mpoly_set_str_pretty to the more wieldy factored form you just displayed? It is highly unlikely the set_str function has a bug.

F-Feng commented 1 month ago

@tthsqe12 Thanks a lot, and here is the string in the factored form,

"-((-1+x3+x4)^2*(x3+x4)*(-x1+x1^2-x2+x1*x2+x2*x3+x2*x4)*(-(x1*x2*x3)+x1^2*x2*x3-x2^2*x3+x1*x2^2*x3-2*x2*x3^2+3*x1*x2*x3^2-x1^2*x2*x3^2+4*x2^2*x3^2-x1*x2^2*x3^2+2*x2*x3^3-2*x1*x2*x3^3-3*x2^2*x3^3+2*x1^2*x4-4*x1^3*x4+2*x1^4*x4+3*x1*x2*x4-7*x1^2*x2*x4+4*x1^3*x2*x4+x2^2*x4-3*x1*x2^2*x4+2*x1^2*x2^2*x4+x1*x3*x4-2*x1^2*x3*x4+x1^3*x3*x4-3*x2*x3*x4-x1*x2*x3*x4+4*x1^2*x2*x3*x4+3*x2^2*x3*x4+3*x1*x2^2*x3*x4+5*x2*x3^2*x4-5*x1*x2*x3^2*x4-6*x2^2*x3^2*x4+x1*x4^2-2*x1^2*x4^2+x1^3*x4^2-x2*x4^2-4*x1*x2*x4^2+5*x1^2*x2*x4^2-x2^2*x4^2+4*x1*x2^2*x4^2+4*x2*x3*x4^2-4*x1*x2*x3*x4^2-3*x2^2*x3*x4^2+x2*x4^3-x1*x2*x4^3)*x5^2)"