# How to obtain all finite connected distributive lattices with SAGE

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 close merge delete

1

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

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

with open('really.txt','w') as f:
f.write(txt)


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?

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.

Sort by » oldest newest most voted 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()]

more

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

1

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