Ask Your Question
1

Translating GAP-output into sage for lattices

asked 2020-10-03 13:16:30 +0100

klaaa gravatar image

updated 2020-10-03 13:19:50 +0100

Hi, I mainly use GAP for computations so my experience with Sage is very little. I wonder whether there is an easy method to translate a GAP statistic for posets into a sage statistic for lattices that can be used to enter in the database http://www.findstat.org/ . The following example illustrates the problem: The GAP output in this example is:

[ [ [ [ 1, 1, 1, 1, 1 ], [ 0, 1, 0, 0, 1 ], [ 0, 0, 1, 0, 1 ], [ 0, 0, 0, 1, 1 ], [ 0, 0, 0, 0, 1 ] ], 2 ],

[ [ [ 1, 1, 1, 1, 1 ], [ 0, 1, 0, 1, 1 ], [ 0, 0, 1, 1, 1 ], [ 0, 0, 0, 1, 1 ], [ 0, 0, 0, 0, 1 ] ], 2 ],

[ [ [ 1, 1, 1, 1, 1 ], [ 0, 1, 0, 0, 1 ], [ 0, 0, 1, 1, 1 ], [ 0, 0, 0, 1, 1 ], [ 0, 0, 0, 0, 1 ] ], 2 ],

[ [ [ 1, 1, 1, 1, 1 ], [ 0, 1, 1, 1, 1 ], [ 0, 0, 1, 1, 1 ], [ 0, 0, 0, 1, 1 ], [ 0, 0, 0, 0, 1 ] ], 1 ],

[ [ [ 1, 1, 1, 1, 1 ], [ 0, 1, 1, 1, 1 ], [ 0, 0, 1, 0, 1 ], [ 0, 0, 0, 1, 1 ], [ 0, 0, 0, 0, 1 ] ], 2 ] ]

This is a list with 5 entries where the first entry is for example [ [ [ 1, 1, 1, 1, 1 ], [ 0, 1, 0, 0, 1 ], [ 0, 0, 1, 0, 1 ], [ 0, 0, 0, 1, 1 ], [ 0, 0, 0, 0, 1 ] ], 2 ]. So this first entry is a list with two entries, the first is the matrix [ [ [ 1, 1, 1, 1, 1 ], [ 0, 1, 0, 0, 1 ], [ 0, 0, 1, 0, 1 ], [ 0, 0, 0, 1, 1 ], [ 0, 0, 0, 0, 1 ] ] that is the leq-matrix of a lattice, namely the diamond lattice (which in sage can be entered as ([(0,1),(0,2),(0,3),(1,4),(2,4),(3,4)],5) ) and the second entry is the number 2, which is the value of the statistic. So to every of the five entries in the big list, there corresponds a lattice with a number (statistic).

Now I try to obtain the same statistic in sage that can be entered in the findstat database and the text should look as follows:

([(0,1),(0,2),(0,3),(1,4),(2,4),(3,4)],5) => 2

([(0,2),(0,3),(2,4),(3,4),(4,1)],5) => 2

([(0,2),(0,3),(1,4),(2,4),(3,1)],5) => 2

([(0,4),(2,3),(3,1),(4,2)],5) => 1

([(0,3),(1,4),(2,4),(3,1),(3,2)],5) => 2

Is there an easy way to translate bigger lists such as the above GAP list automatically into the needed sage output to enter in the findstat database?

Thanks for any help!

edit retag flag offensive close merge delete

Comments

There are several steps you might be asking about:

  • convert a multiline string to sage objects: use sage_eval, see my answer
  • get that string from a file: use with open(filename, 'r') as f: s = f.read()
  • convert from a poset to a lattice or to hasse diagram edges: see @rburing's answer
  • string formatting to get the desired output form, see my answer
slelievre gravatar imageslelievre ( 2020-10-03 17:03:45 +0100 )edit

2 Answers

Sort by » oldest newest most voted
2

answered 2020-10-03 16:58:21 +0100

slelievre gravatar image

updated 2020-10-03 17:08:10 +0100

One possibility is to

  • input a mutli-line string from the GAP output
  • evaluate it as a list of "[list of lists, number]" lists
  • run a small loop to extract the data in the desired form

Here is how it would go.

The initial string:

s = """
[[[[1, 1, 1, 1, 1], [0, 1, 0, 0, 1], [0, 0, 1, 0, 1], [0, 0, 0, 1, 1], [0, 0, 0, 0, 1]], 2],
 [[[1, 1, 1, 1, 1], [0, 1, 0, 1, 1], [0, 0, 1, 1, 1], [0, 0, 0, 1, 1], [0, 0, 0, 0, 1]], 2],
 [[[1, 1, 1, 1, 1], [0, 1, 0, 0, 1], [0, 0, 1, 1, 1], [0, 0, 0, 1, 1], [0, 0, 0, 0, 1]], 2],
 [[[1, 1, 1, 1, 1], [0, 1, 1, 1, 1], [0, 0, 1, 1, 1], [0, 0, 0, 1, 1], [0, 0, 0, 0, 1]], 1],
 [[[1, 1, 1, 1, 1], [0, 1, 1, 1, 1], [0, 0, 1, 0, 1], [0, 0, 0, 1, 1], [0, 0, 0, 0, 1]], 2]]
"""

Turn it into a list:

sage: stats = sage_eval(s)
sage: stats
[[[[1, 1, 1, 1, 1],
   [0, 1, 0, 0, 1],
   [0, 0, 1, 0, 1],
   [0, 0, 0, 1, 1],
   [0, 0, 0, 0, 1]],
  2],
 [[[1, 1, 1, 1, 1],
   [0, 1, 0, 1, 1],
   [0, 0, 1, 1, 1],
   [0, 0, 0, 1, 1],
   [0, 0, 0, 0, 1]],
  2],
 [[[1, 1, 1, 1, 1],
   [0, 1, 0, 0, 1],
   [0, 0, 1, 1, 1],
   [0, 0, 0, 1, 1],
   [0, 0, 0, 0, 1]],
  2],
 [[[1, 1, 1, 1, 1],
   [0, 1, 1, 1, 1],
   [0, 0, 1, 1, 1],
   [0, 0, 0, 1, 1],
   [0, 0, 0, 0, 1]],
  1],
 [[[1, 1, 1, 1, 1],
   [0, 1, 1, 1, 1],
   [0, 0, 1, 0, 1],
   [0, 0, 0, 1, 1],
   [0, 0, 0, 0, 1]],
  2]]

Run the small loop to format as desired:

sage: for m, s in stats:
....:     a = matrix(m)
....:     i = a.parent().one()
....:     d = (a - i).dict()
....:     stat = list(d.keys()), a.ncols()
....:     print(f"{stat} => {s}")
....:
([(0, 1), (0, 2), (0, 3), (0, 4), (1, 4), (2, 4), (3, 4)], 5) => 2
([(0, 1), (0, 2), (0, 3), (0, 4), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)], 5) => 2
([(0, 1), (0, 2), (0, 3), (0, 4), (1, 4), (2, 3), (2, 4), (3, 4)], 5) => 2
([(0, 1), (0, 2), (0, 3), (0, 4), (1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)], 5) => 1
([(0, 1), (0, 2), (0, 3), (0, 4), (1, 2), (1, 3), (1, 4), (2, 4), (3, 4)], 5) => 2
edit flag offensive delete link more

