Ask Your Question
1

Translating quiver in QPA to Sage

asked 2021-01-08 19:09:19 +0200

klaaa gravatar image

updated 2024-04-12 20:13:33 +0200

FrédéricC gravatar image

QPA is a GAP-package that deals with quiver algebras. A quiver is just another word for directed graph. My question is whether there is a quick way to translate the QPA-output of a quiver into a directed graph (with the same names for vertices and arrows) for Sage. For example a quiver in QPA looks as follows:

Quiver( ["v1","v2","v3","v4","v5","v6","v7","v8"], [["v1","v1","a"],["v1","v2","b"],["v2","v3","c"],["v3","v4","d"],["v4","v5","e"],["v5","\v5","f"],["v3","v6","g"],["v6","v7","h"],["v7","v8","i"],["v8","v3","j"]] )

or as follows:

Quiver( ["v1","v2","v3"], [["v1","v2","a1"],["v2","v3","a2"],["v3","v1","a3"]] )

So the first list of the form ["v1","v2","v3","v4","v5","v6","v7","v8"] are always the names of the vertices and the second list

 [["v1","v1","a"],["v1","v2","b"],["v2","v3","c"],["v3","v4","d"],["v4","v5","e"],["v5","\v5","f"],["v3","v6","g"],["v6","v7","h"],["v7","v8","i"],["v8","v3","j"]]

are the names of the vertices, together with the information where they start and end. So for example ,["v2","v3","c"] means that the arrow c starts at v2 and ends at v3.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2021-01-08 20:11:23 +0200

FrédéricC gravatar image

updated 2021-01-08 21:33:22 +0200

you can just copy-paste if you want

sage: data = ["v1","v2","v3","v4","v5","v6","v7","v8"], [["v1","v1","a"],["v1","
....: v2","b"],["v2","v3","c"],["v3","v4","d"],["v4","v5","e"],["v5","v5","f"],
....: ["v3","v6","g"],["v6","v7","h"],["v7","v8","i"],["v8","v3","j"]]          
sage: DiGraph(data, format="vertices_and_edges",loops=True)                     
Looped digraph on 8 vertices

EDIT: here is a more procedural way

def from_QPA(Q): 
    arrows = [(v.SourceOfPath(), v.TargetOfPath(), v) for v in Q.ArrowsOfQuiver() ] 
    elements = Q.VerticesOfQuiver() 
    return DiGraph([elements, arrows], loops=True, format='vertices_and_edges')

then

sage: libgap.LoadPackage("QPA")                                                 
true
sage: Q = libgap.Quiver( ["v1","v2","v3"], [["v1","v2","a1"],["v2","v3","a2"],["v3","v1","a3"]] )
sage: from_QPA(Q)                                                               
Looped digraph on 3 vertices
edit flag offensive delete link more

Comments

Thank you very much! Here is how I entered it into the sage online cell:

data = ["v1","v2","v3","v4","v5","v6","v7","v8"], [["v1","v1","a"],["v1","v2","b"],["v2","v3","c"],["v3","v4","d"], 
["v4","v5","e"],["v5","v5","f"],
["v3","v6","g"],["v6","v7","h"],["v7","v8","i"],["v8","v3","j"]]          
U=DiGraph(data, format="vertices_and_edges",loops=True)                     
display(U)

This is very surprising that it works so easily. But there are two small problems:

  1. Loops are displayed very strange. (this is not a very big problem since loops appear rarely)

  2. The arrows have no names.

Is there an easy way to fix this?

klaaa gravatar imageklaaa ( 2021-01-08 20:46:32 +0200 )edit

Arrows names are there but not displayed by default. You need to ask for them to be displayed.sage: U.plot(edge_labels=True)

FrédéricC gravatar imageFrédéricC ( 2021-01-08 21:22:49 +0200 )edit

Thank you very much again! Is there a way to obtain the digraph as an object in sage so that one can obtain its latex code for example (and not just plot it)? For example like this one can obtain the latex code of the digraph without the edge labelings:

def from_QPA(Q):
arrows = [(v.SourceOfPath(), v.TargetOfPath(), v) for v in Q.ArrowsOfQuiver() ]
elements = Q.VerticesOfQuiver()
return DiGraph([elements, arrows], loops=True, format='vertices_and_edges')
libgap.LoadPackage("QPA")
Q = libgap.Quiver( ["v1","v2","v3"], [["v1","v2","a1"],["v2","v3","a2"],["v3","v1","a3"]] )
U=from_QPA(Q)
display(U)
display(latex(U))

Is there an easy way to obtain it with edge labelings?

klaaa gravatar imageklaaa ( 2021-01-08 22:07:14 +0200 )edit

Have a look at sage: U.set_latex_options?

FrédéricC gravatar imageFrédéricC ( 2021-01-09 09:16:08 +0200 )edit

Thank you very much again. I found the missing option using your suggestion, but sadly for large quivers the displayed directed graph looks terrible despite trying some options to fix that.

But this might be also a problem of tikz and Im not sure anymore whether Sage is the right thing to use for that. I therefore also posted the question in https://tex.stackexchange.com/questio... .

klaaa gravatar imageklaaa ( 2021-01-09 12:12:22 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2021-01-08 19:09:19 +0200

Seen: 297 times

Last updated: Jan 08 '21