Ask Your Question

Alexandru Papiu's profile - activity

2017-07-19 21:34:08 -0600 received badge  Popular Question (source)
2014-06-29 11:53:39 -0600 received badge  Famous Question (source)
2014-06-29 11:53:39 -0600 received badge  Notable Question (source)
2014-06-13 07:07:45 -0600 received badge  Popular Question (source)
2014-04-11 01:19:54 -0600 received badge  Student (source)
2013-10-01 18:50:58 -0600 commented answer Using `SimplicalComplex` on a set of sets

Interesting. I am using the online sage notebook at 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.

2013-09-29 15:12:02 -0600 asked a question 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 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?

2013-09-19 08:39:12 -0600 marked best answer Out of memory while enumerating vectors

In your code, by just replacing [] by () and range() by xrange(), you build a generator, that will loop in real time, without storing all values in a list, saving a lot of memory:

sage: A = ((a,b,c,d) for a in xrange(100) for b in xrange (100) for c in xrange (100) for d in xrange (100))

sage: A
<generator object <genexpr> at 0x5d269b0>

sage: for f in A:
....:     print f
(0, 0, 0, 0)
(0, 0, 0, 1)
(0, 0, 0, 2)
(0, 0, 0, 3)
(0, 0, 0, 4)

By the way, if all prescribed values are the same, you can also do:

sage: B = cartesian_product_iterator([xrange(100) for i in range(4)])

sage: for f in B:
....:     print f
(0, 0, 0, 0)
(0, 0, 0, 1)
(0, 0, 0, 2)
(0, 0, 0, 3)
(0, 0, 0, 4)
2013-09-11 07:24:35 -0600 received badge  Scholar (source)
2013-09-11 07:24:35 -0600 marked best answer Fastest way of running sage?


(This was just going to be a comment but it got too long)

  1. Maybe 1 is faster than 2 since that is running natively on the server, the VirtualBox overhead might slow things down.

  2. You can create a worksheet and run the command

    %time a=factorial(1000000)

    Here is what I got. image description

  3. On profiling programs:

    sage: %prun a=factorial(1000000)
             2 function calls in 0.286 seconds        
       Ordered by: internal time        
       ncalls  tottime  percall  cumtime  percall filename:lineno(function)
            1    0.286    0.286    0.286    0.286    0.286 <string>:1(<module>)
            1    0.000    0.000    0.000    0.000 {method 'disable' of  _lsprof.Profiler' objects}

    More details here.

  4. Perhaps the naive answer is that running it on a "faster" computer would do the job. ;-) My experience back around sage-4.x was that compiling it resulted in faster runs, so my recommendation would be to compile sage on a linux machine.

    Just ran the factorial command and got

    sage: %time a=factorial(1000000)
    CPU times: user 0.27 s, sys: 0.01 s, total: 0.28 s
    Wall time: 0.28 s

    I'm running a compiled sage 5.10 on arch linux.

Hope it helps!

Updated to include running time at

2013-09-09 11:42:56 -0600 asked a question Out of memory while enumerating vectors

I am trying to enumerate all vectors of a certain dimension with entries less then some prescribed values and then check some conditions on each of them. This is the code I was thinking about:

A = [(a,b,c,d) for a in range(100) for b in range (100) for c in range (100) for d in range (10)]

for f in A: if Condition(f): print f

The problem is that when the product of my ranges is larger than $10^7$ or so I get a MemoryError.

Is there a more efficient way of enumerating vectors or avoiding the MemoryError?

Thank you.

2013-09-09 11:28:44 -0600 commented answer Fastest way of running sage?

Thanks you, this is really helpful!

2013-09-09 11:28:08 -0600 received badge  Supporter (source)
2013-09-08 11:28:34 -0600 asked a question Fastest way of running sage?


So far I have used 3 different "versions" of sage:

  1. the online sage notebook:

  2. the sage notebook that I downloaded and run on Windows 7 thru VirtualBox on an intel core 2duo

  3. the sage in the cloud found here:

Using "time a = factorial(1000000)" I get cpu and wall times of(.41s, .41s) for 1 and 2,13s; 9.53s) for 2. For 3 "time" apparently does not work but it seems slower than 1.

Questions: Why is 1 significantly faster than 2?

How can I test 3?

Is there a way to test entire programs that gives the time for every step.

What is the fastest way to run sage?