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

@varnames_interface: handle polynomial_ring(QQ, :x => 3) better #1759

Open
fingolfin opened this issue Jul 26, 2024 · 0 comments
Open

@varnames_interface: handle polynomial_ring(QQ, :x => 3) better #1759

fingolfin opened this issue Jul 26, 2024 · 0 comments

Comments

@fingolfin
Copy link
Member

Right now polynomial_ring(QQ, :x => 3) leads to an error that is not very helpful:

julia> polynomial_ring(QQ, :x => 3)
ERROR: MethodError: no method matching iterate(::Symbol)

Closest candidates are:
  iterate(::Core.Compiler.InstructionStream, ::Int64)
   @ Base show.jl:2778
  iterate(::Core.Compiler.InstructionStream)
   @ Base show.jl:2778
  iterate(::Oscar.EdgeIterator)
   @ Oscar ~/Projekte/OSCAR/Oscar.spielwiese/src/Combinatorics/Graphs/functions.jl:352
  ...

Stacktrace:
  [1] iterate
    @ ./generator.jl:44 [inlined]
  [2] iterate
    @ ./iterators.jl:1202 [inlined]
  [3] iterate
    @ ./iterators.jl:1196 [inlined]
  [4] _collect(::Type{Symbol}, itr::Base.Iterators.Flatten{Base.Generator{…}}, isz::Base.SizeUnknown)
    @ Base ./array.jl:700
  [5] collect(::Type{Symbol}, itr::Base.Iterators.Flatten{Base.Generator{Tuple{…}, AbstractAlgebra.var"#392#393"{…}}})
    @ Base ./array.jl:694
  [6] variable_names(as::Tuple{Pair{Symbol, Int64}}, brackets::Val{true})
    @ AbstractAlgebra ~/.julia/packages/AbstractAlgebra/tABFQ/src/misc/VarNames.jl:73
  [7] variable_names(as::Pair{Symbol, Int64})
    @ AbstractAlgebra ~/.julia/packages/AbstractAlgebra/tABFQ/src/misc/VarNames.jl:71
  [8] polynomial_ring(R::QQField, s::Tuple{Pair{Symbol, Int64}}; kv::@Kwargs{})
    @ AbstractAlgebra ~/.julia/packages/AbstractAlgebra/tABFQ/src/misc/VarNames.jl:305
  [9] polynomial_ring(R::QQField, s::Tuple{Pair{Symbol, Int64}})
    @ AbstractAlgebra ~/.julia/packages/AbstractAlgebra/tABFQ/src/misc/VarNames.jl:304
 [10] polynomial_ring(::QQField, ::Pair{Symbol, Int64}; kv::@Kwargs{})
    @ AbstractAlgebra ~/.julia/packages/AbstractAlgebra/tABFQ/src/misc/VarNames.jl:302
 [11] top-level scope
    @ REPL[63]:1
Some type information was truncated. Use `show(err)` to see complete types.

I'd like to improve this. The two major options are:

  1. catch the problem earlier and give a more helpful error,
  2. pick an interpretation and make it work
    1. perhaps it should be the same as polynomial_ring(QQ, :x => 1:3)
    2. perhaps it should be the same as polynomial_ring(QQ, :x => 3:3)

The fact that there are at least two interpretations might suggest we should prefer the error. Then again I am not sure how natural each is? For me I comparatively often make this mistake because I think "I want three x-variables", so I use :x => 3 when I really mean :x => 1:3. The only reason I am considering the other option is that it is based on Julia semantics: one can "iterate" over an integer, and the integer is treated as if it was a 0-dimensional container with a single entry (itself). Honestly I don't like this, but it is what it is, so one might just lean into it...

Still the safe route would be 1. An error can always be turned into working code later on.

Any thoughts on this?

@fingolfin fingolfin changed the title handle polynomial_ring(QQ, :x => 3) better @varnames_interface: handle polynomial_ring(QQ, :x => 3) better Jul 29, 2024
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

No branches or pull requests

1 participant