Ask Your Question
0

How to obtain all finite connected distributive lattices with SAGE

asked 2017-09-20 19:59:36 +0200

sagequstions gravatar image

updated 2017-09-20 20:53:59 +0200

In https://ask.sagemath.org/question/388... I asked for a programm that translates all finite posets into a given form. Now I want to do the same with all finite connected distributive lattices instead of all connected posets.

First I wanted it with all lattices, I changed the code posets = [ p for p in Posets(n) if p.is_connected() ] into posets = [ p for p in Posets(n) if p.is_connected() and p.is_lattice]

This worked for me. But if I try to obtain now in addition all distributive lattices via the command is_distributive() (found here: http://doc.sagemath.org/html/en/refer...) I get an error when I try into posets = [ p for p in Posets(n) if p.is_connected() and p.is_lattice() and p.is_distributive()]. How to fix that?

And is there a way to obtain all connected finite posets with n points having a global maximum and a global minimum?

Another question: I want to use the SAGE output of this to define a list in GAP. The problem is that I cannot directly copy paste since GAP allows me to define a list only in case the list occupies only one line. (for example [ [["x1", "x2", "x3"], [["x1", "x2"], ["x1", "x3"]] ],

[["x1", "x2", "x3"], [["x1", "x2"], ["x2", "x3"]]],

[["x1", "x2", "x3"], [["x1", "x3"], ["x2", "x3"]]]]

is not ok for GAP but [ [["x1", "x2", "x3"], [["x1", "x2"], ["x1", "x3"]] ], [["x1", "x2", "x3"], [["x1", "x2"], ["x2", "x3"]]], [["x1", "x2", "x3"], [["x1", "x3"], ["x2", "x3"]]]] is ok when it is in one line). Is there a way to obtain the SAGE output in one line or is there a textmanager that can do such a thing? (this is a problem in case the SAGE output is very long)

edit: For my second problem I found the website https://www.textfixer.com/tools/remov... to remove line breaks in text. I wonder if there is a basic way using texteditors without the internet.

edit retag flag offensive close merge delete

Comments

1

You could try to start from the list of posets and take their .order_ideals_lattice()

FrédéricC gravatar imageFrédéricC ( 2017-09-20 21:10:18 +0200 )edit

You can just save your text (say the variable txt) using

with open('really.txt','w') as f:
    f.write(txt)
FrédéricC gravatar imageFrédéricC ( 2017-09-20 21:13:48 +0200 )edit

Good idea to use order ideals but why does the command is_distributive() not work? Maybe I can get all lattices directly without filtering and then the command works?

sagequstions gravatar imagesagequstions ( 2017-09-20 22:04:11 +0200 )edit
1

For the second problem, if m represents your data, str(m) or print(m) should give you the output with no line breaks. Just m tries to present the output in a more readable format.

John Palmieri gravatar imageJohn Palmieri ( 2017-09-20 22:28:58 +0200 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2017-09-20 22:23:46 +0200

The issue is that is_distributive is not defined for all posets, just for lattices -- that is, on the Sage data type of Lattice, not Poset. So one option would be to find all lattices and then filter those:

sage: n = 6
sage: posets = [p for p in Posets(n) if p.is_connected() and p.is_lattice()]
sage: lattices = [p for p in posets if LatticePoset(p).is_distributive()]

Here LatticePoset(p) converts the poset p explicitly into a lattice. You could instead use this at the end

sage: lattices = [LatticePoset(p) for p in posets if LatticePoset(p).is_distributive()]

so that the elements of lattices are lattices, not just posets. Or do the conversion first:

sage: n = 6
sage: lattices = [LatticePoset(p) for p in Posets(n) if p.is_connected() and p.is_lattice()]
sage: distributive_lattices = [p for p in lattices if p.is_distributive()]
edit flag offensive delete link more

Comments

Thank you, do you also have a command to filter out all connected posets having a global maximum and a global minimum?

sagequstions gravatar imagesagequstions ( 2017-09-20 22:40:09 +0200 )edit
1

How about p.has_bottom() and p.has_top()?

John Palmieri gravatar imageJohn Palmieri ( 2017-09-21 00:29:38 +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: 2017-09-20 19:59:36 +0200

Seen: 510 times

Last updated: Sep 20 '17