ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 20 Sep 2017 17:29:38 -0500How to obtain all finite connected distributive lattices with SAGEhttp://ask.sagemath.org/question/38878/how-to-obtain-all-finite-connected-distributive-lattices-with-sage/In https://ask.sagemath.org/question/38865/obtaining-all-posets-in-a-certain-form-with-sage/ 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/reference/combinat/sage/combinat/posets/lattices.html#) 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/remove-line-breaks.php to remove line breaks in text. I wonder if there is a basic way using texteditors without the internet.Wed, 20 Sep 2017 12:59:36 -0500http://ask.sagemath.org/question/38878/how-to-obtain-all-finite-connected-distributive-lattices-with-sage/Comment by John Palmieri for <p>In <a href="https://ask.sagemath.org/question/38865/obtaining-all-posets-in-a-certain-form-with-sage/">https://ask.sagemath.org/question/388...</a> 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.</p>
<p>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]</p>
<p>This worked for me. But if I try to obtain now in addition all distributive lattices via the command is_distributive() (found here: <a href="http://doc.sagemath.org/html/en/reference/combinat/sage/combinat/posets/lattices.html">http://doc.sagemath.org/html/en/refer...</a>) 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?</p>
<p>And is there a way to obtain all connected finite posets with n points having a global maximum and a global minimum?</p>
<p>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"]] ],</p>
<p>[["x1", "x2", "x3"], [["x1", "x2"], ["x2", "x3"]]],</p>
<p>[["x1", "x2", "x3"], [["x1", "x3"], ["x2", "x3"]]]]</p>
<p>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)</p>
<p>edit: For my second problem I found the website <a href="https://www.textfixer.com/tools/remove-line-breaks.php">https://www.textfixer.com/tools/remov...</a> to remove line breaks in text. I wonder if there is a basic way using texteditors without the internet.</p>
http://ask.sagemath.org/question/38878/how-to-obtain-all-finite-connected-distributive-lattices-with-sage/?comment=38887#post-id-38887For 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.Wed, 20 Sep 2017 15:28:58 -0500http://ask.sagemath.org/question/38878/how-to-obtain-all-finite-connected-distributive-lattices-with-sage/?comment=38887#post-id-38887Comment by sagequstions for <p>In <a href="https://ask.sagemath.org/question/38865/obtaining-all-posets-in-a-certain-form-with-sage/">https://ask.sagemath.org/question/388...</a> 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.</p>
<p>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]</p>
<p>This worked for me. But if I try to obtain now in addition all distributive lattices via the command is_distributive() (found here: <a href="http://doc.sagemath.org/html/en/reference/combinat/sage/combinat/posets/lattices.html">http://doc.sagemath.org/html/en/refer...</a>) 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?</p>
<p>And is there a way to obtain all connected finite posets with n points having a global maximum and a global minimum?</p>
<p>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"]] ],</p>
<p>[["x1", "x2", "x3"], [["x1", "x2"], ["x2", "x3"]]],</p>
<p>[["x1", "x2", "x3"], [["x1", "x3"], ["x2", "x3"]]]]</p>
<p>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)</p>
<p>edit: For my second problem I found the website <a href="https://www.textfixer.com/tools/remove-line-breaks.php">https://www.textfixer.com/tools/remov...</a> to remove line breaks in text. I wonder if there is a basic way using texteditors without the internet.</p>
http://ask.sagemath.org/question/38878/how-to-obtain-all-finite-connected-distributive-lattices-with-sage/?comment=38884#post-id-38884Good 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?Wed, 20 Sep 2017 15:04:11 -0500http://ask.sagemath.org/question/38878/how-to-obtain-all-finite-connected-distributive-lattices-with-sage/?comment=38884#post-id-38884Comment by FrédéricC for <p>In <a href="https://ask.sagemath.org/question/38865/obtaining-all-posets-in-a-certain-form-with-sage/">https://ask.sagemath.org/question/388...</a> 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.</p>
<p>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]</p>
<p>This worked for me. But if I try to obtain now in addition all distributive lattices via the command is_distributive() (found here: <a href="http://doc.sagemath.org/html/en/reference/combinat/sage/combinat/posets/lattices.html">http://doc.sagemath.org/html/en/refer...</a>) 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?</p>
<p>And is there a way to obtain all connected finite posets with n points having a global maximum and a global minimum?</p>
<p>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"]] ],</p>
<p>[["x1", "x2", "x3"], [["x1", "x2"], ["x2", "x3"]]],</p>
<p>[["x1", "x2", "x3"], [["x1", "x3"], ["x2", "x3"]]]]</p>
<p>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)</p>
<p>edit: For my second problem I found the website <a href="https://www.textfixer.com/tools/remove-line-breaks.php">https://www.textfixer.com/tools/remov...</a> to remove line breaks in text. I wonder if there is a basic way using texteditors without the internet.</p>
http://ask.sagemath.org/question/38878/how-to-obtain-all-finite-connected-distributive-lattices-with-sage/?comment=38882#post-id-38882You can just save your text (say the variable txt) using
with open('really.txt','w') as f:
f.write(txt)Wed, 20 Sep 2017 14:13:48 -0500http://ask.sagemath.org/question/38878/how-to-obtain-all-finite-connected-distributive-lattices-with-sage/?comment=38882#post-id-38882Comment by FrédéricC for <p>In <a href="https://ask.sagemath.org/question/38865/obtaining-all-posets-in-a-certain-form-with-sage/">https://ask.sagemath.org/question/388...</a> 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.</p>
<p>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]</p>
<p>This worked for me. But if I try to obtain now in addition all distributive lattices via the command is_distributive() (found here: <a href="http://doc.sagemath.org/html/en/reference/combinat/sage/combinat/posets/lattices.html">http://doc.sagemath.org/html/en/refer...</a>) 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?</p>
<p>And is there a way to obtain all connected finite posets with n points having a global maximum and a global minimum?</p>
<p>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"]] ],</p>
<p>[["x1", "x2", "x3"], [["x1", "x2"], ["x2", "x3"]]],</p>
<p>[["x1", "x2", "x3"], [["x1", "x3"], ["x2", "x3"]]]]</p>
<p>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)</p>
<p>edit: For my second problem I found the website <a href="https://www.textfixer.com/tools/remove-line-breaks.php">https://www.textfixer.com/tools/remov...</a> to remove line breaks in text. I wonder if there is a basic way using texteditors without the internet.</p>
http://ask.sagemath.org/question/38878/how-to-obtain-all-finite-connected-distributive-lattices-with-sage/?comment=38881#post-id-38881You could try to start from the list of posets and take their .order_ideals_lattice()Wed, 20 Sep 2017 14:10:18 -0500http://ask.sagemath.org/question/38878/how-to-obtain-all-finite-connected-distributive-lattices-with-sage/?comment=38881#post-id-38881Answer by John Palmieri for <p>In <a href="https://ask.sagemath.org/question/38865/obtaining-all-posets-in-a-certain-form-with-sage/">https://ask.sagemath.org/question/388...</a> 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.</p>
<p>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]</p>
<p>This worked for me. But if I try to obtain now in addition all distributive lattices via the command is_distributive() (found here: <a href="http://doc.sagemath.org/html/en/reference/combinat/sage/combinat/posets/lattices.html">http://doc.sagemath.org/html/en/refer...</a>) 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?</p>
<p>And is there a way to obtain all connected finite posets with n points having a global maximum and a global minimum?</p>
<p>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"]] ],</p>
<p>[["x1", "x2", "x3"], [["x1", "x2"], ["x2", "x3"]]],</p>
<p>[["x1", "x2", "x3"], [["x1", "x3"], ["x2", "x3"]]]]</p>
<p>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)</p>
<p>edit: For my second problem I found the website <a href="https://www.textfixer.com/tools/remove-line-breaks.php">https://www.textfixer.com/tools/remov...</a> to remove line breaks in text. I wonder if there is a basic way using texteditors without the internet.</p>
http://ask.sagemath.org/question/38878/how-to-obtain-all-finite-connected-distributive-lattices-with-sage/?answer=38886#post-id-38886The 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()]
Wed, 20 Sep 2017 15:23:46 -0500http://ask.sagemath.org/question/38878/how-to-obtain-all-finite-connected-distributive-lattices-with-sage/?answer=38886#post-id-38886Comment by John Palmieri for <p>The issue is that <code>is_distributive</code> 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:</p>
<pre><code>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()]
</code></pre>
<p>Here <code>LatticePoset(p)</code> converts the poset <code>p</code> explicitly into a lattice. You could instead use this at the end</p>
<pre><code>sage: lattices = [LatticePoset(p) for p in posets if LatticePoset(p).is_distributive()]
</code></pre>
<p>so that the elements of <code>lattices</code> are lattices, not just posets. Or do the conversion first:</p>
<pre><code>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()]
</code></pre>
http://ask.sagemath.org/question/38878/how-to-obtain-all-finite-connected-distributive-lattices-with-sage/?comment=38896#post-id-38896How about `p.has_bottom()` and `p.has_top()`?Wed, 20 Sep 2017 17:29:38 -0500http://ask.sagemath.org/question/38878/how-to-obtain-all-finite-connected-distributive-lattices-with-sage/?comment=38896#post-id-38896Comment by sagequstions for <p>The issue is that <code>is_distributive</code> 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:</p>
<pre><code>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()]
</code></pre>
<p>Here <code>LatticePoset(p)</code> converts the poset <code>p</code> explicitly into a lattice. You could instead use this at the end</p>
<pre><code>sage: lattices = [LatticePoset(p) for p in posets if LatticePoset(p).is_distributive()]
</code></pre>
<p>so that the elements of <code>lattices</code> are lattices, not just posets. Or do the conversion first:</p>
<pre><code>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()]
</code></pre>
http://ask.sagemath.org/question/38878/how-to-obtain-all-finite-connected-distributive-lattices-with-sage/?comment=38888#post-id-38888Thank you, do you also have a command to filter out all connected posets having a global maximum and a global minimum?Wed, 20 Sep 2017 15:40:09 -0500http://ask.sagemath.org/question/38878/how-to-obtain-all-finite-connected-distributive-lattices-with-sage/?comment=38888#post-id-38888