oscar-system / Singular.jl

Julia package for the Singular library
Other
33 stars 33 forks source link

Inconsistent parameterisation of types #33

Closed wbhart closed 2 years ago

wbhart commented 6 years ago

Currently the type of a Singular matrix over Q is smatrix{spoly{n_Q}}:

R, (x, y) = PolynomialRing(QQ, ["x", "y"])

I = Ideal(R, x, y)
M = Singular.Matrix(I)

 typeof(M)

But the type of a Singular vector over Q is svector{n_Q}:

R, (x, y) = PolynomialRing(QQ, ["x", "y"])

v = Singular.Vector([x + 1, x*y + 1, y])

typeof(v)

On the other hand, the entries in the Singular vector do not actually seem to be polynomials, but something else.

We should make a decision on what Singular.jl will be, just a system for polynomial rings, or will it eventually have other kinds of rings, i.e. what can be put into a matrix and what can be put into a vector. Which rings? Just polynomial rings? If so, the spoly can be omitted from the parameterisation in the type, as per svector currently. If not, we should include the spoly in the parameterisation of the type, as per smatrix currently.

wbhart commented 6 years ago

There is also the consideration that to integrate with Nemo, it may be necessary to give the longer parameterisation, so that Nemo can know what the types of the entries of a Singular matrix of vector are, so that the Nemo generic code can work with them, once the relevant interface is implemented by Singular.jl.

On the other hand, this heavily depends on whether these Singular types should be intended to work with generic code from Nemo, or whether they should be considered internal implementation details of Singular itself.

hannes14 commented 6 years ago

The type of a Singular vector (svector) has to include the ring as its components are elements of a Singular polynomial ring (for example must have an monomial ordering). And more: also the monomial ordering is in fact a monomial ordering for monomials of a svector (includes, for example such things like position-over-term etc.). In Singular spoly and svector are in principle the same (in order to apply several algorithms like groebner basis, syzygy, normal form to both of them). Maybe Singular.Vector is something different?

hannes14 commented 6 years ago

Matrices are different: their entries are always spoly (never svector) and mainly used to convert to/from smodule: I would prefer matrices in Nemo for regular operation on matrices (and have a conversion to/from the Singular types)

wbhart commented 6 years ago

Yeah, Singular.Vector isn't the right name either (I just changed it from svector which is the name of the type of a Singular vector). At this level we shouldn't be doing coercion using the name of the type we want to coerce to, but the name of the parent object we want to coerce to.

The vector type I'm talking about here is supposed to represent an element of a free module over the given polynomial ring.

So I guess the code above should really say:

R, (x, y) = PolynomialRing(QQ, ["x", "y"])
S = FreeModule(R, 3)

v = S([x + 1, x*y + 1, y])

typeof(v)

I will at least fix that, so it works. But that is a different issue of course.

wbhart commented 6 years ago

"Matrices are different: their entries are always spoly".

What mathematically are the entries of an svector? It's an element of a free module over which ring? A polynomial ring? Or can you also have a free module over Q directly, say?

hannes14 commented 6 years ago

An svector is a sum of products of the a coefficient from a coefficient domain (like Z,Q), power of variables (from a polynomial ring) and a statndard generator of the free module. Therefore an svector is mathematically an element of the freemodule. It has no entries, but con be converted to a vector, whose elements are from the polynomial ring (mathematically by finding the coefficients of standard generators of the free module) (see function Array{T <: Nemo.RingElem}(v::svector{T}) and function svector{T <: Nemo.RingElem}(a::Array{spoly{T}, 1}) in Singular/src/module/vector.jl) In Singular you have free modules only over polynomial rings. A free module over Q can only be represented (in Singular) as a free module over Q[t} and not using t.

fingolfin commented 2 years ago

This seems to have been resolved:

julia> R, (x, y) = PolynomialRing(QQ, ["x", "y"])
(Singular Polynomial Ring (QQ),(x,y),(dp(2),C), spoly{n_Q}[x, y])

julia> S = FreeModule(R, 3)
Free Module of rank 3 over Singular Polynomial Ring (QQ),(x,y),(dp(2),C)

julia> v = S([x + 1, x*y + 1, y])
x*y*gen(2)+x*gen(1)+y*gen(3)+gen(2)+gen(1)

julia> typeof(v)
svector{spoly{n_Q}}

Or also this:

julia> R, (x, y) = PolynomialRing(QQ, ["x", "y"])
(Singular Polynomial Ring (QQ),(x,y),(dp(2),C), spoly{n_Q}[x, y])

julia> v1 = vector(R, x + 1, x*y + 1, y)
x*y*gen(2)+x*gen(1)+y*gen(3)+gen(2)+gen(1)

julia> typeof(v1)
svector{spoly{n_Q}}

... and the type is now "consistent" with that of the matrix.