{"id":1170,"date":"2015-02-23T13:42:18","date_gmt":"2015-02-23T18:42:18","guid":{"rendered":"http:\/\/matroidunion.org\/?p=1170"},"modified":"2015-02-23T13:55:15","modified_gmt":"2015-02-23T18:55:15","slug":"matroid-computation-in-sagemath-visualizations","status":"publish","type":"post","link":"https:\/\/matroidunion.org\/?p=1170","title":{"rendered":"Matroid computation in SageMath: visualizations"},"content":{"rendered":"<p><a href=\"https:\/\/matroidunion.org\/wp-content\/uploads\/2015\/02\/sage0.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/matroidunion.org\/wp-content\/uploads\/2015\/02\/sage0.png\" alt=\"sage0\" width=\"784\" height=\"584\" class=\"alignnone size-full wp-image-1173\" srcset=\"https:\/\/matroidunion.org\/wp-content\/uploads\/2015\/02\/sage0.png 784w, https:\/\/matroidunion.org\/wp-content\/uploads\/2015\/02\/sage0-300x223.png 300w, https:\/\/matroidunion.org\/wp-content\/uploads\/2015\/02\/sage0-402x300.png 402w\" sizes=\"auto, (max-width: 784px) 100vw, 784px\" \/><\/a><br \/>\nThis post is another installment in my series on matroid computation in <a href=\"http:\/\/www.sagemath.org\">SageMath<\/a>\u00a0<a href=\"#foot1\">[1]<\/a>, with older posts\u00a0<a href=\"https:\/\/matroidunion.org\/?p=514\">here<\/a>,\u00a0<a href=\"https:\/\/matroidunion.org\/?p=301\">here<\/a>, <a href=\"https:\/\/matroidunion.org\/?p=286\">here<\/a>, and <a title=\"Matroid Computation with Sage: comparing matroids\" href=\"https:\/\/matroidunion.org\/?p=517\">here<\/a>. As always, clicking the &#8220;<strong>Evaluate<\/strong>&#8221; buttons below will execute the code and return the answer (or, in today&#8217;s post, draw the picture). The various computations are linked, so execute them in the right order.<\/p>\n<p>Last summer, <a href=\"https:\/\/sites.google.com\/site\/jayantapteshomepage\/\">Jayant Apte\u00a0<\/a>was selected to participate in the Google Summer of Code program. During the summer he\u00a0extended SageMath&#8217;s matroid capabilities in two major ways.<\/p>\n<ul>\n<li>Drawing geometric representations of rank-3 matroids<\/li>\n<li>A more efficient minor test for binary matroids<\/li>\n<\/ul>\n<p>The first of these has been part of Sage for a while; the second is awaiting review but should be included fairly soon.<\/p>\n<p>Let&#8217;s get started with everyone&#8217;s favorite matroid.<\/p>\n<div class=\"sage1\"><script type=\"text\/x-sage\">\nM = matroids.named_matroids.Fano()\nM.show()\n<\/script><\/div>\n<p>That was easy! We can deal with parallel elements too:<\/p>\n<div class=\"sage1\"><script type=\"text\/x-sage\">\nM = matroids.PG(3,2).contract(0)\nM.show()\n<\/script><\/div>\n<p>Loops are no problem either:<\/p>\n<div class=\"sage1\"><script type=\"text\/x-sage\">\nM = matroids.PG(3,2).contract([0,1])\nM.show()\n<\/script><\/div>\n<p>Note that we resort to a slightly different method of display for large parallel classes. The point in the geometric representation will receive a label that is not an element of the matroid, and below the diagram it will state that this label actually represents a parallel class of elements.<\/p>\n<p>The examples above were chosen because the default positioning algorithm gives a decent picture. Unfortunately, that is not always the case:<\/p>\n<div class=\"sage1\"><script type=\"text\/x-sage\">\nmatroids.named_matroids.Pappus().show()\n<\/script><\/div>\n<p>In these instances, the options of the <code>show()<\/code> method come in handy. To get a full list, type <code>M.show?<\/code> in your own session of SageMath, and hit the <TAB> key. This will bring up the help page of the method (assuming you defined $M$ to be a matroid in an earlier command). We will go through these options one by one.<\/p>\n<div class=\"sage1\"><script type=\"text\/x-sage\">\nM = matroids.CompleteGraphic(4)\nM.show()\n<\/script><\/div>\n<p>This is not bad, but we don&#8217;t need a curved line to draw this diagram. The solution is to specify a different basis, whose elements will be placed at the corners of a triangle:<\/p>\n<div class=\"sage1\"><script type=\"text\/x-sage\">\nM = matroids.CompleteGraphic(4)\nM.show(B=[0,1,4])\n<\/script><\/div>\n<p>Trying different bases is not going to help the Pappus matroid too much. In that case, after inspecting, for instance, <code>M.circuit_closures()<\/code>, we can come up with custom coordinates for the points. To tell Sage that we&#8217;re doing this, we add the option <code>pos_method=1<\/code>.<\/p>\n<div class=\"sage1\"><script type=\"text\/x-sage\">\nM = matroids.named_matroids.Pappus()\npos = {'a':(0,1), 'b': (1,1), 'c':(2,1), 'd':(0,0), 'e':(1,0), 'f':(2,0), 'g':(1.5,0.5), 'h':(1,0.5), 'i':(0.5,0.5)}\nM.show(pos_method=1,pos_dict=pos)\n<\/script><\/div>\n<p>A second example, just because:<\/p>\n<div class=\"sage1\"><script type=\"text\/x-sage\">\nM=matroids.named_matroids.BetsyRoss()\npos={}\ns=\"abcde\"\nt=\"fghij\"\nx=1.61\ny=1\/1.61\nfor i in range(5):\n    pos[s[i]]=(RR(x*sin(2*pi*i\/5)), RR(x*cos(2*pi*i\/5)))\n    pos[t[i]]=(RR(y*sin(2*pi*(i+1\/2)\/5)), RR(y*cos(2*pi*(i+1\/2)\/5)))\npos['k']=(0,0)\nM.show(pos_method=1,pos_dict=pos)\n<\/script><\/div>\n<p>Our final option today deals with <em>betweenness<\/em>. In projective geometry this is a meaningless concept, of course, but in a concrete diagram it can matter whether we draw a line from $a$ through $b$ to $c$ or from $b$ through $a$ to $c$. In SageMath, we can specify this through the <code>line_orders<\/code> option. An example should make this clear.<\/p>\n<div class=\"sage1\"><script type=\"text\/x-sage\">\nM = matroids.named_matroids.P7()\npos = {'a':(2,1), 'b':(0,0), 'c': (0,1), 'g': (0,2), 'e': (1.5,0.75), 'f':(1.5,1), 'd':(0.2,1.9)}\nM.show(pos_method=1,pos_dict=pos)\n<\/script><\/div>\n<p>We specify the order on the line $\\{d,e,f\\}$:<\/p>\n<div class=\"sage1\"><script type=\"text\/x-sage\">\nM = matroids.named_matroids.P7()\npos = {'a':(2,1), 'b':(0,0), 'c': (0,1), 'g': (0,2), 'e': (1.5,0.75), 'f':(1.5,1), 'd':(0.2,1.9)}\nlines=[['d','f','e']]\nM.show(pos_method=1,pos_dict=pos,lineorders=lines)\n<\/script><\/div>\n<p>A slightly less contrived example is provided by $\\textrm{AG}(2,3)$.<\/p>\n<div class=\"sage1\"><script type=\"text\/x-sage\">\nM = matroids.AG(2,3)\npos={1:(0,2), 3:(1,2), 5:(2,2), 0:(0,1), 4:(1,1), 2:(2,1), 8:(0,0), 7:(1,0), 6:(2,0)}\nM.show(pos_method=1,pos_dict=pos)\n<\/script><\/div>\n<p>I prefer a rotational symmetry to the curved lines:<\/p>\n<div class=\"sage1\"><script type=\"text\/x-sage\">\npos={1:(0,2), 3:(1,2), 5:(2,2), 0:(0,1), 4:(1,1), 2:(2,1), 8:(0,0), 7:(1,0), 6:(2,0)}\nlines=[[0,3,6],[3,2,8],[2,7,1],[7,0,5],[0,3,6]]\nM.show(pos_method=1,pos_dict=pos, lineorders=lines)\n<\/script><\/div>\n<p>It&#8217;s not perfect (I&#8217;d like the curved lines to protrude out of the square), but it&#8217;s in the ballpark.<\/p>\n<p>Note: after you have drawn a matroid, the options for drawing so are saved. So next time,<\/p>\n<div class=\"sage1\"><script type=\"text\/x-sage\">\nM.show()\n<\/script><\/div>\n<p>will produce the same graphic.<\/p>\n<p>There are many ways in which the drawing routines can be improved. Options like color, aspect ratio, letting the user decide how to handle parallel elements, and functionality like saving plot information when you save a matroid, adding &#8220;nice&#8221; plots to the built-in library of matroids, special plots for Dowling geometries, plots for rank-4 matroids, and the list goes on. Interested? There&#8217;s another Google Summer of Code coming up soon!<\/p>\n<p><a id=\"foot1\"><\/a>[1] SageMath is\u00a0now the official name of the Sage Mathematical Software System.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post is another installment in my series on matroid computation in SageMath\u00a0[1], with older posts\u00a0here,\u00a0here, here, and here. As always, clicking the &#8220;Evaluate&#8221; buttons below will execute the code and return the answer (or, in today&#8217;s post, draw the &hellip; <a href=\"https:\/\/matroidunion.org\/?p=1170\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1170","post","type-post","status-publish","format-standard","hentry","category-matroids"],"_links":{"self":[{"href":"https:\/\/matroidunion.org\/index.php?rest_route=\/wp\/v2\/posts\/1170","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/matroidunion.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/matroidunion.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/matroidunion.org\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/matroidunion.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1170"}],"version-history":[{"count":11,"href":"https:\/\/matroidunion.org\/index.php?rest_route=\/wp\/v2\/posts\/1170\/revisions"}],"predecessor-version":[{"id":1182,"href":"https:\/\/matroidunion.org\/index.php?rest_route=\/wp\/v2\/posts\/1170\/revisions\/1182"}],"wp:attachment":[{"href":"https:\/\/matroidunion.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1170"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/matroidunion.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1170"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/matroidunion.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1170"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}