Opened 3 years ago

Last modified 3 years ago

#24837 closed enhancement

Improve the output of repr_pretty for Polyhedron — at Version 1

Reported by: jipilab Owned by:
Priority: major Milestone: sage-8.4
Component: geometry Keywords: days93, IMA-PolyGeom
Cc: vdelecroix, moritz, tscrim Merged in:
Authors: Jean-Philippe Labbé Reviewers:
Report Upstream: N/A Work issues:
Branch: u/jipilab/24837 (Commits, GitHub, GitLab) Commit: 7cf1a562e411bb1307b906c173d04f177d66fc0f
Dependencies: #22572 Stopgaps:

Status badges

Description (last modified by jipilab)

Following #22572, we can improve the output of the pretty print:

    sage: Cube = polytopes.cube()
    sage: TCube = Cube.truncation()
    sage: Nice_repr = TCube.repr_pretty_Hrepresentation(separator='\n')
    sage: print(Nice_repr)
    1 >= x0
    1 >= x1
    3*x1 + 7 >= 3*x0 + 3*x2
    x0 + 1 >= 0
    x1 + 1 >= 0
    3*x0 + 7 >= 3*x1 + 3*x2
    3*x0 + 3*x1 + 7 >= 3*x2
    3*x0 + 3*x2 + 7 >= 3*x1
    3*x0 + 3*x1 + 3*x2 + 7 >= 0
    x2 + 1 >= 0
    1 >= x2
    3*x1 + 3*x2 + 7 >= 3*x0
    3*x2 + 7 >= 3*x0 + 3*x1
    7 >= 3*x0 + 3*x1 + 3*x2

In the new version it gives:

    sage: print(TCube.Hrepresentation_str())
                    -x0 >= -1 
                    -x1 >= -1 
    -3*x0 + 3*x1 - 3*x2 >= -7 
                     x0 >= -1 
                     x1 >= -1 
     3*x0 - 3*x1 - 3*x2 >= -7 
     3*x0 + 3*x1 - 3*x2 >= -7 
     3*x0 - 3*x1 + 3*x2 >= -7 
     3*x0 + 3*x1 + 3*x2 >= -7 
                     x2 >= -1 
                    -x2 >= -1 
    -3*x0 + 3*x1 + 3*x2 >= -7 
    -3*x0 - 3*x1 + 3*x2 >= -7 
    -3*x0 - 3*x1 - 3*x2 >= -7

    sage: print(TCube.Hrepresentation_str(latex=True))
    \begin{array}{rcl}
                                   -x_{0} & \geq & -1 \\
                                   -x_{1} & \geq & -1 \\
    -3 \, x_{0} + 3 \, x_{1} - 3 \, x_{2} & \geq & -7 \\
                                    x_{0} & \geq & -1 \\
                                    x_{1} & \geq & -1 \\
     3 \, x_{0} - 3 \, x_{1} - 3 \, x_{2} & \geq & -7 \\
     3 \, x_{0} + 3 \, x_{1} - 3 \, x_{2} & \geq & -7 \\
     3 \, x_{0} - 3 \, x_{1} + 3 \, x_{2} & \geq & -7 \\
     3 \, x_{0} + 3 \, x_{1} + 3 \, x_{2} & \geq & -7 \\
                                    x_{2} & \geq & -1 \\
                                   -x_{2} & \geq & -1 \\
    -3 \, x_{0} + 3 \, x_{1} + 3 \, x_{2} & \geq & -7 \\
    -3 \, x_{0} - 3 \, x_{1} + 3 \, x_{2} & \geq & -7 \\
    -3 \, x_{0} - 3 \, x_{1} - 3 \, x_{2} & \geq & -7 
    \end{array}

The style parameter allows to change the way to print the H-relations:

sage: P = polytopes.permutahedron(3)
sage: print(P.Hrepresentation_str(style='<='))
-x0 - x1 - x2 == -6 
      x1 + x2 <=  5 
           x2 <=  3 
           x1 <=  3 
          -x1 <= -1 
     -x1 - x2 <= -3 
          -x2 <= -1

In order to make the function more apparent, deprecation of the current function is perhaps a good idea and change the name to Hrepresentation_str.

Change History (1)

comment:1 Changed 3 years ago by jipilab

  • Authors set to Jean-Philippe Labbé
  • Branch set to u/jipilab/24837
  • Commit set to 7cf1a562e411bb1307b906c173d04f177d66fc0f
  • Dependencies set to #22572
  • Description modified (diff)
  • Status changed from new to needs_review

Once the tutorial is merged in #22572, we should change the "tips" page accordingly...


New commits:

7cf1a56first version
Note: See TracTickets for help on using tickets.