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

confusion on the return of collect(permutation group) #345

Closed
tthsqe12 opened this issue Mar 16, 2021 · 4 comments
Closed

confusion on the return of collect(permutation group) #345

tthsqe12 opened this issue Mar 16, 2021 · 4 comments

Comments

@tthsqe12
Copy link
Contributor

I have observed this behavior before and was wondering if it was intended:

julia> G = SymmetricGroup(3)
Full symmetric group over 3 elements

julia> collect(G)
6-element Vector{Perm{Int64}}:
 ()
 (1,2)
 (1,3,2)
 (2,3)
 (1,2,3)
 (1,3)

julia> Zx,x=ZZ["x"]; k,a=number_field(x^4+10x^2+2); G,_=galois_group(k)
(Group([ (1,2), (3,4), (1,3)(2,4) ]), Galois Context for x^4 + 10*x^2 + 2 and prime 11)

julia> collect(G)
8-element Vector{Any}:
 ()
 (3,4)
 (1,2)
 (1,2)(3,4)
 (1,3)(2,4)
 (1,3,2,4)
 (1,4,2,3)
 (1,4)(2,3)

The problem here is the Vector{Any} return type. It is my understanding that once this is the type of an object you cannot call methods declared like f(::Vector{PermGroupElem}) on it. Even more mysterious is that the following does get the correct array type:

julia> [g for g in G]
8-element Vector{PermGroupElem}:
 ()
 (3,4)
 (1,2)
 (1,2)(3,4)
 (1,3)(2,4)
 (1,3,2,4)
 (1,4,2,3)
 (1,4)(2,3)
@tthsqe12
Copy link
Contributor Author

my package status:

(@v1.6) pkg> status
      Status `~/.julia/environments/v1.6/Project.toml`
  [c3fe647b] AbstractAlgebra v0.14.0
  [1f15a43c] CxxWrap v0.11.2
  [e30172f5] Documenter v0.26.3
  [3e1990a7] Hecke v0.9.6
  [7073ff75] IJulia v1.23.2
  [2edaba10] Nemo v0.21.0 `~/.julia/dev/Nemo`
  [f1435218] Oscar v0.5.2-DEV `~/.julia/dev/Oscar`
  [295af30f] Revise v3.1.14
  [bcd08a7b] Singular v0.4.7 `~/.julia/dev/Singular`
  [2913bbd2] StatsBase v0.33.3
  [43d676ae] Singular_jll v402.0.104+0
  [9a3f8284] Random
  [8dfed614] Test

@fingolfin
Copy link
Member

SymmetricGroup is a command (or rather, type) from AbstractAlgebra, I think, and we are not really using it in Oscar (so we should not be exporting it -- that's a bug). There, use symmetric_group instead. With that, I get:

julia> G = symmetric_group(3)
Sym( [ 1 .. 3 ] )

julia> collect(G)
6-element Vector{Any}:
 ()
 (2,3)
 (1,3)
 (1,3,2)
 (1,2,3)
 (1,2)

Which is consistent with the output of galois_group, but of course the Any is still undesired.

To fix this, I think we must defined a suitable eltype method (perhaps there's a different / better way? Let me know, folks). Like this:

julia> Base.eltype(::Type{PermGroup}) = PermGroupElem

julia> collect(G)
6-element Vector{PermGroupElem}:
 ()
 (2,3)
 (1,3)
 (1,3,2)
 (1,2,3)
 (1,2)

@GDeFranceschi can you perhaps add such Base.eltypes methods for our various container types in the groups part of Oscar (groups, cosets, double cosets, GSets, ...) together with suitable tests (i.e., something like @test typeof(collect(G)) == Vector{PermGroupElem})

@GDeFranceschi
Copy link
Contributor

For some of these already exists elem_type. For these types, do I just put eltype = elem_type?

@fingolfin
Copy link
Member

Resolved:

julia> G = symmetric_group(3)
Sym( [ 1 .. 3 ] )

julia> collect(G)
6-element Vector{PermGroupElem}:
 ()
 (2,3)
 (1,3)
 (1,3,2)
 (1,2,3)
 (1,2)

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

No branches or pull requests

3 participants