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

Support for polytopes with (real) QQBar coefficients? #3286

Closed
fingolfin opened this issue Jan 31, 2024 · 2 comments · Fixed by #3308
Closed

Support for polytopes with (real) QQBar coefficients? #3286

fingolfin opened this issue Jan 31, 2024 · 2 comments · Fixed by #3308
Assignees
Labels
topic: polyhedral geometry Issue concerns polyhedral geometry code

Comments

@fingolfin
Copy link
Member

Our implementation of the algebraic closure of the rationals, QQBar / CalciumQQBar, is quite nice and it comes with an "automatic" real or complex embedding of its elements.

It would be quite handy if one could directly take a bunch of vectors over this field, and create polyhedra/polytopes from this. E.g. construct a convex hull and visualize it. I guess this is related to currently ongoing work for doing this for embedded number fields.

Example:

julia> e = one(CalciumQQBar)
Root 1.00000 of x - 1

julia> s, c = sinpi(2*e/5), cospi(2*e/5)
(Root 0.951057 of 16x^4 - 20x^2 + 5, Root 0.309017 of 4x^2 + 2x - 1)

julia> pts = [ [e, e], [s,c], [c,s] ]
3-element Vector{Vector{qqbar}}:
 [Root 1.00000 of x - 1, Root 1.00000 of x - 1]
 [Root 0.951057 of 16x^4 - 20x^2 + 5, Root 0.309017 of 4x^2 + 2x - 1]
 [Root 0.309017 of 4x^2 + 2x - 1, Root 0.951057 of 16x^4 - 20x^2 + 5]

julia> P = convex_hull(pts)
ERROR: MethodError: Cannot `convert` an object of type Int64 to an object of type qqbar

This initial error is easy to fix, just something missing in Nemo (see Nemocas/Nemo.jl#1650).

But after adding the missing conversion method, there are more errors inside PolyhedralGeometry specific code I am not familiar with. So in particular I don't know hard it would be to do in general.

But in this case, I managed to proceed quite nicely after converting to floating point:

julia> Base.convert(::Type{Float64}, x::qqbar) = Float64(ArbField(64)(x))  # TODO: add to Nemo

julia> Vector{Vector{Float64}}(pts)
3-element Vector{Vector{Float64}}:
 [1.0, 1.0]
 [0.9510565162951535, 0.30901699437494745]
 [0.30901699437494745, 0.9510565162951535]

julia> P = convex_hull(Vector{Vector{Float64}}(pts))
Polyhedron in ambient dimension 2

julia> visualize(P)

which gave me
Screen Shot 2024-01-31 at 15 34 41

@fingolfin fingolfin added the topic: polyhedral geometry Issue concerns polyhedral geometry code label Jan 31, 2024
@benlorenz
Copy link
Member

I will try to add this in during the refactoring. To make it work nicely it will need to be added to a few type collections.

But the manual approach currently also fails due to some type / constructor issues, I will collect these and create an issue:

julia> pts = [ e e e; e s c; e c s]
3×3 Matrix{qqbar}:
 Root 1.00000 of x - 1  Root 1.00000 of x - 1               Root 1.00000 of x - 1
 Root 1.00000 of x - 1  Root 0.951057 of 16x^4 - 20x^2 + 5  Root 0.309017 of 4x^2 + 2x - 1
 Root 1.00000 of x - 1  Root 0.309017 of 4x^2 + 2x - 1      Root 0.951057 of 16x^4 - 20x^2 + 5

julia> ppts = Polymake.Matrix{Polymake.OscarNumber}(pts)
WARNING: cfunction: return type of cmp does not match
pm::Matrix<common::OscarNumber>
(Root 1.00000 of x - 1) (Root 1.00000 of x - 1) (Root 1.00000 of x - 1)
(Root 1.00000 of x - 1) (Root 0.951057 of 16x^4 - 20x^2 + 5) (Root 0.309017 of 4x^2 + 2x - 1)
(Root 1.00000 of x - 1) (Root 0.309017 of 4x^2 + 2x - 1) (Root 0.951057 of 16x^4 - 20x^2 + 5)


julia> pp = Polymake.polytope.Polytope{Polymake.OscarNumber}(POINTS=ppts)
ERROR: TypeError: in cfunction, expected Int64, got a value of type Int32

Here the issue is that Base.cmp for qqbar returns an Int32 instead of the expected Int64, which could be fixed by a cast there or a wrapper function in the OscarNumber code.

I also needed something like this to allow the embedding to work with the OscarNumber:

(::Nemo.CalciumQQBarField)(r::Rational{BigInt}) = qqbar(fmpq(r))

(i.e. we need a constructor from Rational{BigInt}.)

There will probably be more small things missing to get this working.

@benlorenz benlorenz self-assigned this Jan 31, 2024
@fingolfin
Copy link
Member Author

@benlorenz great! And yeah, we need Rational->QQBar conversion, already requested on Nemocas/Nemo.jl#1650 -- it shouldn't be hard either, but right now I have other things to finish (and perhaps we can convince someone else to work on that ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: polyhedral geometry Issue concerns polyhedral geometry code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants