ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 07 Oct 2020 19:43:07 +0200Obtaining a simplicial complex associated to a poset with the help of Sagehttps://ask.sagemath.org/question/53752/obtaining-a-simplicial-complex-associated-to-a-poset-with-the-help-of-sage/I want to associate to a finite poset a simplicial complex $\Delta(P)$ and study the homology(with coefficients in the rational numbers or a finite field) and the topological type of this simplicial complex using Sage. I have not yet used sage for this and wanted to ask whether there is an easy method to do this.
Let $P$ be a a finite poset with at least two elements and for $p \in P$ define two subsets as follows:
$J(p):=$ { $ g \in P | p \nleq g $ } and $I(p):=$ { $g \in P | g \leq p $ }.
For a subset $S$ of $P$ (we view $P$ also as set of its vertices) we then define
$J(S):= \bigcap\limits_{p \in S}^{}{J(p)}$ and $I(S):= \bigcup\limits_{p \in S}^{}{I(p)}$.
We set $J( \emptyset)=P, J(P)=\emptyset$ and $I(\emptyset)=\emptyset$, $I(P)=P$.
Then the simplicial complex $\Delta(P)$ is defined as the set of all subsets $S \subseteq P$ with $J(S^c) \subseteq I(S^c)$, where fore a subset $S \subseteq P$ we denote by $S^c$ the complement of $S$ in $P$.
For example when the poset $P$ is a chain with $n$-elements then $\Delta(P)$ should have topological type of the $(n-2)$-sphere.
I can obtain the sets $J(p)$ and $I(p)$ for elements but not for subsets in Sage, but I would think there is an easy trick.
Here is an example in Sage for a given poset $P$ :
P=posets.BooleanLattice(2)
display(P)
p=P[2]
I=[u for u in P if P.is_lequal(u,p)]
J=[u for u in P if not P.is_lequal(p,u)]
display(I)
display(J)
Thanks for any help.Wed, 07 Oct 2020 09:50:02 +0200https://ask.sagemath.org/question/53752/obtaining-a-simplicial-complex-associated-to-a-poset-with-the-help-of-sage/Comment by rburing for <p>I want to associate to a finite poset a simplicial complex $\Delta(P)$ and study the homology(with coefficients in the rational numbers or a finite field) and the topological type of this simplicial complex using Sage. I have not yet used sage for this and wanted to ask whether there is an easy method to do this. </p>
<p>Let $P$ be a a finite poset with at least two elements and for $p \in P$ define two subsets as follows:</p>
<p>$J(p):=$ { $ g \in P | p \nleq g $ } and $I(p):=$ { $g \in P | g \leq p $ }.</p>
<p>For a subset $S$ of $P$ (we view $P$ also as set of its vertices) we then define </p>
<p>$J(S):= \bigcap\limits_{p \in S}^{}{J(p)}$ and $I(S):= \bigcup\limits_{p \in S}^{}{I(p)}$.</p>
<p>We set $J( \emptyset)=P, J(P)=\emptyset$ and $I(\emptyset)=\emptyset$, $I(P)=P$.</p>
<p>Then the simplicial complex $\Delta(P)$ is defined as the set of all subsets $S \subseteq P$ with $J(S^c) \subseteq I(S^c)$, where fore a subset $S \subseteq P$ we denote by $S^c$ the complement of $S$ in $P$.</p>
<p>For example when the poset $P$ is a chain with $n$-elements then $\Delta(P)$ should have topological type of the $(n-2)$-sphere.</p>
<p>I can obtain the sets $J(p)$ and $I(p)$ for elements but not for subsets in Sage, but I would think there is an easy trick.</p>
<p>Here is an example in Sage for a given poset $P$ :</p>
<pre><code>P=posets.BooleanLattice(2)
display(P)
p=P[2]
I=[u for u in P if P.is_lequal(u,p)]
J=[u for u in P if not P.is_lequal(p,u)]
display(I)
display(J)
</code></pre>
<p>Thanks for any help.</p>
https://ask.sagemath.org/question/53752/obtaining-a-simplicial-complex-associated-to-a-poset-with-the-help-of-sage/?comment=53753#post-id-53753Please add the code you have so far, with an example $P$.Wed, 07 Oct 2020 09:57:31 +0200https://ask.sagemath.org/question/53752/obtaining-a-simplicial-complex-associated-to-a-poset-with-the-help-of-sage/?comment=53753#post-id-53753Comment by klaaa for <p>I want to associate to a finite poset a simplicial complex $\Delta(P)$ and study the homology(with coefficients in the rational numbers or a finite field) and the topological type of this simplicial complex using Sage. I have not yet used sage for this and wanted to ask whether there is an easy method to do this. </p>
<p>Let $P$ be a a finite poset with at least two elements and for $p \in P$ define two subsets as follows:</p>
<p>$J(p):=$ { $ g \in P | p \nleq g $ } and $I(p):=$ { $g \in P | g \leq p $ }.</p>
<p>For a subset $S$ of $P$ (we view $P$ also as set of its vertices) we then define </p>
<p>$J(S):= \bigcap\limits_{p \in S}^{}{J(p)}$ and $I(S):= \bigcup\limits_{p \in S}^{}{I(p)}$.</p>
<p>We set $J( \emptyset)=P, J(P)=\emptyset$ and $I(\emptyset)=\emptyset$, $I(P)=P$.</p>
<p>Then the simplicial complex $\Delta(P)$ is defined as the set of all subsets $S \subseteq P$ with $J(S^c) \subseteq I(S^c)$, where fore a subset $S \subseteq P$ we denote by $S^c$ the complement of $S$ in $P$.</p>
<p>For example when the poset $P$ is a chain with $n$-elements then $\Delta(P)$ should have topological type of the $(n-2)$-sphere.</p>
<p>I can obtain the sets $J(p)$ and $I(p)$ for elements but not for subsets in Sage, but I would think there is an easy trick.</p>
<p>Here is an example in Sage for a given poset $P$ :</p>
<pre><code>P=posets.BooleanLattice(2)
display(P)
p=P[2]
I=[u for u in P if P.is_lequal(u,p)]
J=[u for u in P if not P.is_lequal(p,u)]
display(I)
display(J)
</code></pre>
<p>Thanks for any help.</p>
https://ask.sagemath.org/question/53752/obtaining-a-simplicial-complex-associated-to-a-poset-with-the-help-of-sage/?comment=53754#post-id-53754I added a small example for the Boolean lattice on how to obtain $J(p)$ and $I(p)$.Wed, 07 Oct 2020 10:09:56 +0200https://ask.sagemath.org/question/53752/obtaining-a-simplicial-complex-associated-to-a-poset-with-the-help-of-sage/?comment=53754#post-id-53754Answer by FrédéricC for <p>I want to associate to a finite poset a simplicial complex $\Delta(P)$ and study the homology(with coefficients in the rational numbers or a finite field) and the topological type of this simplicial complex using Sage. I have not yet used sage for this and wanted to ask whether there is an easy method to do this. </p>
<p>Let $P$ be a a finite poset with at least two elements and for $p \in P$ define two subsets as follows:</p>
<p>$J(p):=$ { $ g \in P | p \nleq g $ } and $I(p):=$ { $g \in P | g \leq p $ }.</p>
<p>For a subset $S$ of $P$ (we view $P$ also as set of its vertices) we then define </p>
<p>$J(S):= \bigcap\limits_{p \in S}^{}{J(p)}$ and $I(S):= \bigcup\limits_{p \in S}^{}{I(p)}$.</p>
<p>We set $J( \emptyset)=P, J(P)=\emptyset$ and $I(\emptyset)=\emptyset$, $I(P)=P$.</p>
<p>Then the simplicial complex $\Delta(P)$ is defined as the set of all subsets $S \subseteq P$ with $J(S^c) \subseteq I(S^c)$, where fore a subset $S \subseteq P$ we denote by $S^c$ the complement of $S$ in $P$.</p>
<p>For example when the poset $P$ is a chain with $n$-elements then $\Delta(P)$ should have topological type of the $(n-2)$-sphere.</p>
<p>I can obtain the sets $J(p)$ and $I(p)$ for elements but not for subsets in Sage, but I would think there is an easy trick.</p>
<p>Here is an example in Sage for a given poset $P$ :</p>
<pre><code>P=posets.BooleanLattice(2)
display(P)
p=P[2]
I=[u for u in P if P.is_lequal(u,p)]
J=[u for u in P if not P.is_lequal(p,u)]
display(I)
display(J)
</code></pre>
<p>Thanks for any help.</p>
https://ask.sagemath.org/question/53752/obtaining-a-simplicial-complex-associated-to-a-poset-with-the-help-of-sage/?answer=53755#post-id-53755something like this maybe (not tested)
def test_subset(P, S):
Sc = set(g for g in P if g not in S)
in_ISc = lambda g: any(s in Sc for s in P.principal_order_filter(g))
JSc = (g for g in P if not any(s in Sc
for s in P.principal_order_ideal(g)))
return all(in_ISc(g) for g in JSc)Wed, 07 Oct 2020 12:26:37 +0200https://ask.sagemath.org/question/53752/obtaining-a-simplicial-complex-associated-to-a-poset-with-the-help-of-sage/?answer=53755#post-id-53755Comment by klaaa for <p>something like this maybe (not tested)</p>
<pre><code>def test_subset(P, S):
Sc = set(g for g in P if g not in S)
in_ISc = lambda g: any(s in Sc for s in P.principal_order_filter(g))
JSc = (g for g in P if not any(s in Sc
for s in P.principal_order_ideal(g)))
return all(in_ISc(g) for g in JSc)
</code></pre>
https://ask.sagemath.org/question/53752/obtaining-a-simplicial-complex-associated-to-a-poset-with-the-help-of-sage/?comment=53760#post-id-53760Thank you very much again. It seems to work now. I combined it and obtained the simplicial complex as follows:
def test_subset(P, S):
Sc = set(g for g in P if g not in S)
in_ISc = lambda g: any(s in Sc for s in P.principal_order_filter(g))
JSc = (g for g in P if not any(s in Sc
for s in P.principal_order_ideal(g)))
return all(in_ISc(g) for g in JSc)
P=posets.ChainPoset(4)
P=P.relabel()
U = Subsets(P)
G=[t for t in U if test_subset(P, t)==true]
GG=[list(r) for r in G]
display(GG)
S=SimplicialComplex(GG)
display(S)
phi, M = S.algebraic_topological_model(QQ)
M.homology()Wed, 07 Oct 2020 16:40:38 +0200https://ask.sagemath.org/question/53752/obtaining-a-simplicial-complex-associated-to-a-poset-with-the-help-of-sage/?comment=53760#post-id-53760Comment by klaaa for <p>something like this maybe (not tested)</p>
<pre><code>def test_subset(P, S):
Sc = set(g for g in P if g not in S)
in_ISc = lambda g: any(s in Sc for s in P.principal_order_filter(g))
JSc = (g for g in P if not any(s in Sc
for s in P.principal_order_ideal(g)))
return all(in_ISc(g) for g in JSc)
</code></pre>
https://ask.sagemath.org/question/53752/obtaining-a-simplicial-complex-associated-to-a-poset-with-the-help-of-sage/?comment=53761#post-id-53761Do you know whether I calcuate the homology the right way over the rational numbers QQ? It seems I have to use the strange command
phi, M = S.algebraic_topological_model(QQ)
and I do not quite know why I need to write the phi before the M.
Also do you know whether there is a command to check whether the simplicial complex is topologically homeomorphic to a sphere?Wed, 07 Oct 2020 16:41:55 +0200https://ask.sagemath.org/question/53752/obtaining-a-simplicial-complex-associated-to-a-poset-with-the-help-of-sage/?comment=53761#post-id-53761Comment by FrédéricC for <p>something like this maybe (not tested)</p>
<pre><code>def test_subset(P, S):
Sc = set(g for g in P if g not in S)
in_ISc = lambda g: any(s in Sc for s in P.principal_order_filter(g))
JSc = (g for g in P if not any(s in Sc
for s in P.principal_order_ideal(g)))
return all(in_ISc(g) for g in JSc)
</code></pre>
https://ask.sagemath.org/question/53752/obtaining-a-simplicial-complex-associated-to-a-poset-with-the-help-of-sage/?comment=53762#post-id-53762Just use `S.homology(base_ring=QQ)`. This gives reduced homology.Wed, 07 Oct 2020 18:49:23 +0200https://ask.sagemath.org/question/53752/obtaining-a-simplicial-complex-associated-to-a-poset-with-the-help-of-sage/?comment=53762#post-id-53762Comment by John Palmieri for <p>something like this maybe (not tested)</p>
<pre><code>def test_subset(P, S):
Sc = set(g for g in P if g not in S)
in_ISc = lambda g: any(s in Sc for s in P.principal_order_filter(g))
JSc = (g for g in P if not any(s in Sc
for s in P.principal_order_ideal(g)))
return all(in_ISc(g) for g in JSc)
</code></pre>
https://ask.sagemath.org/question/53752/obtaining-a-simplicial-complex-associated-to-a-poset-with-the-help-of-sage/?comment=53763#post-id-53763Mathematically, how do you check if a simplicial complex is homeomorphic to a sphere?Wed, 07 Oct 2020 19:08:35 +0200https://ask.sagemath.org/question/53752/obtaining-a-simplicial-complex-associated-to-a-poset-with-the-help-of-sage/?comment=53763#post-id-53763Comment by John Palmieri for <p>something like this maybe (not tested)</p>
<pre><code>def test_subset(P, S):
Sc = set(g for g in P if g not in S)
in_ISc = lambda g: any(s in Sc for s in P.principal_order_filter(g))
JSc = (g for g in P if not any(s in Sc
for s in P.principal_order_ideal(g)))
return all(in_ISc(g) for g in JSc)
</code></pre>
https://ask.sagemath.org/question/53752/obtaining-a-simplicial-complex-associated-to-a-poset-with-the-help-of-sage/?comment=53764#post-id-53764You can check things like `S.is_pseudomanifold()` and `S.fundamental_group()` to see if it has a chance to be a sphere, but I don't know how to definitively check the homeomorphism type of a simplicial complex.Wed, 07 Oct 2020 19:12:55 +0200https://ask.sagemath.org/question/53752/obtaining-a-simplicial-complex-associated-to-a-poset-with-the-help-of-sage/?comment=53764#post-id-53764Comment by John Palmieri for <p>something like this maybe (not tested)</p>
<pre><code>def test_subset(P, S):
Sc = set(g for g in P if g not in S)
in_ISc = lambda g: any(s in Sc for s in P.principal_order_filter(g))
JSc = (g for g in P if not any(s in Sc
for s in P.principal_order_ideal(g)))
return all(in_ISc(g) for g in JSc)
</code></pre>
https://ask.sagemath.org/question/53752/obtaining-a-simplicial-complex-associated-to-a-poset-with-the-help-of-sage/?comment=53765#post-id-53765You can also check `S.is_shellable()`.Wed, 07 Oct 2020 19:43:07 +0200https://ask.sagemath.org/question/53752/obtaining-a-simplicial-complex-associated-to-a-poset-with-the-help-of-sage/?comment=53765#post-id-53765Comment by FrédéricC for <p>something like this maybe (not tested)</p>
<pre><code>def test_subset(P, S):
Sc = set(g for g in P if g not in S)
in_ISc = lambda g: any(s in Sc for s in P.principal_order_filter(g))
JSc = (g for g in P if not any(s in Sc
for s in P.principal_order_ideal(g)))
return all(in_ISc(g) for g in JSc)
</code></pre>
https://ask.sagemath.org/question/53752/obtaining-a-simplicial-complex-associated-to-a-poset-with-the-help-of-sage/?comment=53759#post-id-53759There was a typo "Isc" versus ISc.Wed, 07 Oct 2020 15:26:56 +0200https://ask.sagemath.org/question/53752/obtaining-a-simplicial-complex-associated-to-a-poset-with-the-help-of-sage/?comment=53759#post-id-53759Comment by klaaa for <p>something like this maybe (not tested)</p>
<pre><code>def test_subset(P, S):
Sc = set(g for g in P if g not in S)
in_ISc = lambda g: any(s in Sc for s in P.principal_order_filter(g))
JSc = (g for g in P if not any(s in Sc
for s in P.principal_order_ideal(g)))
return all(in_ISc(g) for g in JSc)
</code></pre>
https://ask.sagemath.org/question/53752/obtaining-a-simplicial-complex-associated-to-a-poset-with-the-help-of-sage/?comment=53757#post-id-53757Thank you very much, but it seems to not work for every subset. For example here it works:
def test_subset(P, S):
Sc = set(g for g in P if g not in S)
in_ISc = lambda g: any(s in Sc for s in P.principal_order_filter(g))
Jsc = (g for g in P if not any(s in Sc
for s in P.principal_order_ideal(g)))
return all(in_Isc(g) for g in Jsc)
P=posets.BooleanLattice(2)
U = Subsets(P)
T=U[2]
display(T)
test_subset(P, T)
but for the same poset P with another subset it does not work and gives an error (see next comment)Wed, 07 Oct 2020 13:32:19 +0200https://ask.sagemath.org/question/53752/obtaining-a-simplicial-complex-associated-to-a-poset-with-the-help-of-sage/?comment=53757#post-id-53757Comment by klaaa for <p>something like this maybe (not tested)</p>
<pre><code>def test_subset(P, S):
Sc = set(g for g in P if g not in S)
in_ISc = lambda g: any(s in Sc for s in P.principal_order_filter(g))
JSc = (g for g in P if not any(s in Sc
for s in P.principal_order_ideal(g)))
return all(in_ISc(g) for g in JSc)
</code></pre>
https://ask.sagemath.org/question/53752/obtaining-a-simplicial-complex-associated-to-a-poset-with-the-help-of-sage/?comment=53758#post-id-53758Here it gives an error:
def test_subset(P, S):
Sc = set(g for g in P if g not in S)
in_ISc = lambda g: any(s in Sc for s in P.principal_order_filter(g))
Jsc = (g for g in P if not any(s in Sc
for s in P.principal_order_ideal(g)))
return all(in_Isc(g) for g in Jsc)
P=posets.BooleanLattice(2)
U = Subsets(P)
T=U[1]
display(T)
test_subset(P, T)Wed, 07 Oct 2020 13:32:31 +0200https://ask.sagemath.org/question/53752/obtaining-a-simplicial-complex-associated-to-a-poset-with-the-help-of-sage/?comment=53758#post-id-53758