Opened 2 years ago

Closed 20 months ago

Last modified 20 months ago

#24837 closed enhancement (fixed)

Improve the output of repr_pretty_Hrepresentation for Polyhedron

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: Moritz Firsching, Travis Scrimshaw
Report Upstream: N/A Work issues:
Branch: b1ae583 (Commits) Commit:
Dependencies: #22572 Stopgaps:

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
sage: print(P.Hrepresentation_str(style='positive'))
x0 + x1 + x2 == 6       
           5 >= x1 + x2 
           3 >= x2      
           3 >= x1      
          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 (24)

comment:1 Changed 2 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

comment:2 Changed 2 years ago by jipilab

  • Description modified (diff)

comment:3 Changed 2 years ago by jipilab

  • Summary changed from Improve the output of repr_pretty for Polyhedron to Improve the output of repr_pretty_Hrepresentation for Polyhedron

comment:4 Changed 2 years ago by git

  • Commit changed from 7cf1a562e411bb1307b906c173d04f177d66fc0f to 132c27af3c97ad7892cfdc2242259802175cdc0d

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

132c27aMerge branch 'develop' into 24837

comment:5 Changed 2 years ago by git

  • Commit changed from 132c27af3c97ad7892cfdc2242259802175cdc0d to 3fea478c2c433fa7976f8ba1fda76684850b511f

Branch pushed to git repo; I updated commit sha1. Last 10 new commits:

231cd56deleted trailing whitespace
f685c64fixed some typos in lectures.rst
7f5e125fixed typos in polyhedra_quickref.rst
bd6c356LateX -> LaTeX in polytope_tikz.rst
b1ce45bSeveral other corrections
d526f70renamed tutorial files
d7896f8Merge branch 'develop' into 22572
597b802Merge branch sage8.2.rc1 into 22572
066c7a5Merge branch tutorial into 24837
3fea478Adapted tutorial

comment:6 Changed 2 years ago by jipilab

  • Keywords IMA-PolyGeom added

comment:7 Changed 2 years ago by moritz

  • Branch changed from u/jipilab/24837 to u/moritz/24837

comment:8 Changed 2 years ago by moritz

  • Commit changed from 3fea478c2c433fa7976f8ba1fda76684850b511f to f98b24a1e9ae874ce7f4a4a0b8d086619132d328
  • Reviewers set to Moritz Firsching

There was one doctest failing and a bit whitespace left. Other than that I think this is good to go. Set it on positive review on my behalf if you agree!


New commits:

f98b24afix a doctest and remove trailing whitespace

comment:9 Changed 2 years ago by jipilab

  • Status changed from needs_review to positive_review

The last bot test looks good. I'm setting it to positive review.

comment:10 Changed 2 years ago by jipilab

  • Milestone changed from sage-8.2 to sage-8.3

comment:11 Changed 2 years ago by vbraun

  • Status changed from positive_review to needs_work

Merge conflict

comment:12 Changed 23 months ago by jipilab

  • Branch changed from u/moritz/24837 to u/jipilab/24837
  • Commit changed from f98b24a1e9ae874ce7f4a4a0b8d086619132d328 to e6ba9cc64d2fe33381bfdf4e0b1ca7c4802b9531
  • Status changed from needs_work to needs_review

Solved the conflicts with Sage8.3.b1.


New commits:

e6ba9ccMerged with Sage 8.3.b1

comment:13 Changed 21 months ago by jipilab

Ping!

comment:14 Changed 21 months ago by tscrim

  • Reviewers changed from Moritz Firsching to Moritz Firsching, Travis Scrimshaw
  • Status changed from needs_review to needs_work

Two trivial failures; see patchbot for details:

sage -t --long --warn-long 49.3 src/doc/en/thematic_tutorials/geometry/tips.rst  # 2 doctests failed

comment:15 Changed 21 months ago by git

  • Commit changed from e6ba9cc64d2fe33381bfdf4e0b1ca7c4802b9531 to 736f60f40460584e93c64a2b5bc30ae133800fe2

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

736f60ffixed doctests

comment:16 Changed 21 months ago by jipilab

  • Status changed from needs_work to needs_review

Should now work...

comment:17 follow-up: Changed 21 months ago by jipilab

There are two pyflakes warnings about the usage of QQ and RDF.

Question: if they are used in doctests, that's not necessary to import them, correct?

If so, I'd just remove them...

comment:18 in reply to: ↑ 17 ; follow-up: Changed 21 months ago by tscrim

  • Cc tscrim added

Replying to jipilab:

There are two pyflakes warnings about the usage of QQ and RDF.

Question: if they are used in doctests, that's not necessary to import them, correct?

If so, I'd just remove them...

Please do. What is imported in a file and what used in doctests, which is the global namespace, are essentially independent. Once you remove them, you can set a positive review on my behalf.

comment:19 in reply to: ↑ 18 Changed 21 months ago by jipilab

Replying to tscrim:

Replying to jipilab:

There are two pyflakes warnings about the usage of QQ and RDF.

Question: if they are used in doctests, that's not necessary to import them, correct?

If so, I'd just remove them...

Please do. What is imported in a file and what used in doctests, which is the global namespace, are essentially independent. Once you remove them, you can set a positive review on my behalf.

Sounds good! I just wanted to make sure...

comment:20 Changed 21 months ago by git

  • Commit changed from 736f60f40460584e93c64a2b5bc30ae133800fe2 to b1ae58333b87efe5574bf876c6d53cddd3f8420d

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

b1ae583Removed unnecessary import

comment:21 Changed 21 months ago by jipilab

  • Status changed from needs_review to positive_review

Done! Thanks for the review!

comment:22 Changed 20 months ago by vdelecroix

  • Milestone changed from sage-8.3 to sage-8.4

update milestone 8.3 -> 8.4

comment:23 Changed 20 months ago by vbraun

  • Branch changed from u/jipilab/24837 to b1ae58333b87efe5574bf876c6d53cddd3f8420d
  • Resolution set to fixed
  • Status changed from positive_review to closed

comment:24 Changed 20 months ago by dkrenn

  • Commit b1ae58333b87efe5574bf876c6d53cddd3f8420d deleted

There is a follow-up ticket #26141 concerning the code quality.

Note: See TracTickets for help on using tickets.