Sage: Ticket #12872: A show method for permutations
https://trac.sagemath.org/ticket/12872
<p>
Following the discussion that took place there [1], this patch adds a .show() method to the Permutation class, to obtain drawings like the own we can see there [2].
</p>
<p>
Nathann
</p>
<p>
[1] <a class="ext-link" href="https://groups.google.com/d/topic/sage-combinat-devel/vdfE7iaJTxs/discussion"><span class="icon"></span>https://groups.google.com/d/topic/sage-combinat-devel/vdfE7iaJTxs/discussion</a>
</p>
<p>
[2] <a class="ext-link" href="http://upload.wikimedia.org/wikipedia/en/7/78/Permutation_graph.svg"><span class="icon"></span>http://upload.wikimedia.org/wikipedia/en/7/78/Permutation_graph.svg</a>
</p>
en-usSagehttps://trac.sagemath.org/chrome/site/logo_sagemath_trac.png
https://trac.sagemath.org/ticket/12872
Trac 1.1.6ncohenTue, 24 Apr 2012 10:32:48 GMTdescription changed
https://trac.sagemath.org/ticket/12872#comment:1
https://trac.sagemath.org/ticket/12872#comment:1
<ul>
<li><strong>description</strong>
modified (<a href="/ticket/12872?action=diff&version=1">diff</a>)
</li>
</ul>
TicketncohenTue, 24 Apr 2012 10:50:41 GMTstatus changed; cc set
https://trac.sagemath.org/ticket/12872#comment:2
https://trac.sagemath.org/ticket/12872#comment:2
<ul>
<li><strong>cc</strong>
<em>wdj</em> <em>fhivert</em> added
</li>
<li><strong>status</strong>
changed from <em>new</em> to <em>needs_review</em>
</li>
</ul>
<p>
Now needs a review ! And comments too, if you do not agree with the patch <code>:-)</code>
</p>
<p>
Nathann
</p>
TicketncohenTue, 24 Apr 2012 10:51:20 GMTdescription changed
https://trac.sagemath.org/ticket/12872#comment:3
https://trac.sagemath.org/ticket/12872#comment:3
<ul>
<li><strong>description</strong>
modified (<a href="/ticket/12872?action=diff&version=3">diff</a>)
</li>
</ul>
TicketwdjTue, 24 Apr 2012 12:20:47 GMT
https://trac.sagemath.org/ticket/12872#comment:4
https://trac.sagemath.org/ticket/12872#comment:4
<p>
Testing now, but some comments:
</p>
<p>
(1) I don't understand the line 1166 (inversion_list = []). Am I missing something?
</p>
<p>
(2) In the examples, there is only one:-) What do you think of
the following idea: In the examples, compare your graph with
what you get using show <a class="missing wiki">BipartiteGraph?</a>, as below? Note the difference
in the orientation of the graph. (I prefer the orientation in the
bipartite graph plot personally.) Just food for thought. I'm attaching two plots, one is your plot, re-oriented to match the graph plot, and the other is the graph plot.
</p>
<pre class="wiki">sage: p = Permutations(10).random_element(); p
[5, 10, 4, 8, 3, 1, 9, 6, 2, 7]
sage: E = [(i, 10+p(i)) for i in range(1,11)]
sage: G = BipartiteGraph(E); G.show()
sage: p.show()
sage: G = BipartiteGraph(E); G.show()
sage: p.show()
</pre>
TicketwdjTue, 24 Apr 2012 12:21:42 GMTattachment set
https://trac.sagemath.org/ticket/12872
https://trac.sagemath.org/ticket/12872
<ul>
<li><strong>attachment</strong>
set to <em>swap-diagram-nathann.png</em>
</li>
</ul>
<p>
reoriented diagram plot
</p>
TicketwdjTue, 24 Apr 2012 12:22:11 GMTattachment set
https://trac.sagemath.org/ticket/12872
https://trac.sagemath.org/ticket/12872
<ul>
<li><strong>attachment</strong>
set to <em>swap-diagram-sage.png</em>
</li>
</ul>
<p>
bipartite example plot (same permutation as other plot)
</p>
TicketncohenTue, 24 Apr 2012 12:33:35 GMT
https://trac.sagemath.org/ticket/12872#comment:5
https://trac.sagemath.org/ticket/12872#comment:5
<blockquote class="citation">
<p>
(1) I don't understand the line 1166 (inversion_list = []). Am I missing something?
</p>
</blockquote>
<p>
*Sigh*
</p>
<p>
No, you are right <code>:-)</code>
</p>
<blockquote class="citation">
<p>
(2) In the examples, there is only one:-) What do you think of
the following idea:
</p>
</blockquote>
<p>
Right ! What do you think of this patch ? <code>:-)</code>
</p>
<p>
Nathann
</p>
TicketncohenTue, 24 Apr 2012 12:41:24 GMT
https://trac.sagemath.org/ticket/12872#comment:6
https://trac.sagemath.org/ticket/12872#comment:6
<p>
Here it is !
</p>
TicketwdjTue, 24 Apr 2012 13:57:33 GMT
https://trac.sagemath.org/ticket/12872#comment:7
https://trac.sagemath.org/ticket/12872#comment:7
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/12872#comment:6" title="Comment 6">ncohen</a>:
</p>
<blockquote class="citation">
<p>
Here it is !
</p>
</blockquote>
<p>
Thanks very much!
However, the labels (0-9) do not match the permutation set (1-10). Shouldn't they match?
</p>
TicketncohenTue, 24 Apr 2012 13:59:36 GMT
https://trac.sagemath.org/ticket/12872#comment:8
https://trac.sagemath.org/ticket/12872#comment:8
<p>
Well, for me the problems is that permutations do not match the natural choice, which is 0-9 <code>:-P</code>
</p>
<p>
But you are right of course, and it is now fixed.
</p>
<p>
Nathann
</p>
TickethivertTue, 24 Apr 2012 15:11:48 GMT
https://trac.sagemath.org/ticket/12872#comment:9
https://trac.sagemath.org/ticket/12872#comment:9
<p>
Hi Nathann,
</p>
<p>
Your drawing are very cool ! I'm not completely sure this is what I expected by typing <code>p.show()</code>. Maybe, it's worth asking on sage-combinat-devel for a better name.
</p>
<p>
Florent
</p>
TickethivertTue, 24 Apr 2012 15:12:04 GMTcc changed
https://trac.sagemath.org/ticket/12872#comment:10
https://trac.sagemath.org/ticket/12872#comment:10
<ul>
<li><strong>cc</strong>
<em>sage-combinat</em> added
</li>
</ul>
TicketncohenTue, 24 Apr 2012 15:16:21 GMT
https://trac.sagemath.org/ticket/12872#comment:11
https://trac.sagemath.org/ticket/12872#comment:11
<p>
Well, I am not sure either and perhaps you have in mind another representation that would fit well in Permutation.show. What I know though, is that the drawing we have now would *NEVER* be found by an interested user unless it can be reached by Permutation.show (I do not even know if this drawing has a name, Jason says that the name he uses is non-standard, ...), and so the best for me is to have some arguments in Permutation.show() that would yield different kinds of drawings.
</p>
<p>
Do we get this patch inside of Sage while we wait for another type of drawing to be added ? I'm writing to sage-combinat-devel in the meantime !
</p>
<p>
Nathann
</p>
TicketncohenTue, 24 Apr 2012 15:19:42 GMTattachment set
https://trac.sagemath.org/ticket/12872
https://trac.sagemath.org/ticket/12872
<ul>
<li><strong>attachment</strong>
set to <em>tmp_1.png</em>
</li>
</ul>
TicketncohenWed, 25 Apr 2012 08:44:52 GMTattachment set
https://trac.sagemath.org/ticket/12872
https://trac.sagemath.org/ticket/12872
<ul>
<li><strong>attachment</strong>
set to <em>1.png</em>
</li>
</ul>
TicketncohenWed, 25 Apr 2012 08:45:00 GMTattachment set
https://trac.sagemath.org/ticket/12872
https://trac.sagemath.org/ticket/12872
<ul>
<li><strong>attachment</strong>
set to <em>2.png</em>
</li>
</ul>
TicketncohenWed, 25 Apr 2012 08:45:06 GMTattachment set
https://trac.sagemath.org/ticket/12872
https://trac.sagemath.org/ticket/12872
<ul>
<li><strong>attachment</strong>
set to <em>3.png</em>
</li>
</ul>
TicketncohenWed, 25 Apr 2012 08:45:13 GMTattachment set
https://trac.sagemath.org/ticket/12872
https://trac.sagemath.org/ticket/12872
<ul>
<li><strong>attachment</strong>
set to <em>4.png</em>
</li>
</ul>
TicketwdjWed, 25 Apr 2012 16:48:00 GMT
https://trac.sagemath.org/ticket/12872#comment:12
https://trac.sagemath.org/ticket/12872#comment:12
<p>
This last patch passed all tests on 5.0.b10. I like the drawings now:-)
</p>
TicketdcoudertSat, 28 Apr 2012 08:13:58 GMT
https://trac.sagemath.org/ticket/12872#comment:13
https://trac.sagemath.org/ticket/12872#comment:13
<p>
Hello,
</p>
<p>
I'm able to install the patch on 5.0.beta14, but shouldn't you had some tests to the function?
</p>
<p>
Also:
</p>
<ul><li>paralell -> parallel
</li><li>why are you using "chord-diagram" instead of "circular"?
</li><li>You could use capitalize() in tests to ease usage.
</li></ul>
TicketncohenSat, 28 Apr 2012 08:34:28 GMT
https://trac.sagemath.org/ticket/12872#comment:14
https://trac.sagemath.org/ticket/12872#comment:14
<p>
Hellooooooooo !!!
</p>
<blockquote class="citation">
<p>
but shouldn't you had some tests to the function?
</p>
</blockquote>
<p>
Well, there are 4 ! Of course the image are not "checked", but the code is run anyway and nothing crashes.. That's more or less all we can do with the docstring system :-/
</p>
<blockquote class="citation">
<ul><li>paralell -> parallel
</li></ul></blockquote>
<p>
Arggggggggggggggggggggg !!!
</p>
<blockquote class="citation">
<ul><li>why are you using "chord-diagram" instead of "circular"?
</li></ul></blockquote>
<p>
Oh. Well, because it is the word that the guys from Sage-combinat picked the most naturally. I like permutations but that's their stuff much more than mine, so that they hold for True is true for me <code>:-D</code>
</p>
<blockquote class="citation">
<ul><li>You could use capitalize() in tests to ease usage.
</li></ul></blockquote>
<p>
Hmmmm. Well, I think that it had some meaning to do this for our LP solvers because we never know which letters should be upper case and which one are not (Gurobi or GUROBI ? Cplex or CPLEX), but let's not add a layer of administration to *all* the functions that take a parameter like that. I added a "else" statement though, so that there is an exception raised if the given string does not match any of the good ones. These arguments are always lower-case anyway.
</p>
<p>
Patch updated !
</p>
<p>
Nathann
</p>
TicketdcoudertSat, 28 Apr 2012 09:27:36 GMT
https://trac.sagemath.org/ticket/12872#comment:15
https://trac.sagemath.org/ticket/12872#comment:15
<p>
OK (install, tests, docbuild, etc.), so it remains to wait for answers from sage-combinat.
</p>
TicketncohenSat, 28 Apr 2012 09:34:53 GMT
https://trac.sagemath.org/ticket/12872#comment:16
https://trac.sagemath.org/ticket/12872#comment:16
<p>
? To what do you expect answers ?
</p>
TicketdcoudertSat, 28 Apr 2012 09:36:36 GMT
https://trac.sagemath.org/ticket/12872#comment:17
https://trac.sagemath.org/ticket/12872#comment:17
<p>
It's written above: "Do we get this patch inside of Sage while we wait for another type of drawing to be added ? I'm writing to sage-combinat-devel in the meantime ! "
</p>
<p>
So what's the feedback?
</p>
TicketncohenSat, 28 Apr 2012 10:03:15 GMT
https://trac.sagemath.org/ticket/12872#comment:18
https://trac.sagemath.org/ticket/12872#comment:18
<p>
Oh, sorry. Of course when you re-upload a patch all the previous times when you uploaded it disappear. Actually, in this patch there was at first only the "braid" drawing, and people on sage-combinat said that the most natural was to plot th disjoint union of circuits, and also the chord-diagram. So I updated my patch like that and the default drawing is now the circuit thing, with the braid only as an option. The braid was the only one implemented at first, and the only one I was personally interested in having <code>:-)</code>
</p>
<p>
Nathann
</p>
TicketdcoudertSat, 28 Apr 2012 10:15:00 GMTreviewer set
https://trac.sagemath.org/ticket/12872#comment:19
https://trac.sagemath.org/ticket/12872#comment:19
<ul>
<li><strong>reviewer</strong>
set to <em>David Coudert</em>
</li>
</ul>
<p>
I was about to give positive review when I saw line 1169 "orizontally". Please add an 'h' ;-)
</p>
TicketncohenSat, 28 Apr 2012 10:16:58 GMT
https://trac.sagemath.org/ticket/12872#comment:20
https://trac.sagemath.org/ticket/12872#comment:20
<p>
Done !
</p>
TicketdcoudertSat, 28 Apr 2012 10:20:05 GMT
https://trac.sagemath.org/ticket/12872#comment:21
https://trac.sagemath.org/ticket/12872#comment:21
<p>
No!
</p>
TicketncohenSat, 28 Apr 2012 10:21:32 GMT
https://trac.sagemath.org/ticket/12872#comment:22
https://trac.sagemath.org/ticket/12872#comment:22
<p>
Right... qrefresh <code>:-P</code>
</p>
TicketncohenSat, 28 Apr 2012 10:21:44 GMTattachment set
https://trac.sagemath.org/ticket/12872
https://trac.sagemath.org/ticket/12872
<ul>
<li><strong>attachment</strong>
set to <em>trac_12872.patch</em>
</li>
</ul>
TicketdcoudertSat, 28 Apr 2012 10:23:55 GMTstatus changed
https://trac.sagemath.org/ticket/12872#comment:23
https://trac.sagemath.org/ticket/12872#comment:23
<ul>
<li><strong>status</strong>
changed from <em>needs_review</em> to <em>positive_review</em>
</li>
</ul>
<p>
Nice. For me the patch is OK, so I give positive review.
D.
</p>
TicketncohenSat, 28 Apr 2012 10:30:12 GMT
https://trac.sagemath.org/ticket/12872#comment:24
https://trac.sagemath.org/ticket/12872#comment:24
<p>
Thaaaaaaaaaaanks !!!
</p>
<p>
Nathann
</p>
TicketjdemeyerMon, 30 Apr 2012 08:29:52 GMTauthor set
https://trac.sagemath.org/ticket/12872#comment:25
https://trac.sagemath.org/ticket/12872#comment:25
<ul>
<li><strong>author</strong>
set to <em>Nathann Cohen</em>
</li>
</ul>
Ticketstumpc5Tue, 01 May 2012 09:55:24 GMT
https://trac.sagemath.org/ticket/12872#comment:26
https://trac.sagemath.org/ticket/12872#comment:26
<p>
Hi Natann,
</p>
<p>
thanks for working on that! Here are some further comments:
</p>
<ol><li>for the braid representation: I would think of options for orientation being X-to-Y for X,Y being top,bottom or bottom,top or left-right or right-left. Also, I think of a braid in a different way: order the inversions in some order (say lex) and then swap two strings at a time. This produces pictures like on the wiki page for the braid group, <a class="ext-link" href="http://en.wikipedia.org/wiki/Braid_group"><span class="icon"></span>http://en.wikipedia.org/wiki/Braid_group</a>.
</li></ol><ol start="2"><li>A second way of drawing the chord diagram is by having two vertices (i,"in") and (i,"out") for each letter. The pic then becomes a matching of 2n points placed on a circle.
</li></ol><ol start="3"><li>do you think of implementing the Rothe (or inversion) diagram Florent mentioned?
</li></ol><ol start="4"><li>The one-line notation is also nice when just drawing arcs between points.
</li></ol><p>
Maybe at least points 3 and 4 might only be worth implementing when doing it in latex/tikz - but this might also apply to 1.
</p>
<p>
Feel free to say that you don't want to do it, I might then start looking at it one day...
</p>
<p>
Best, Christian
</p>
TicketncohenWed, 02 May 2012 09:41:08 GMT
https://trac.sagemath.org/ticket/12872#comment:27
https://trac.sagemath.org/ticket/12872#comment:27
<p>
Hellooooooo Christian !!
</p>
<blockquote class="citation">
<ol><li>for the braid representation: I would think of options for orientation being X-to-Y for X,Y being top,bottom or bottom,top or left-right or right-left. Also, I think of a braid in a different way: order the inversions in some order (say lex) and then swap two strings at a time. This produces pictures like on the wiki page for the braid group, <a class="ext-link" href="http://en.wikipedia.org/wiki/Braid_group"><span class="icon"></span>http://en.wikipedia.org/wiki/Braid_group</a>.
</li></ol></blockquote>
<p>
You mean the kind of drawings produced by my patch on pseudolines (<a class="closed ticket" href="https://trac.sagemath.org/ticket/12090" title="enhancement: Arrangements of pseudolines (closed: fixed)">#12090</a>) ? <code>:-P</code>
</p>
<p>
I will not code that twice, but that feature of pseudolines can be exposed in the .show method of course !
</p>
<blockquote class="citation">
<ol start="2"><li>A second way of drawing the chord diagram is by having two vertices (i,"in") and (i,"out") for each letter. The pic then becomes a matching of 2n points placed on a circle.
</li></ol><ol start="3"><li>do you think of implementing the Rothe (or inversion) diagram Florent mentioned?
</li></ol><ol start="4"><li>The one-line notation is also nice when just drawing arcs between points.
</li></ol></blockquote>
<p>
Actually I only needed to plot permutations as done by the initial patch, that is the <code></code>algorithm="braid"<code></code> version of the current patch. I implemented others because it did not seem to be the universal way to draw them but besides that I will stay as clear from graphical codes as I can <code>:-P</code>
</p>
<p>
Have fuuuuuuuuuuuuuuuuuuuuuuuuuuuun !!!
</p>
<p>
Nathann
</p>
TicketjdemeyerSun, 06 May 2012 12:20:08 GMTstatus changed; resolution, merged set
https://trac.sagemath.org/ticket/12872#comment:28
https://trac.sagemath.org/ticket/12872#comment:28
<ul>
<li><strong>status</strong>
changed from <em>positive_review</em> to <em>closed</em>
</li>
<li><strong>resolution</strong>
set to <em>fixed</em>
</li>
<li><strong>merged</strong>
set to <em>sage-5.1.beta0</em>
</li>
</ul>
Ticket