ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 02 Oct 2013 07:53:21 -0500Using `SimplicalComplex` on a set of setshttps://ask.sagemath.org/question/10581/using-simplicalcomplex-on-a-set-of-sets/Say I have something like this:
[{{1,2},{2,3}} , {{1,2},{3,4}}]
So I have a list of sets consisting of subsets of $1,2,...,n\space$ (in general the lists I am interested in are longer). I get these by using `Subset(X,n)`. Now I want to look at the simplicial complex with facets `{1,2},{2,3}` and then the simplical complex with facets `{1,3},{3,6}` and so on.
Now the `SimplicialComplex` command only works for lists like so:
SimplicialComplex([[0,1], [1,2], [0,2]])
See [here](http://www.sagemath.org/doc/reference/homology/sage/homology/simplicial_complex.html) for more info on finite simplical complexes in sage.
My question is: what is the best way to go from my set of sets to a list of lists?
More generally what is the best way to deal the fact that most enumerative combinatorics I can do in sage gives me sets but for `SimplicialComplex` I need lists?Sun, 29 Sep 2013 15:12:02 -0500https://ask.sagemath.org/question/10581/using-simplicalcomplex-on-a-set-of-sets/Answer by John Palmieri for <p>Say I have something like this: </p>
<pre><code>[{{1,2},{2,3}} , {{1,2},{3,4}}]
</code></pre>
<p>So I have a list of sets consisting of subsets of $1,2,...,n\space$ (in general the lists I am interested in are longer). I get these by using <code>Subset(X,n)</code>. Now I want to look at the simplicial complex with facets <code>{1,2},{2,3}</code> and then the simplical complex with facets <code>{1,3},{3,6}</code> and so on.</p>
<p>Now the <code>SimplicialComplex</code> command only works for lists like so: </p>
<pre><code>SimplicialComplex([[0,1], [1,2], [0,2]])
</code></pre>
<p>See <a href="http://www.sagemath.org/doc/reference/homology/sage/homology/simplicial_complex.html">here</a> for more info on finite simplical complexes in sage.</p>
<p>My question is: what is the best way to go from my set of sets to a list of lists?</p>
<p>More generally what is the best way to deal the fact that most enumerative combinatorics I can do in sage gives me sets but for <code>SimplicialComplex</code> I need lists?</p>
https://ask.sagemath.org/question/10581/using-simplicalcomplex-on-a-set-of-sets/?answer=15513#post-id-15513I don't think I understand your question: in what way don't sets work when defining a simplicial complex? I tried the following in Sage 5.11, Sage 5.6, and in the most recent beta release, and it worked in all of them:
sage: S = Set([Set([1,2]),Set([2,3])])
sage: SimplicialComplex(S)
Simplicial complex with vertex set (1, 2, 3) and facets {(1, 2), (2, 3)}
sage: S = [{1,2}, {2,3}]
sage: SimplicialComplex(S)
Simplicial complex with vertex set (1, 2, 3) and facets {(1, 2), (2, 3)}
sage: S = Subsets({1,2,3}, 2)
sage: SimplicialComplex(S)
Simplicial complex with vertex set (1, 2, 3) and facets {(1, 3), (1, 2), (2, 3)}
In the documentation that you cited, it says
> `maximal_faces` should be a list or
> tuple or set (indeed, anything which
> may be converted to a set) whose
> elements are lists (or tuples, etc.)
> of vertices.
So sets should be allowed, and they seem to work.Mon, 30 Sep 2013 04:33:37 -0500https://ask.sagemath.org/question/10581/using-simplicalcomplex-on-a-set-of-sets/?answer=15513#post-id-15513Comment by John Palmieri for <p>I don't think I understand your question: in what way don't sets work when defining a simplicial complex? I tried the following in Sage 5.11, Sage 5.6, and in the most recent beta release, and it worked in all of them:</p>
<pre><code>sage: S = Set([Set([1,2]),Set([2,3])])
sage: SimplicialComplex(S)
Simplicial complex with vertex set (1, 2, 3) and facets {(1, 2), (2, 3)}
sage: S = [{1,2}, {2,3}]
sage: SimplicialComplex(S)
Simplicial complex with vertex set (1, 2, 3) and facets {(1, 2), (2, 3)}
sage: S = Subsets({1,2,3}, 2)
sage: SimplicialComplex(S)
Simplicial complex with vertex set (1, 2, 3) and facets {(1, 3), (1, 2), (2, 3)}
</code></pre>
<p>In the documentation that you cited, it says</p>
<blockquote>
<p><code>maximal_faces</code> should be a list or
tuple or set (indeed, anything which
may be converted to a set) whose
elements are lists (or tuples, etc.)
of vertices.</p>
</blockquote>
<p>So sets should be allowed, and they seem to work.</p>
https://ask.sagemath.org/question/10581/using-simplicalcomplex-on-a-set-of-sets/?comment=16965#post-id-16965sagenb.org seems to be running Sage 5.4, which is rather old. That's the problem. I'll see if the version can be updated.Wed, 02 Oct 2013 04:53:39 -0500https://ask.sagemath.org/question/10581/using-simplicalcomplex-on-a-set-of-sets/?comment=16965#post-id-16965Comment by tmonteil for <p>I don't think I understand your question: in what way don't sets work when defining a simplicial complex? I tried the following in Sage 5.11, Sage 5.6, and in the most recent beta release, and it worked in all of them:</p>
<pre><code>sage: S = Set([Set([1,2]),Set([2,3])])
sage: SimplicialComplex(S)
Simplicial complex with vertex set (1, 2, 3) and facets {(1, 2), (2, 3)}
sage: S = [{1,2}, {2,3}]
sage: SimplicialComplex(S)
Simplicial complex with vertex set (1, 2, 3) and facets {(1, 2), (2, 3)}
sage: S = Subsets({1,2,3}, 2)
sage: SimplicialComplex(S)
Simplicial complex with vertex set (1, 2, 3) and facets {(1, 3), (1, 2), (2, 3)}
</code></pre>
<p>In the documentation that you cited, it says</p>
<blockquote>
<p><code>maximal_faces</code> should be a list or
tuple or set (indeed, anything which
may be converted to a set) whose
elements are lists (or tuples, etc.)
of vertices.</p>
</blockquote>
<p>So sets should be allowed, and they seem to work.</p>
https://ask.sagemath.org/question/10581/using-simplicalcomplex-on-a-set-of-sets/?comment=16964#post-id-16964@alexandru-papiu just in case: notice that there is a difference between Sage `Set` and python `set` (note the case).Wed, 02 Oct 2013 07:04:04 -0500https://ask.sagemath.org/question/10581/using-simplicalcomplex-on-a-set-of-sets/?comment=16964#post-id-16964Comment by Alexandru Papiu for <p>I don't think I understand your question: in what way don't sets work when defining a simplicial complex? I tried the following in Sage 5.11, Sage 5.6, and in the most recent beta release, and it worked in all of them:</p>
<pre><code>sage: S = Set([Set([1,2]),Set([2,3])])
sage: SimplicialComplex(S)
Simplicial complex with vertex set (1, 2, 3) and facets {(1, 2), (2, 3)}
sage: S = [{1,2}, {2,3}]
sage: SimplicialComplex(S)
Simplicial complex with vertex set (1, 2, 3) and facets {(1, 2), (2, 3)}
sage: S = Subsets({1,2,3}, 2)
sage: SimplicialComplex(S)
Simplicial complex with vertex set (1, 2, 3) and facets {(1, 3), (1, 2), (2, 3)}
</code></pre>
<p>In the documentation that you cited, it says</p>
<blockquote>
<p><code>maximal_faces</code> should be a list or
tuple or set (indeed, anything which
may be converted to a set) whose
elements are lists (or tuples, etc.)
of vertices.</p>
</blockquote>
<p>So sets should be allowed, and they seem to work.</p>
https://ask.sagemath.org/question/10581/using-simplicalcomplex-on-a-set-of-sets/?comment=16966#post-id-16966Interesting. I am using the online sage notebook at http://www.sagenb.org/ and sets of sets do not work for me. I get the error `TypeError: unhashable type: 'set'` when I try the second option you describe above. And for the other two the simplical complexes I get are incorrect. Tue, 01 Oct 2013 18:50:58 -0500https://ask.sagemath.org/question/10581/using-simplicalcomplex-on-a-set-of-sets/?comment=16966#post-id-16966Comment by John Palmieri for <p>I don't think I understand your question: in what way don't sets work when defining a simplicial complex? I tried the following in Sage 5.11, Sage 5.6, and in the most recent beta release, and it worked in all of them:</p>
<pre><code>sage: S = Set([Set([1,2]),Set([2,3])])
sage: SimplicialComplex(S)
Simplicial complex with vertex set (1, 2, 3) and facets {(1, 2), (2, 3)}
sage: S = [{1,2}, {2,3}]
sage: SimplicialComplex(S)
Simplicial complex with vertex set (1, 2, 3) and facets {(1, 2), (2, 3)}
sage: S = Subsets({1,2,3}, 2)
sage: SimplicialComplex(S)
Simplicial complex with vertex set (1, 2, 3) and facets {(1, 3), (1, 2), (2, 3)}
</code></pre>
<p>In the documentation that you cited, it says</p>
<blockquote>
<p><code>maximal_faces</code> should be a list or
tuple or set (indeed, anything which
may be converted to a set) whose
elements are lists (or tuples, etc.)
of vertices.</p>
</blockquote>
<p>So sets should be allowed, and they seem to work.</p>
https://ask.sagemath.org/question/10581/using-simplicalcomplex-on-a-set-of-sets/?comment=16963#post-id-16963It looks like sagenb.org will get updated some time this week.Wed, 02 Oct 2013 07:53:21 -0500https://ask.sagemath.org/question/10581/using-simplicalcomplex-on-a-set-of-sets/?comment=16963#post-id-16963Answer by tmonteil for <p>Say I have something like this: </p>
<pre><code>[{{1,2},{2,3}} , {{1,2},{3,4}}]
</code></pre>
<p>So I have a list of sets consisting of subsets of $1,2,...,n\space$ (in general the lists I am interested in are longer). I get these by using <code>Subset(X,n)</code>. Now I want to look at the simplicial complex with facets <code>{1,2},{2,3}</code> and then the simplical complex with facets <code>{1,3},{3,6}</code> and so on.</p>
<p>Now the <code>SimplicialComplex</code> command only works for lists like so: </p>
<pre><code>SimplicialComplex([[0,1], [1,2], [0,2]])
</code></pre>
<p>See <a href="http://www.sagemath.org/doc/reference/homology/sage/homology/simplicial_complex.html">here</a> for more info on finite simplical complexes in sage.</p>
<p>My question is: what is the best way to go from my set of sets to a list of lists?</p>
<p>More generally what is the best way to deal the fact that most enumerative combinatorics I can do in sage gives me sets but for <code>SimplicialComplex</code> I need lists?</p>
https://ask.sagemath.org/question/10581/using-simplicalcomplex-on-a-set-of-sets/?answer=15512#post-id-15512I do not know whether it is the "best" way, but at least a short and readable way to transform a set of sets `S` into a list of lists `L`:
sage: S = Set([Set([1,2]),Set([2,3])]) ; S
{{1, 2}, {2, 3}}
sage: L = [i.list() for i in S] ; L
[[1, 2], [2, 3]]
sage: C = SimplicialComplex(L) ; C
Simplicial complex with vertex set (1, 2, 3) and facets {(1, 2), (2, 3)}
Mon, 30 Sep 2013 00:44:36 -0500https://ask.sagemath.org/question/10581/using-simplicalcomplex-on-a-set-of-sets/?answer=15512#post-id-15512