Ask Your Question

Jason Bandlow's profile - activity

2019-08-02 19:55:09 +0100 received badge  Popular Question (source)
2015-09-10 01:33:34 +0100 received badge  Good Answer (source)
2015-09-10 01:33:34 +0100 received badge  Nice Answer (source)
2015-03-02 19:36:21 +0100 received badge  Great Answer (source)
2015-03-02 19:36:21 +0100 received badge  Guru (source)
2014-06-29 03:14:31 +0100 marked best answer Finding the problem in a doctest timeout

After changing a file and running the doctests, I'm getting:

sage -t  "devel/sage-trac/sage/combinat/sf/"
*** *** Error: TIMED OUT! PROCESS KILLED! *** ***

 [360.2 s]
The following tests failed:

sage -t  "devel/sage-trac/sage/combinat/sf/" # Time out
Total time for all tests: 360.3 seconds

Is there an easy way to find out which test it was running when the timeout occurred? Or, equivalently, which tests did pass successfully?

2012-04-11 02:47:52 +0100 received badge  Taxonomist
2012-03-09 02:27:00 +0100 received badge  Famous Question (source)
2011-11-15 11:54:16 +0100 received badge  Good Answer (source)
2011-08-25 10:25:10 +0100 received badge  Nice Answer (source)
2011-08-12 13:24:17 +0100 received badge  Nice Answer (source)
2011-08-11 13:53:12 +0100 answered a question numerical_approx() weirdness?

