Ask Your Question
1

Translating GAP-output into sage for lattices

asked 2020-10-03 06:16:30 -0500

klaaa gravatar image

updated 2020-10-03 06:19:50 -0500

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 10:03:45 -0500 )edit

2 answers

Sort by » oldest newest most voted
2

answered 2020-10-03 09:58:21 -0500

slelievre gravatar image

updated 2020-10-03 10:08:10 -0500

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 10:14:06 -0500 )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 11:49:37 -0500 )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 11:53:44 -0500 )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 13:14:27 -0500 )edit
2

answered 2020-10-03 09:53:59 -0500

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 10:04:57 -0500 )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 10:23:22 -0500 )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 06:16:30 -0500

Seen: 75 times

Last updated: Oct 03