Nemo.jl icon indicating copy to clipboard operation
Nemo.jl copied to clipboard

Difference between factor and roots

Open kirtsar opened this issue 5 years ago • 3 comments

I found some inconsistency in the API of Nemo. If we have the polynomial f(X) over some ring (QQ, ZZ, others), we can use only factor (no roots function). If we use CC (for example ComplexField(64), then we can use roots only (no factoring). Also there is something strange in AbstractAlgebra.QQ and Nemo.QQ (i mean: should they really be different?). I collect all of these in the code below:

using AbstractAlgebra
R, x = QQ["X"]
factor(x^2 - x - 1)      # not working -- no factor in AbstractAlgebra
using Nemo
factor(x^2 - x - 1)      # not working --for some mysterious reason Nemo.QQ != AbstractAlgebra.QQ
R, x = Nemo.QQ["X"]
factor(x^2 - x - 1)      # works well
roots(x^2 - x - 1)      # not working -- no roots for QQ
CC = ComplexField(64)
R, x = CC["X"]
factor(x^2 - x - 1)      # not working -- maybe because it has the different nature (?)
# answer in the form root +- epsilon
roots(x^2 - x - 1)      # works fine

kirtsar avatar Jul 30 '19 05:07 kirtsar

Nemo adds functionality to AbstractAlgebra by wrapping high performance C libraries. So no mystery about the differences.

As for factoring vs roots, it boils down to what is implemented.

Feel free to contribute additional functionality, of course.

wbhart avatar Jul 30 '19 08:07 wbhart

Oh, maybe it isn't clear: you shouldn't do "using AbstractAlgebra" in the same session as "using Nemo". The Nemo package is designed to simply replace AbstractAlgebra once you find you need its functionality. It automatically loads AbstractAlgebra behind the scenes and replaces functionality where needed. So just try your examples with "using Nemo" in a fresh Julia session. Of course there are still some differences based on what people have contributed and how much time they have.

(If you really need access to AbstractAlgebra, you can do "import AbstractAlgebra" after "using Nemo", then typically "Generic.blah(blah)" to call generic AbstractAlgebra functionality. But you have to know what you are doing if you want to do this. Typically it shouldn't be needed for most users.)

wbhart avatar Jul 30 '19 08:07 wbhart

in Hecke, recently, we've also added a high-performance roots function for fmpq_poly (and fmpz_poly) as this was required by a different problem. This can, of course, be moved to Nemo...

fieker avatar Sep 03 '19 18:09 fieker

Situation is better these days:

julia> using Nemo

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

julia> factor(x^2 - x - 1)
1 * (X^2 - X - 1)

julia> roots(x^2 - x - 1)
QQFieldElem[]

julia> roots(x^2 - 2x + 1)
1-element Vector{QQFieldElem}:
 1

julia> CC = ComplexField()
Complex field

julia> R, x = CC["X"]
(Univariate polynomial ring in X over CC, X)

julia> factor(x^2 - x - 1)
ERROR: function factor is not implemented for argument
ComplexPolyRingElem: X^2 - 1.0000000000000000000*X - 1.0000000000000000000

The difference between AA and Nemo was already explained.

Since CC is an inexact field I don't think factoring makes too much sense?

Overall I think this can be closed now.

fingolfin avatar Dec 05 '24 22:12 fingolfin

I'm happy for this to be closed, but for CC, if we can compute roots, we can write down the factorisation... Furthermore, we support, hopefully, factorisation of rational polynomials over C and R via absolute factorisation and/ or embeddings

fieker avatar Dec 06 '24 07:12 fieker