When you write pi.n(digits=3), you do not get the rational number 314/100. What you get is a floating point number $x$ with a guarantee that $|\pi - x| \le 0.01$ (I believe this number also "knows" how many digits you care about; that's why print shows exactly 3 digits). Because floating point numbers are internally stored in base 2, it is impossible to represent 314/100 exactly.

2011-07-21 21:52:33 +0100 received badge  Notable Question (source)
2011-05-23 10:46:47 +0100 commented question How to magically define variables and use functional notation instead of methods

I'm not sure I understand your question. Are you talking about pre-defining things you might want to use; for example, in your init.sage file? If you're not, I don't know what you mean, since Python will complain about any symbol it doesn't recognize, and I don't believe there is a way to change that. (I could be wrong, though.)

2011-05-20 17:12:26 +0100 received badge  Nice Answer (source)
2011-05-20 10:36:30 +0100 answered a question Solve system of equations with additional conditions in sage

Since $n$ and $k$ are both bounded, you can try something like this:

sage: var('a b c d n k')
sage: nmin = ceil(1080/90); nmax = floor(2000/60)
sage: kmin = ceil(1000/70); kmax = floor(1920/40)
sage: constraints = [a >= 80, b >= 1000, c >= 20, d >= 40, a + b <= 2000, c + d <= 90]
sage: result = []
sage: for nn in [nmin..nmax]:
....:     for kk in [kmin..kmax]:
....:         result.append( solve(constraints +  [n==nn, k==kk, a+b==n*(c+d), b==k*d], (a,b,c,d,n,k)))

I think this will take some time to run, but it should get you all the solutions you want.

2011-05-19 00:13:02 +0100 received badge  Commentator
2011-05-19 00:13:02 +0100 commented question Solve system of equations with additional conditions in sage

For eqn1, there is an obvious upper and lower bound for n, and for each choice of n in this range, you will have 1 equation in four unknowns to determine a,b,c,d (in addition to the constraints). Once you decide on b, you can choose k freely, and this will determine e. What sort of answer are you hoping to get?

2011-05-18 17:23:11 +0100 answered a question How-to: sum

To add to the diversity of answers here, another valid approach is to add a single line to what you already have:


This will return 100. The point is that you can use this syntax to sum the values of a proper function, but not arbitrary Python expressions.

2011-05-11 20:49:54 +0100 answered a question substitute expression instead of formal function symbol

I'm not sure I understand why your example doesn't work, but here is a workaround:

sage: var('a b x')
sage: f = function('foo',x)
sage: g(x) = a*foo(x) + b*foo(x)^2
sage: h = g.diff(x)
sage: bar(x) = a*x + b
sage: h.substitute_function(foo, bar)
2*(a*x + b)*a*b + a^2
2011-04-01 06:31:06 +0100 received badge  Popular Question (source)
2011-02-26 18:02:09 +0100 received badge  Nice Answer (source)
2011-02-26 14:32:28 +0100 answered a question How do I create subsets of sets?

Here is one solution:

sage: [p for p in [0..100] if is_prime(p) and (p%6)==1]
[7, 13, 19, 31, 37, 43, 61, 67, 73, 79, 97]

For more documentation on this, look for list comprehensions in your favorite Python documentation.

2011-01-08 02:01:10 +0100 received badge  Good Answer (source)
2011-01-08 02:01:10 +0100 received badge  Nice Answer (source)
2011-01-08 02:01:10 +0100 received badge  Enlightened (source)
2011-01-04 08:58:33 +0100 received badge  Nice Answer (source)
2011-01-04 08:58:33 +0100 received badge  Good Answer (source)
2010-12-28 20:48:45 +0100 received badge  Nice Answer (source)
2010-12-28 20:48:45 +0100 received badge  Self-Learner (source)
2010-12-24 12:13:09 +0100 received badge  Nice Question (source)
2010-12-24 12:13:09 +0100 received badge  Good Question (source)
2010-12-15 18:12:18 +0100 received badge  Good Answer (source)
2010-12-15 14:51:32 +0100 received badge  Nice Answer (source)
2010-12-15 13:43:38 +0100 commented answer multidictionaries

You're welcome! In fact, lists won't work as keys. Look up 'mutable' vs. 'immutable' in connection with Python to understand why.

2010-12-15 10:16:19 +0100 answered a question multidictionaries

If I correctly understand your question, dictionaries can do this. You just need to use tuples as keys. Example:

sage: m = {} # an empty dictionary
sage: m[('Cathy', 19)] = '555-1212'
sage: m[('Cathy', 19)]
2010-12-14 10:31:30 +0100 received badge  Editor (source)
2010-12-14 10:29:42 +0100 answered a question How to add term order to free module?

To slightly elaborate on John's comment, "CombinatorialFreeModule" allows you to specify an arbitrary comparison function on the elements. Here is a sample doctest from sage.categories.modules_with_basis :

            sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X")
            sage: x = 3*X.monomial(1) + 2*X.monomial(2) + X.monomial(3)
            sage: x.leading_monomial()
            sage: def cmp(x,y): return y-x
            sage: x.leading_monomial(cmp=cmp)
2010-12-12 15:24:09 +0100 answered a question Idempotent help

Here is some code for this:

for n in [2..100]:
    print n,': (',len(n.prime_factors()), sum(a.is_idempotent() for a in Zmod(n)),')'

For a fixed n, len(n.prime_factors()) gives the number of prime factors of n and sum(a.is_idempotent() for a in Zmod(n)) gives the number of idempotents.

2010-12-08 10:43:41 +0100 commented answer A Combinatorics Problem - Product Rule Indices

See also OrderedSetPartitions, which may be helpful.

2010-12-02 21:30:33 +0100 answered a question why won't simplify multiply out square roots?

Probably not what you're looking for, but the best I could do:

sage: sqrt(m^2).simplify_full()
2010-11-12 11:44:37 +0100 answered a question multi-symmetric functions and multi-partitions

I don't think that what you want is available directly in sage, although there may be some tricks available depending on exactly what you want to do. I don't have time to go into more depth right now, but please post this question to the Google Group: sage-combinat-devel. There are a lot of people (including me!) who read that, who would be interested in getting this kind of functionality into sage.

2010-11-09 11:00:33 +0100 commented answer Compiling R with PNG support

This was the key. I did not have libpng installed. I installed it, re-compiled r with sage -f, and everything works. Thanks for your help, everyone!

2010-11-09 09:57:14 +0100 commented answer Compiling R with PNG support

Thanks, I'll try this.

2010-11-09 09:51:50 +0100 answered a question Compiling R with PNG support

(This should maybe be a comment, but I'm posting as an answer for better formatting.) I just discovered the following:

sage: r.eval('capabilities("png")')
'  png \nFALSE '
sage: r.eval('capabilities("X11")')
' X11 \nTRUE '

So apparently, I have X11 support, but not PNG support. Does that suggest anything that I might be able to do?

2010-11-09 09:01:42 +0100 commented answer Compiling R with PNG support

I don't think we've discussed this before (maybe that was Jason Grout?). The file /usr/include/X11/Xwindows.h is present on my system; I'll try at some point to take a look at the spkg-install in more detail and see if I can't figure out what is failing. Thanks for pointing out the Trac ticket!

2010-11-08 20:18:40 +0100 received badge  Student (source)
2010-11-07 18:24:19 +0100 asked a question Compiling R with PNG support

I just compiled sage 4.6 from source on an Ubuntu 10.04 machine. I have the xorg-dev packages installed. However, I still cannot get r to save the plot of a histogram. Specifically, I am getting:

sage: r.png('/tmp/histogram.png') 
RuntimeError: R was not compiled with PNG support

What does work is:

sage: r.X11()
sage: r.hist("rnorm(100)")

But I can't save the resulting graphic. (Of course, I can print-screen and get it that way, but I was hoping there would be a better way.) Can I compile R with PNG support somehow? Or is there another workaround which will give me what I want (namely, saving a picture of a histogram)?