Open kaelingre opened 1 week ago
Could you provide a minimal working example written in C?
Here's the simplest C example where this happened to me:
#include <flint/fmpz_mpoly.h>
int main() {
fmpz_mpoly_ctx_struct ctx;
fmpz_mpoly_ctx_init(&ctx, 2, ORD_LEX);
fmpz_mpoly_struct x1;
fmpz_mpoly_init(&x1, &ctx);
fmpz_mpoly_gen(&x1, 0, &ctx);
fmpz_mpoly_struct x2;
fmpz_mpoly_init(&x2, &ctx);
fmpz_mpoly_gen(&x2, 1, &ctx);
//p = x1 + x2
fmpz_mpoly_struct p;
fmpz_mpoly_init(&p, &ctx);
fmpz_mpoly_add(&p, &x1, &x2, &ctx);
printf("p = ");
fmpz_mpoly_print_pretty(&p, NULL, &ctx);
printf("\n");
//make the trivial replacement x1->x1, x2->x2
fmpz_mpoly_struct replData[2];
fmpz_mpoly_struct* repl[2];
repl[0] = &replData[0];
repl[1] = &replData[1];
fmpz_mpoly_init(repl[0], &ctx);
fmpz_mpoly_gen(repl[0], 0, &ctx);
fmpz_mpoly_init(repl[1], &ctx);
fmpz_mpoly_gen(repl[1], 0, &ctx);
printf("success: %d\n", fmpz_mpoly_compose_fmpz_mpoly(&p, &p, repl, &ctx, &ctx));
printf("p = ");
fmpz_mpoly_print_pretty(&p, NULL, &ctx);
printf("\n");
return 0;
}
which outputs
p = x1+x2
success: 1
p = x1^3305670466+x1
If this is indeed not the intended behavior I'd also be happy to track down the issue.
Yeah, it looks like there should be an aliasing check here.
Alright, the problem is that the function _fmpz_mpoly_compose_mat(A,B,...) requires A!=B. There's an assert which would have caught the above problem, had I turned on asserts.
Are the first two polynomials in the function fmpz_mpoly_compose_fmpz_mpoly allowed to be the same? I haven't found anything in the documentation that would tell me otherwise. If so, the following (C++) code leads to random (incorrect) output:
Leads for example to an output of the form:
Also note that uncommenting the line in the for loop will produce a correct output. If one is not intended to have input=output it would be useful to know, for which functions this is forbidden.