Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segfault in factor_squarefree for univariate polynomial #1594

Closed
fingolfin opened this issue Dec 9, 2023 · 1 comment · Fixed by #1596
Closed

Segfault in factor_squarefree for univariate polynomial #1594

fingolfin opened this issue Dec 9, 2023 · 1 comment · Fixed by #1596

Comments

@fingolfin
Copy link
Member

It doesn't like factoring zero:

julia> R,x = QQ[:x]
(Univariate polynomial ring in x over QQ, x)

julia> factor_squarefree(zero(R))

[10714] signal (11.2): Segmentation fault: 11
in expression starting at REPL[4]:1
fmpz_sgn at /Users/mhorn/.julia/artifacts/93c4c327196f73ed4a7e268093e3a7f4097b744d/lib/libflint.dylib (unknown line)
fmpz_poly_factor_squarefree at /Users/mhorn/.julia/artifacts/93c4c327196f73ed4a7e268093e3a7f4097b744d/lib/libflint.dylib (unknown line)
Allocations: 4346002 (Pool: 4343463; Big: 2539); GC: 6
Segmentation fault: 11

It should be trivial to catch the input zero before passing to FLINT to fix this issue. But it is not clear to me what the correct output is supposed to be. The AA documentation is far too vague to clarify this. And experiments are not conclusive:

# factoring integer 0 gives an error
julia> factor(0)
ERROR: ArgumentError: Argument is not non-zero

# factor_squarefree for integers is not implemented at all 
julia> factor_squarefree(0)
ERROR: function factor_squarefree is not implemented for argument
Int64: 0

julia> factor_squarefree(ZZ(0))
ERROR: function factor_squarefree is not implemented for argument
ZZRingElem: 0

# factoring a multivariate zero polynomial gives a `Fac` factorization with "unit" equal to... zero ??
julia> R,(x,y) = QQ[:x,:y]
(Multivariate polynomial ring in 2 variables over QQ, QQMPolyRingElem[x, y])

julia> factor(zero(R))
0

julia> factor_squarefree(zero(R))
0

julia> R,(x,y) = GF(5)[:x,:y]
(Multivariate polynomial ring in 2 variables over GF(5), fpMPolyRingElem[x, y])

julia> factor(zero(R))
0

julia> factor_squarefree(zero(R))
0

# same behavior for univariate polynomial over a finite field
julia> R,x = GF(5)[:x]
(Univariate polynomial ring in x over GF(5), x)

julia> factor(zero(R))
0

julia> factor_squarefree(zero(R))
0

So based on a majority vote... a factorization with unit 0 is to be returned?!

@thofma
Copy link
Member

thofma commented Dec 9, 2023

For the segfault see #1510 (comment) (upstream issue flintlib/flint#1414).

I think in #1510 we came to the conclusion, that factor_squarefree(R(0)) should throw an error like factor(R(0)) does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants