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

`getindex` for vector creation

Open albinahlback opened this issue 8 months ago • 5 comments

With

julia> @which Int[1, 2, 3, 4]
getindex(::Type{T}, vals...) where T
     @ Base array.jl:397

we expect to create an array. However, something like

julia> ZZ[1, 2, 3, 4]
julia> ZZ[ZZ(1), ZZ(2), ZZ(3), ZZ(4)]

does not work, but should?

albinahlback avatar Apr 03 '25 11:04 albinahlback

Should it, though? The Julia syntax is for T[1,2,3] where T is a type. While we indeed allow specifying a ring instead of a type in many situations, I don't think that's an automatism.

Generally we don't want people to use a Vector{BigInt} resp. (in Nemo) a Vector{ZZRingElem}, as such this might even be counter productive?

I am open to discuss this and be convinced otherwise, though :-)

Ping @fieker @thofma

fingolfin avatar Apr 03 '25 14:04 fingolfin

I don't mind too much that people create Vector{ZZRingElem}. When I wrote in #2053 that it is ambiguous, I did not mean in the compiler ambiguity sense, but that is hard to explain to a user why R[1] and R[1, 2] do different things. For example, ZZ[1] throws, but ZZ[1, 2] gives a Vector.

thofma avatar Apr 03 '25 16:04 thofma

Generally we don't want people to use a Vector{BigInt} resp. (in Nemo) a Vector{ZZRingElem}, as such this might even be counter productive?

We could make a C-style vector instead of Julia vectors.

But I'm fine with closing this as well.

Edit: We could make an $m \times 1$ matrix. But, if we close this, I think one should not be able to write ZZ[1 2; 3 4].

albinahlback avatar Apr 03 '25 20:04 albinahlback

there is a c-style Vector{ZZRingElem} in Hecke:src/Sparse/ZZRow.jl - it has its own pittfalls

fieker avatar Apr 04 '25 06:04 fieker

What is the rational behind R[1] giving the first generator? After some thinking, I think I'd prefer to abandon this instead.

albinahlback avatar Apr 04 '25 12:04 albinahlback