Ask Your Question

mhampton's profile - activity

2020-05-07 18:07:40 +0100 received badge  Famous Question (source)
2019-05-20 08:00:26 +0100 received badge  Popular Question (source)
2018-04-23 13:11:57 +0100 received badge  Popular Question (source)
2018-04-11 01:20:31 +0100 received badge  Notable Question (source)
2015-12-01 15:34:19 +0100 received badge  Notable Question (source)
2015-09-30 02:38:16 +0100 received badge  Popular Question (source)
2015-09-30 02:38:16 +0100 received badge  Notable Question (source)
2015-02-16 14:32:17 +0100 received badge  Popular Question (source)
2015-01-28 04:36:34 +0100 received badge  Great Answer (source)
2014-06-24 08:33:53 +0100 received badge  Great Answer (source)
2013-04-23 06:57:40 +0100 received badge  Nice Answer (source)
2012-10-23 17:49:15 +0100 received badge  Popular Question (source)
2012-10-19 00:48:59 +0100 commented answer add users to notebook from sage commandline

I tried that from scratch (starting over and inserting the "nbu.set_accounts(True)", and it still doesn't work.

2012-10-19 00:36:22 +0100 commented answer add users to notebook from sage commandline

I thought I tried that, and it didn't work. But I will try again, perhaps things get messed up if it is not done initially.

2012-10-17 13:22:02 +0100 asked a question add users to notebook from sage commandline

I know I've done this before, but it was a few years ago and I can't remember exactly how I did it. Its possible that the notebook has changed in some relevant ways in the meantime.

I'd like to add a bunch of users to a notebook from the commandline. I tried something like this:

users = [['Alice','123'], ['Bob','123'], ['Carol','789']]
nb = sagenb.notebook.notebook.load_notebook('/path/to/my.sagenb/')
nbu = nb.user_manager()
for u in users:
    nbu.add_user(u[0],u[1],'',account_type='user',force=True)
nb.save()

But the users do not show up when I start the notebook.

2012-07-30 08:11:43 +0100 received badge  Good Answer (source)
2012-07-30 08:11:43 +0100 received badge  Nice Answer (source)
2012-05-09 16:49:00 +0100 received badge  Good Answer (source)
2012-03-01 09:08:57 +0100 received badge  Nice Question (source)
2012-02-24 19:24:51 +0100 received badge  Nice Answer (source)
2012-02-24 00:13:20 +0100 answered a question ode_solver : unable to convert to float

You could just write a Runge-Kutta 4th-order solver in python, and if your system isn't too nasty that will speedily and happily use complex values.

2012-02-24 00:09:49 +0100 answered a question Extract solutions from solve

Sometimes - especially in more complicated multivariate cases - using the option solution_dict = True is convenient. It doesn't really help here, but for your example:

x = var('x')
f = x^2 - 5*x + 6
z = solve(f, x, solution_dict=True)
for solution in z:
    print x.subs(solution)

3
2
2011-10-30 17:09:21 +0100 received badge  Taxonomist
2011-06-22 05:00:09 +0100 received badge  Nice Answer (source)
2011-06-22 05:00:09 +0100 received badge  Good Answer (source)
2011-06-02 06:15:34 +0100 received badge  Nice Answer (source)
2011-04-07 16:14:11 +0100 answered a question Complex forms and differentials

To the best of my knowledge those operators are not currently implemented in Sage. The differential forms class is pretty new, and lacks a number of features currently. I know the developers of it had some future plans but I don't know if they included support for complex operators.

2011-03-25 00:07:53 +0100 received badge  Nice Answer (source)
2011-03-21 22:18:09 +0100 answered a question Mac OS vs Ubuntu for high performance computing

Is this a laptop you are talking about? If so, go with the Mac. But if you will mostly be using the machine remotely then it probably gives more bang for the buck to put linux on generic hardware.

To get a better answer I think you'd have to describe what sort of tasks cause bottlenecks in your workflow.

2011-03-14 00:15:47 +0100 commented answer convert mpmath function to cython

Thanks, that's very helpful.

2011-03-05 10:56:24 +0100 commented answer convert mpmath function to cython

Thanks. Yes, using a recurrence would be much better, but I'm trying to get away with not thinking too much. If I had more time for this project it would be cool to implement Fisher's exact test for the general case (larger contingency tables, not just 2 by 2) but that is much harder.

2011-03-05 10:55:07 +0100 commented answer convert mpmath function to cython

Its Fisher's exact test. I was using the R implementation, but the smallest value it will give is 10^(-16), and I'd like more precision.

2011-03-04 15:39:58 +0100 asked a question convert mpmath function to cython

I think I could figure this out eventually, but I'm hoping it will be a very easy question for someone out there. I would like to convert the following function to cython to be as fast as possible. I am not sure exactly what I need to import from mpmath to do that.

Here is the function:

from mpmath import *
mp.dps = 25; mp.pretty = True
def hyp_mp(a1,a2,b1,b2):
    num = gamma(a1+a2+1)*gamma(b1+b2+1)*gamma(a1+b1+1)*gamma(a2+b2+1)
    denom = gamma(a1+1)*gamma(a2+1)*gamma(b1+1)*gamma(b2+1)*gamma(a1+a2+b1+b2+1)
    return num/denom

def myfisher_mp(a1,a2,b1,b2):
    p = hyp_mp(a1,a2,b1,b2)
    outp = p
    for i in range(0,a1):
        temp = hyp_mp(i,a2+a1-i,b1-i+a1,b2-a1+i)
        if temp > p:
            break
        else:
            outp += temp
    for i in range(0,a2):
        temp = hyp_mp(a1+a2-i,i,b1-a2+i,b2+a2-i)
        if temp > p:
            break
        else:
            outp += temp
    return outp

A good test case would be myfisher_mp(1286, 9548, 133437, 148905), which takes about 1 second on my desktop. The inputs a1,a2,b1,b2 can be assumed to be positive ints.

2011-02-03 06:46:03 +0100 received badge  Great Answer (source)
2011-02-03 06:46:03 +0100 received badge  Nice Answer (source)
2011-02-03 06:46:03 +0100 received badge  Good Answer (source)
2011-02-03 06:46:03 +0100 received badge  Guru (source)
2011-02-03 06:46:03 +0100 received badge  Enlightened (source)
2011-01-14 01:41:07 +0100 commented answer Quotient decomposition by Groebner basis

Thanks, somehow I had missed the "lift" command. That is exactly what I needed.

2011-01-10 17:31:08 +0100 answered a question How many memories uses Sage?

get_memory_usage() is probably what you want.

2011-01-08 21:54:12 +0100 asked a question Quotient decomposition by Groebner basis

I can accomplish the following task in awkward ways using syzygy modules, but I am wondering if there is a better way somehow. It would be nice to have a single command for it.

Suppose we have a polynomial $P$ and a set of polynomials $Q_1,...,Q_n$, and it is possible to calculate the Groebner basis $G$ of the ideal generated by all the $Q_i$. Let $R$ be the remainder of $P$ after reducing by $G$. In Sage, how can we find polynomials $S_1,...,S_n$ such that $P = R + \sum S_i Q_i$?

2011-01-08 21:53:13 +0100 asked a question Quotient decomposition by Groebner basis

I can accomplish the following task in awkward ways using syzygy modules, but I am wondering if there is a better way somehow. It would be nice to have a single command for it.

Suppose we have a polynomial $P$ and a set of polynomials $Q_1,...,Q_n$, and it is possible to calculate the Groebner basis $G$ of the ideal generated by all the $Q_i$. Let $R$ be the remainder of $P$ after reducing by $G$. In Sage, how can we find polynomials $S_1,...,S_n$ such that $P = R + \sum S_i Q_i$?

2010-10-25 15:30:59 +0100 answered a question Speedup commonly used Sage functions?

OK, that makes more sense. But for some purposes, xmrange is faster. Suppose you actually want the output of xmrange as a list. Then if you look at:

def test1(nx):
    return xmrange([nx]*3)

def test2(nx):
    answer = []
    for k1 in xrange(nx):
        for k2 in xrange(nx):
            for k3 in xrange(nx): answer.append([k1,k2,k3])
    return answer

the xmrange solution wins:

timeit('test1(10)')
    625 loops, best of 3: 28.5 µs per loop

timeit('test2(10)')
    625 loops, best of 3: 403 µs per loop

although I'm sure there are more efficient ways to use xrange for this.

2010-10-24 20:41:43 +0100 answered a question Speedup commonly used Sage functions?

Those two functions don't really do the same thing. They both return [0,0,0], so if that's all you want you could do:

def test3():
    return [0,0,0]

The function test1 is probably slower because it has to actually construct an object to iterate over those values, while test2 does not. It might be more fair to compare functions that return all the values.

2010-10-23 01:12:06 +0100 answered a question How to output from sage

It really depends what your output is, but for some things you could do:

sage: f = file('/desired/path/output.txt','w')
sage: f.write(str(my_amazing_output))
sage: f.close()

Maybe I don't understand the question though.

2010-10-14 23:11:24 +0100 received badge  Self-Learner (source)
2010-10-14 23:11:24 +0100 received badge  Self-Learner (source)
2010-10-14 23:11:12 +0100 received badge  Teacher (source)