Comments

Thank you very much, this seems to work!

klaaa gravatar imageklaaa ( 2020-10-03 17:14:06 +0100 )edit

Be careful, after getting the matrix, I don't think I'm doing the right thing.

For the first matrix it works by luck, but for the other four it's not as expected in the question.

Check the code in @rburing's answer, and do the appropriate mix.

slelievre gravatar imageslelievre ( 2020-10-03 18:49:37 +0100 )edit

If you are working with GAP and Sage, you might also be interested in

  • running GAP computations from Sage using libgap.
  • Nicolas Thiéry's sage-gap semantic interface
  • running Sage computations from GAP using the Homalg GAP package
slelievre gravatar imageslelievre ( 2020-10-03 18:53:44 +0100 )edit

Thanks again. For findstat just the isomorphism type of the lattice is important and not the actual labeling (or using too many relations as you do in the example, since only the cover relations would be enough).

klaaa gravatar imageklaaa ( 2020-10-03 20:14:27 +0100 )edit
2

answered 2020-10-03 16:53:59 +0100

rburing gravatar image

So essentially you want to turn a leq-matrix into a LatticePoset and get its Hasse diagram:

sage: M = Matrix([ [ 1, 1, 1, 1, 1 ], [ 0, 1, 1, 1, 1 ], [ 0, 0, 1, 1, 1 ], [ 0, 0, 0, 1, 1 ], [ 0, 0, 0, 0, 1 ] ])
sage: L = LatticePoset((range(M.nrows()), lambda i,j: M[i,j] == 1))
sage: H = L._hasse_diagram
sage: (H.edges(labels=False), len(H))
([(0, 1), (1, 2), (2, 3), (3, 4)], 5)

I don't understand why you write a different labeling of the vertices, but I hope this helps.

edit flag offensive delete link more

Comments

Thanks... I got that part wrong!

slelievre gravatar imageslelievre ( 2020-10-03 17:04:57 +0100 )edit

The different labeling seems to be due to FindStat, but they don't explain anywhere how their canonical labeling works, as far as I can see.

rburing gravatar imagerburing ( 2020-10-03 17:23:22 +0100 )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: 2020-10-03 13:16:30 +0100

Seen: 278 times

Last updated: Oct 03 '20