Skip to content

Instantly share code, notes, and snippets.

@mapio
Last active January 20, 2016 16:12
Show Gist options
  • Save mapio/c44c029a1c1a5ff1ab59 to your computer and use it in GitHub Desktop.
Save mapio/c44c029a1c1a5ff1ab59 to your computer and use it in GitHub Desktop.
The Hasse diagram of the divisibility graph
Display the source blob
Display the rendered blob
Raw
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by graphviz version 2.38.0 (20140413.2041)
-->
<!-- Title: G Pages: 1 -->
<svg width="332pt" height="530pt"
viewBox="0.00 0.00 332.00 530.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 526)">
<title>G</title>
<polygon fill="white" stroke="none" points="-4,4 -4,-526 328,-526 328,4 -4,4"/>
<!-- 3 -->
<g id="node1" class="node"><title>3</title>
<ellipse fill="none" stroke="black" cx="27" cy="-450" rx="27" ry="18"/>
<text text-anchor="middle" x="27" y="-446.3" font-family="Times,serif" font-size="14.00">3</text>
</g>
<!-- 15 -->
<g id="node2" class="node"><title>15</title>
<ellipse fill="none" stroke="black" cx="117" cy="-450" rx="27" ry="18"/>
<text text-anchor="middle" x="117" y="-446.3" font-family="Times,serif" font-size="14.00">15</text>
</g>
<!-- 3&#45;&gt;15 -->
<g id="edge1" class="edge"><title>3&#45;&gt;15</title>
<path fill="none" stroke="black" d="M54.4029,-450C62.3932,-450 71.3106,-450 79.8241,-450"/>
<polygon fill="black" stroke="black" points="79.919,-453.5 89.919,-450 79.919,-446.5 79.919,-453.5"/>
</g>
<!-- 21 -->
<g id="node4" class="node"><title>21</title>
<ellipse fill="none" stroke="black" cx="117" cy="-342" rx="27" ry="18"/>
<text text-anchor="middle" x="117" y="-338.3" font-family="Times,serif" font-size="14.00">21</text>
</g>
<!-- 3&#45;&gt;21 -->
<g id="edge5" class="edge"><title>3&#45;&gt;21</title>
<path fill="none" stroke="black" d="M43.0716,-435.299C46.7867,-431.423 50.656,-427.158 54,-423 72.0758,-400.522 71.9242,-391.478 90,-369 91.254,-367.441 92.5819,-365.866 93.9478,-364.303"/>
<polygon fill="black" stroke="black" points="96.7429,-366.434 100.928,-356.701 91.5868,-361.699 96.7429,-366.434"/>
</g>
<!-- 9 -->
<g id="node10" class="node"><title>9</title>
<ellipse fill="none" stroke="black" cx="117" cy="-504" rx="27" ry="18"/>
<text text-anchor="middle" x="117" y="-500.3" font-family="Times,serif" font-size="14.00">9</text>
</g>
<!-- 3&#45;&gt;9 -->
<g id="edge29" class="edge"><title>3&#45;&gt;9</title>
<path fill="none" stroke="black" d="M47.5301,-461.984C59.3788,-469.255 74.6989,-478.656 87.8424,-486.721"/>
<polygon fill="black" stroke="black" points="86.1707,-489.802 96.5245,-492.049 89.8319,-483.836 86.1707,-489.802"/>
</g>
<!-- 6 -->
<g id="node19" class="node"><title>6</title>
<ellipse fill="none" stroke="black" cx="117" cy="-288" rx="27" ry="18"/>
<text text-anchor="middle" x="117" y="-284.3" font-family="Times,serif" font-size="14.00">6</text>
</g>
<!-- 3&#45;&gt;6 -->
<g id="edge13" class="edge"><title>3&#45;&gt;6</title>
<path fill="none" stroke="black" d="M43.8776,-435.863C47.5772,-431.976 51.2376,-427.565 54,-423 80.193,-379.711 63.807,-358.289 90,-315 91.0359,-313.288 92.1981,-311.598 93.4413,-309.949"/>
<polygon fill="black" stroke="black" points="96.2826,-312.011 100.122,-302.137 90.9629,-307.461 96.2826,-312.011"/>
</g>
<!-- 7 -->
<g id="node3" class="node"><title>7</title>
<ellipse fill="none" stroke="black" cx="27" cy="-288" rx="27" ry="18"/>
<text text-anchor="middle" x="27" y="-284.3" font-family="Times,serif" font-size="14.00">7</text>
</g>
<!-- 7&#45;&gt;21 -->
<g id="edge2" class="edge"><title>7&#45;&gt;21</title>
<path fill="none" stroke="black" d="M47.5301,-299.984C59.3788,-307.255 74.6989,-316.656 87.8424,-324.721"/>
<polygon fill="black" stroke="black" points="86.1707,-327.802 96.5245,-330.049 89.8319,-321.836 86.1707,-327.802"/>
</g>
<!-- 14 -->
<g id="node21" class="node"><title>14</title>
<ellipse fill="none" stroke="black" cx="117" cy="-126" rx="27" ry="18"/>
<text text-anchor="middle" x="117" y="-122.3" font-family="Times,serif" font-size="14.00">14</text>
</g>
<!-- 7&#45;&gt;14 -->
<g id="edge16" class="edge"><title>7&#45;&gt;14</title>
<path fill="none" stroke="black" d="M33.9171,-270.402C43.3734,-243.653 63.5528,-191.78 90,-153 91.1275,-151.347 92.3592,-149.701 93.6539,-148.085"/>
<polygon fill="black" stroke="black" points="96.4794,-150.172 100.461,-140.354 91.2256,-145.547 96.4794,-150.172"/>
</g>
<!-- 4 -->
<g id="node5" class="node"><title>4</title>
<ellipse fill="none" stroke="black" cx="117" cy="-180" rx="27" ry="18"/>
<text text-anchor="middle" x="117" y="-176.3" font-family="Times,serif" font-size="14.00">4</text>
</g>
<!-- 8 -->
<g id="node6" class="node"><title>8</title>
<ellipse fill="none" stroke="black" cx="207" cy="-180" rx="27" ry="18"/>
<text text-anchor="middle" x="207" y="-176.3" font-family="Times,serif" font-size="14.00">8</text>
</g>
<!-- 4&#45;&gt;8 -->
<g id="edge3" class="edge"><title>4&#45;&gt;8</title>
<path fill="none" stroke="black" d="M144.403,-180C152.393,-180 161.311,-180 169.824,-180"/>
<polygon fill="black" stroke="black" points="169.919,-183.5 179.919,-180 169.919,-176.5 169.919,-183.5"/>
</g>
<!-- 12 -->
<g id="node9" class="node"><title>12</title>
<ellipse fill="none" stroke="black" cx="207" cy="-288" rx="27" ry="18"/>
<text text-anchor="middle" x="207" y="-284.3" font-family="Times,serif" font-size="14.00">12</text>
</g>
<!-- 4&#45;&gt;12 -->
<g id="edge6" class="edge"><title>4&#45;&gt;12</title>
<path fill="none" stroke="black" d="M133.072,-194.701C136.787,-198.577 140.656,-202.842 144,-207 162.076,-229.478 161.924,-238.522 180,-261 181.254,-262.559 182.582,-264.134 183.948,-265.697"/>
<polygon fill="black" stroke="black" points="181.587,-268.301 190.928,-273.299 186.743,-263.566 181.587,-268.301"/>
</g>
<!-- 20 -->
<g id="node13" class="node"><title>20</title>
<ellipse fill="none" stroke="black" cx="207" cy="-234" rx="27" ry="18"/>
<text text-anchor="middle" x="207" y="-230.3" font-family="Times,serif" font-size="14.00">20</text>
</g>
<!-- 4&#45;&gt;20 -->
<g id="edge9" class="edge"><title>4&#45;&gt;20</title>
<path fill="none" stroke="black" d="M137.53,-191.984C149.379,-199.255 164.699,-208.656 177.842,-216.721"/>
<polygon fill="black" stroke="black" points="176.171,-219.802 186.525,-222.049 179.832,-213.836 176.171,-219.802"/>
</g>
<!-- 28 -->
<g id="node22" class="node"><title>28</title>
<ellipse fill="none" stroke="black" cx="207" cy="-126" rx="27" ry="18"/>
<text text-anchor="middle" x="207" y="-122.3" font-family="Times,serif" font-size="14.00">28</text>
</g>
<!-- 4&#45;&gt;28 -->
<g id="edge20" class="edge"><title>4&#45;&gt;28</title>
<path fill="none" stroke="black" d="M137.53,-168.016C149.379,-160.745 164.699,-151.344 177.842,-143.279"/>
<polygon fill="black" stroke="black" points="179.832,-146.164 186.525,-137.951 176.171,-140.198 179.832,-146.164"/>
</g>
<!-- 24 -->
<g id="node16" class="node"><title>24</title>
<ellipse fill="none" stroke="black" cx="297" cy="-261" rx="27" ry="18"/>
<text text-anchor="middle" x="297" y="-257.3" font-family="Times,serif" font-size="14.00">24</text>
</g>
<!-- 8&#45;&gt;24 -->
<g id="edge26" class="edge"><title>8&#45;&gt;24</title>
<path fill="none" stroke="black" d="M223.733,-194.481C237.373,-207.036 257.298,-225.376 272.773,-239.621"/>
<polygon fill="black" stroke="black" points="270.676,-242.447 280.404,-246.644 275.416,-237.297 270.676,-242.447"/>
</g>
<!-- 16 -->
<g id="node20" class="node"><title>16</title>
<ellipse fill="none" stroke="black" cx="297" cy="-180" rx="27" ry="18"/>
<text text-anchor="middle" x="297" y="-176.3" font-family="Times,serif" font-size="14.00">16</text>
</g>
<!-- 8&#45;&gt;16 -->
<g id="edge14" class="edge"><title>8&#45;&gt;16</title>
<path fill="none" stroke="black" d="M234.403,-180C242.393,-180 251.311,-180 259.824,-180"/>
<polygon fill="black" stroke="black" points="259.919,-183.5 269.919,-180 259.919,-176.5 259.919,-183.5"/>
</g>
<!-- 13 -->
<g id="node7" class="node"><title>13</title>
<ellipse fill="none" stroke="black" cx="27" cy="-72" rx="27" ry="18"/>
<text text-anchor="middle" x="27" y="-68.3" font-family="Times,serif" font-size="14.00">13</text>
</g>
<!-- 26 -->
<g id="node8" class="node"><title>26</title>
<ellipse fill="none" stroke="black" cx="117" cy="-72" rx="27" ry="18"/>
<text text-anchor="middle" x="117" y="-68.3" font-family="Times,serif" font-size="14.00">26</text>
</g>
<!-- 13&#45;&gt;26 -->
<g id="edge4" class="edge"><title>13&#45;&gt;26</title>
<path fill="none" stroke="black" d="M54.4029,-72C62.3932,-72 71.3106,-72 79.8241,-72"/>
<polygon fill="black" stroke="black" points="79.919,-75.5001 89.919,-72 79.919,-68.5001 79.919,-75.5001"/>
</g>
<!-- 12&#45;&gt;24 -->
<g id="edge11" class="edge"><title>12&#45;&gt;24</title>
<path fill="none" stroke="black" d="M232.046,-280.622C241.435,-277.741 252.362,-274.389 262.5,-271.279"/>
<polygon fill="black" stroke="black" points="263.754,-274.555 272.287,-268.275 261.701,-267.863 263.754,-274.555"/>
</g>
<!-- 18 -->
<g id="node11" class="node"><title>18</title>
<ellipse fill="none" stroke="black" cx="207" cy="-396" rx="27" ry="18"/>
<text text-anchor="middle" x="207" y="-392.3" font-family="Times,serif" font-size="14.00">18</text>
</g>
<!-- 9&#45;&gt;18 -->
<g id="edge7" class="edge"><title>9&#45;&gt;18</title>
<path fill="none" stroke="black" d="M132.886,-489.145C136.605,-485.272 140.522,-481.047 144,-477 159.68,-458.755 176.177,-437.065 188.209,-420.724"/>
<polygon fill="black" stroke="black" points="191.326,-422.39 194.4,-412.251 185.674,-418.26 191.326,-422.39"/>
</g>
<!-- 27 -->
<g id="node24" class="node"><title>27</title>
<ellipse fill="none" stroke="black" cx="207" cy="-504" rx="27" ry="18"/>
<text text-anchor="middle" x="207" y="-500.3" font-family="Times,serif" font-size="14.00">27</text>
</g>
<!-- 9&#45;&gt;27 -->
<g id="edge23" class="edge"><title>9&#45;&gt;27</title>
<path fill="none" stroke="black" d="M144.403,-504C152.393,-504 161.311,-504 169.824,-504"/>
<polygon fill="black" stroke="black" points="169.919,-507.5 179.919,-504 169.919,-500.5 169.919,-507.5"/>
</g>
<!-- 2 -->
<g id="node12" class="node"><title>2</title>
<ellipse fill="none" stroke="black" cx="27" cy="-153" rx="27" ry="18"/>
<text text-anchor="middle" x="27" y="-149.3" font-family="Times,serif" font-size="14.00">2</text>
</g>
<!-- 2&#45;&gt;4 -->
<g id="edge30" class="edge"><title>2&#45;&gt;4</title>
<path fill="none" stroke="black" d="M52.0464,-160.378C61.4354,-163.259 72.3623,-166.611 82.4996,-169.721"/>
<polygon fill="black" stroke="black" points="81.7006,-173.137 92.2874,-172.725 83.7539,-166.445 81.7006,-173.137"/>
</g>
<!-- 2&#45;&gt;26 -->
<g id="edge8" class="edge"><title>2&#45;&gt;26</title>
<path fill="none" stroke="black" d="M43.7326,-138.519C57.3727,-125.964 77.2979,-107.624 92.7733,-93.3791"/>
<polygon fill="black" stroke="black" points="95.4162,-95.7034 100.404,-86.3558 90.6756,-90.553 95.4162,-95.7034"/>
</g>
<!-- 22 -->
<g id="node15" class="node"><title>22</title>
<ellipse fill="none" stroke="black" cx="117" cy="-18" rx="27" ry="18"/>
<text text-anchor="middle" x="117" y="-14.3" font-family="Times,serif" font-size="14.00">22</text>
</g>
<!-- 2&#45;&gt;22 -->
<g id="edge27" class="edge"><title>2&#45;&gt;22</title>
<path fill="none" stroke="black" d="M36.2457,-135.737C47.1274,-113.719 67.5485,-74.9146 90,-45 91.2012,-43.3996 92.4889,-41.794 93.8251,-40.2077"/>
<polygon fill="black" stroke="black" points="96.6342,-42.3189 100.733,-32.5491 91.4363,-37.6304 96.6342,-42.3189"/>
</g>
<!-- 2&#45;&gt;6 -->
<g id="edge17" class="edge"><title>2&#45;&gt;6</title>
<path fill="none" stroke="black" d="M36.2457,-170.263C47.1274,-192.281 67.5485,-231.085 90,-261 91.2012,-262.6 92.4889,-264.206 93.8251,-265.792"/>
<polygon fill="black" stroke="black" points="91.4363,-268.37 100.733,-273.451 96.6342,-263.681 91.4363,-268.37"/>
</g>
<!-- 2&#45;&gt;14 -->
<g id="edge22" class="edge"><title>2&#45;&gt;14</title>
<path fill="none" stroke="black" d="M52.0464,-145.622C61.4354,-142.741 72.3623,-139.389 82.4996,-136.279"/>
<polygon fill="black" stroke="black" points="83.7539,-139.555 92.2874,-133.275 81.7006,-132.863 83.7539,-139.555"/>
</g>
<!-- 10 -->
<g id="node23" class="node"><title>10</title>
<ellipse fill="none" stroke="black" cx="117" cy="-234" rx="27" ry="18"/>
<text text-anchor="middle" x="117" y="-230.3" font-family="Times,serif" font-size="14.00">10</text>
</g>
<!-- 2&#45;&gt;10 -->
<g id="edge18" class="edge"><title>2&#45;&gt;10</title>
<path fill="none" stroke="black" d="M43.7326,-167.481C57.3727,-180.036 77.2979,-198.376 92.7733,-212.621"/>
<polygon fill="black" stroke="black" points="90.6756,-215.447 100.404,-219.644 95.4162,-210.297 90.6756,-215.447"/>
</g>
<!-- 11 -->
<g id="node14" class="node"><title>11</title>
<ellipse fill="none" stroke="black" cx="27" cy="-18" rx="27" ry="18"/>
<text text-anchor="middle" x="27" y="-14.3" font-family="Times,serif" font-size="14.00">11</text>
</g>
<!-- 11&#45;&gt;22 -->
<g id="edge10" class="edge"><title>11&#45;&gt;22</title>
<path fill="none" stroke="black" d="M54.4029,-18C62.3932,-18 71.3106,-18 79.8241,-18"/>
<polygon fill="black" stroke="black" points="79.919,-21.5001 89.919,-18 79.919,-14.5001 79.919,-21.5001"/>
</g>
<!-- 5 -->
<g id="node17" class="node"><title>5</title>
<ellipse fill="none" stroke="black" cx="27" cy="-396" rx="27" ry="18"/>
<text text-anchor="middle" x="27" y="-392.3" font-family="Times,serif" font-size="14.00">5</text>
</g>
<!-- 5&#45;&gt;15 -->
<g id="edge19" class="edge"><title>5&#45;&gt;15</title>
<path fill="none" stroke="black" d="M47.5301,-407.984C59.3788,-415.255 74.6989,-424.656 87.8424,-432.721"/>
<polygon fill="black" stroke="black" points="86.1707,-435.802 96.5245,-438.049 89.8319,-429.836 86.1707,-435.802"/>
</g>
<!-- 25 -->
<g id="node18" class="node"><title>25</title>
<ellipse fill="none" stroke="black" cx="117" cy="-396" rx="27" ry="18"/>
<text text-anchor="middle" x="117" y="-392.3" font-family="Times,serif" font-size="14.00">25</text>
</g>
<!-- 5&#45;&gt;25 -->
<g id="edge12" class="edge"><title>5&#45;&gt;25</title>
<path fill="none" stroke="black" d="M54.4029,-396C62.3932,-396 71.3106,-396 79.8241,-396"/>
<polygon fill="black" stroke="black" points="79.919,-399.5 89.919,-396 79.919,-392.5 79.919,-399.5"/>
</g>
<!-- 5&#45;&gt;10 -->
<g id="edge24" class="edge"><title>5&#45;&gt;10</title>
<path fill="none" stroke="black" d="M33.9171,-378.402C43.3734,-351.653 63.5528,-299.78 90,-261 91.1275,-259.347 92.3592,-257.701 93.6539,-256.085"/>
<polygon fill="black" stroke="black" points="96.4794,-258.172 100.461,-248.354 91.2256,-253.547 96.4794,-258.172"/>
</g>
<!-- 6&#45;&gt;12 -->
<g id="edge21" class="edge"><title>6&#45;&gt;12</title>
<path fill="none" stroke="black" d="M144.403,-288C152.393,-288 161.311,-288 169.824,-288"/>
<polygon fill="black" stroke="black" points="169.919,-291.5 179.919,-288 169.919,-284.5 169.919,-291.5"/>
</g>
<!-- 6&#45;&gt;18 -->
<g id="edge25" class="edge"><title>6&#45;&gt;18</title>
<path fill="none" stroke="black" d="M132.886,-302.855C136.605,-306.728 140.522,-310.953 144,-315 159.68,-333.245 176.177,-354.935 188.209,-371.276"/>
<polygon fill="black" stroke="black" points="185.674,-373.74 194.4,-379.749 191.326,-369.61 185.674,-373.74"/>
</g>
<!-- 14&#45;&gt;28 -->
<g id="edge15" class="edge"><title>14&#45;&gt;28</title>
<path fill="none" stroke="black" d="M144.403,-126C152.393,-126 161.311,-126 169.824,-126"/>
<polygon fill="black" stroke="black" points="169.919,-129.5 179.919,-126 169.919,-122.5 169.919,-129.5"/>
</g>
<!-- 10&#45;&gt;20 -->
<g id="edge28" class="edge"><title>10&#45;&gt;20</title>
<path fill="none" stroke="black" d="M144.403,-234C152.393,-234 161.311,-234 169.824,-234"/>
<polygon fill="black" stroke="black" points="169.919,-237.5 179.919,-234 169.919,-230.5 169.919,-237.5"/>
</g>
</g>
</svg>
def divisibility_graph( n ):
E = set()
for dst in range( 30 ):
for src in range( 2, dst ):
if dst % src == 0:
E.add( ( src, dst ) )
return E
def hasse_diagram( E ):
E2 = set()
for e0 in E:
for e1 in E:
if e0[1] == e1[0]:
E2.add( ( e0[0], e1[1] ) )
return E - E2
def to_dot( E ):
res = [ 'digraph G { rankdir = LR; ' ]
res.extend( [ '{}->{};'.format( *e ) for e in E ] )
res.append( '}' )
return '\n'.join( res )
if __name__ == '__main__':
from sys import argv
E = divisibility_graph( int( argv[ 1 ] ) )
H = hasse_diagram( E )
print to_dot( H )
@mapio
Copy link
Author

mapio commented Jan 20, 2016

This code generates the Hasse diagram of the divisibility graph in Graphviz format. You can run it as

 python hasse_divisibility.py 30 | dot -Tsvg >h.svg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment