Opened 2 years ago

Closed 11 days ago

#22574 closed enhancement (fixed)

Add .change_ring() method for polyhedra

Reported by: mforets Owned by:
Priority: major Milestone: sage-8.7
Component: geometry Keywords: days84, polytope
Cc: mkoeppe, jipilab Merged in:
Authors: Laith Rastanawi Reviewers: Jean-Philippe Labbé
Report Upstream: N/A Work issues:
Branch: c9b92db (Commits) Commit: c9b92dbc55f09e73e00c307bf19fa59d52d898e0
Dependencies: Stopgaps:

Description (last modified by jipilab)

Polyhedra can be defined in different rings, and this method allows to transform between rings (compare to the similar feature for matrices).

TODO:

  • Once done, add it to tutorial

Change History (13)

comment:1 Changed 2 years ago by jipilab

There is currently:

sage: P = Polyhedron(vertices=[(1,0), (0,1)], rays=[(1,1)], base_ring=ZZ);  P
A 2-dimensional polyhedron in ZZ^2 defined as the convex hull of 2 vertices and 1 ray
sage: P_QQ = P.base_extend(QQ); P_QQ
A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 2 vertices and 1 ray

Could there be a boolean parameter such as inplace (similar as in graphs and simplicial complexes...) to determine if one should create a new object or just change the base ring?

I am wondering how much changing the base ring changes the internals of the polyhedron object. Would many things break? We can try and see...

comment:2 follow-up: Changed 2 years ago by mkoeppe

I think there is no value in trying to implement inplace -- the various base rings are handled by different classes after all. Moreover, right now polyhedra are immutable - and it would be strange to be able to mutate the base ring but nothing else.

comment:3 in reply to: ↑ 2 Changed 2 years ago by jipilab

Replying to mkoeppe:

I think there is no value in trying to implement inplace -- the various base rings are handled by different classes after all. Moreover, right now polyhedra are immutable - and it would be strange to be able to mutate the base ring but nothing else.

Agreed.

Further, I don't really like the fact that hidden in base_extend is the possibility to change the backend, which as a matter of fact doesn't work. This is not user-friendly to say the least. I would therefore also deprecate the keyword completely and point to a .change_backend() method (see #22575). I guess that such a method will take care to handle the modifications of base ring if need be...

comment:4 Changed 13 months ago by jipilab

  • Description modified (diff)

comment:5 Changed 6 weeks ago by gh-LaisRast

  • Branch set to u/gh-LaisRast/change_ring
  • Commit set to 5f617670bb3af64f3fb1519f562a5e4dd5666c4d

New commits:

5f61767add change_ring to base.py and parent.py

comment:6 Changed 6 weeks ago by git

  • Commit changed from 5f617670bb3af64f3fb1519f562a5e4dd5666c4d to 6cdd9d551bbbb0521c1b08aa959ffeb51ce299f3

Branch pushed to git repo; I updated commit sha1. New commits:

6cdd9d5add documentation

comment:7 Changed 6 weeks ago by gh-LaisRast

  • Status changed from new to needs_review

comment:8 Changed 5 weeks ago by jipilab

  • Status changed from needs_review to needs_work

Hi,

Here are a couple of things I saw:

  • Adapt the convention for the input, see for example vertex_facet_graph:
    +        - ``backend`` -- the new backend, see
    +            :func:`~sage.geometry.polyhedron.constructor.Polyhedron`.
    +            If ``None`` (the default), use the same defaulting behavior
    +            as described there; it is not attempted to keep the same
    +            backend.
    
  • It would be good to have more examples with all the potential pairings.
  • Further, it would be nice to handle the potential error in the function when coercing from QQ to ZZ and return a message like: 'Can not change the ring to ZZ: a coordinate is rational'. And these examples should be added after the examples that do work.

comment:9 Changed 4 weeks ago by git

  • Commit changed from 6cdd9d551bbbb0521c1b08aa959ffeb51ce299f3 to c9b92dbc55f09e73e00c307bf19fa59d52d898e0

Branch pushed to git repo; I updated commit sha1. New commits:

c9b92dbAdd more debug output/Add more documentation

comment:10 Changed 4 weeks ago by gh-LaisRast

  • Milestone changed from sage-7.6 to sage-8.7
  • Status changed from needs_work to needs_review

comment:11 Changed 3 weeks ago by jipilab

  • Authors set to Laith Rastanawi
  • Reviewers set to Jean-Philippe Labbé

comment:12 Changed 13 days ago by jipilab

  • Status changed from needs_review to positive_review

This looks good to me.

comment:13 Changed 11 days ago by vbraun

  • Branch changed from u/gh-LaisRast/change_ring to c9b92dbc55f09e73e00c307bf19fa59d52d898e0
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.