Ask Your Question

Mike Hansen's profile - activity

2017-09-17 19:21:54 -0500 received badge  Nice Answer (source)
2016-10-17 13:31:27 -0500 received badge  Good Answer (source)
2016-10-17 13:24:51 -0500 received badge  Nice Answer (source)
2016-08-10 07:03:46 -0500 received badge  Taxonomist
2015-08-04 07:20:17 -0500 received badge  Nice Answer (source)
2015-02-26 07:32:07 -0500 received badge  Nice Answer (source)
2014-12-10 03:52:12 -0500 received badge  Nice Answer (source)
2014-02-07 02:25:25 -0500 received badge  Guru (source)
2014-02-07 02:25:25 -0500 received badge  Great Answer (source)
2013-11-18 06:48:45 -0500 received badge  Nice Answer (source)
2013-10-02 10:17:06 -0500 received badge  Good Answer (source)
2013-10-02 10:17:06 -0500 received badge  Great Answer (source)
2013-10-02 10:17:06 -0500 received badge  Nice Answer (source)
2013-09-30 18:18:41 -0500 received badge  Good Answer (source)
2013-07-27 14:42:20 -0500 received badge  Great Answer (source)
2013-07-03 15:07:46 -0500 received badge  Good Answer (source)
2013-06-27 20:50:26 -0500 received badge  Nice Answer (source)
2013-02-19 05:39:27 -0500 received badge  Nice Answer (source)
2013-02-18 09:15:12 -0500 answered a question Buchberger Algorithm

The best option is to just use I.groebner_basis().

sage: P.<a,b,c,e,f,g,h,i,j,k> = PolynomialRing(GF(32003),10)
sage: I = sage.rings.ideal.Katsura(P,6)
sage: I.groebner_basis()
Polynomial Sequence with 22 Polynomials in 6 Variables
sage: list(_)
[g^6 - 11466*g^5 - 3669*b*g^3 + 4465*c*g^3 - 2315*e*g^3 + 5098*f*g^3 - 8372*g^4 - 15837*f^3 - 9547*b*e*g + 839*b*f*g + 15210*c*f*g - 2141*f^2*g - 13725*b*g^2 - 10720*c*g^2 - 8122*e*g^2 - 2102*f*g^2 - 13908*g^3 + 4663*b*e + 12265*b*f + 6285*c*f + 12921*e*f + 11846*f^2 + 6867*b*g + 9878*c*g - 860*e*g - 1743*f*g - 8368*g^2 + 1892*b + 8121*c - 3112*e + 4349*f + 2284*g, b*g^4 + 12019*g^5 + 6465*b*g^3 - 13833*c*g^3 - 14150*e*g^3 - 1091*f*g^3 - 14524*g^4 - 15914*f^3 - 15812*b*e*g + 15278*b*f*g - 4542*c*f*g - 7300*f^2*g + 9977*b*g^2 - 14014*c*g^2 + 3296*e*g^2 + 5812*f*g^2 - 10065*g^3 - 4292*b*e - 463*b*f - 12423*c*f - 853*e*f - 11889*f^2 + 3839*b*g + 6212*c*g - 7338*e*g + 1142*f*g + 12073*g^2 + 15253*b - 7437*c + 11862*e - 6614*f + 11312*g, c*g^4 - 13467*g^5 + 14690*b*g^3 - 1071*c*g^3 + 7136*e*g^3 + 249*f*g^3 + 5472*g^4 + 11550*f^3 + 3557*b*e*g + 1925*b*f*g + 9868*c*f*g - 130*f^2*g - 3432*b*g^2 - 6768*c*g^2 + 1982*e*g^2 + 12826*f*g^2 - 12180*g^3 + 13808*b*e + 11322*b*f + 2171*c*f + 12372*e*f + 10928*f^2 + 750*b*g + 9052*c*g - 9008*e*g - 2003*f*g - 5879*g^2 - 15186*b + 8220*c - 6034*e - 7337*f + 906*g, e*g^4 - 13178*g^5 - 2372*b*g^3 + 2247*c*g^3 - 14789*e*g^3 + 2351*f*g^3 - 6361*g^4 + 8004*f^3 - 3036*b*e*g + 11459*b*f*g - 15592*c*f*g - 1543*f^2*g - 903*b*g^2 - 9248*c*g^2 - 10163*e*g^2 - 10066*f*g^2 - 6929*g^3 + 8587*b*e + 3419*b*f - 12100*c*f - 6787*e*f - 10573*f^2 - 2036*b*g + 8698*c*g + 7884*e*g - 7506*f*g + 2111*g^2 + 14794*b - 15398*c + 13481*e - 3213*f + 2440*g, f*g^4 - 3764*g^5 - 14119*b*g^3 + 2796*c*g^3 + 11676*e*g^3 - 3057*f*g^3 + 12155*g^4 + 3551*f^3 - 15434*b*e*g - 1738*b*f*g - 8112*c*f*g - 15180*f ...
(more)
2012-11-22 06:17:05 -0500 received badge  Good Answer (source)
2012-11-22 06:17:05 -0500 received badge  Great Answer (source)
2012-11-22 06:17:05 -0500 received badge  Nice Answer (source)
2012-10-25 18:06:09 -0500 received badge  Good Answer (source)
2012-10-23 04:04:30 -0500 received badge  Nice Answer (source)
2012-10-23 04:04:30 -0500 received badge  Good Answer (source)
2012-10-16 04:43:09 -0500 received badge  Good Answer (source)
2012-09-29 05:39:33 -0500 received badge  Good Answer (source)
2012-09-29 05:39:33 -0500 received badge  Great Answer (source)
2012-09-29 05:39:33 -0500 received badge  Nice Answer (source)
2012-09-29 05:39:33 -0500 received badge  Guru (source)
2012-09-08 11:58:54 -0500 received badge  Nice Answer (source)
2012-08-27 22:54:26 -0500 answered a question Can't thread with permutation groups?

The problem is that the GAP interface is not threadsafe -- both threads are accessing the same GAP session. You could use the @parallel decorator and forking (which has a bit of overhead). For example,

def method_1(n):
    import time
    time.sleep(20)
    return 1, Integer(gap(n)*n)

def method_2(n):
    return 2, Integer(gap(n)*n)

def try_fast(n):
    @parallel
    def try_method(method):
        return method(n)

    method_num, result = try_method([method_1, method_2]).next()[1]
    print "Computed by method %s"%method_num
    return result

The result of the (decorated) try_method function is an iterator which will yield the results as soon as they are ready. In this case, we just need the first one.

 sage: %time try_fast(4)
 Killing any remaining workers...
 Computed by method 2
 CPU times: user 0.00 s, sys: 0.02 s, total: 0.02 s
 Wall time: 0.27 s
 16
2012-06-13 20:04:51 -0500 edited answer Symbolic product in Sage?

I found symbolic sum but not symbolic product in the reference files. I need to be able to classify a function of a erratic x which involve several symbolic foodstuffs from 1 to n or whatever. I then want to be able to do a derivative and a limit of this. I am trying out Sage because Mathematical doesn't seem to be able to handle this stuff exactly. I can define the function just fine but when I try to take the limit Mathematical can't seem to handle it.

2012-06-13 20:04:13 -0500 commented answer How to "recover" real number from expression?

Yeah, the name make s more sense when you're familiar with the underlying pynac library. Can you think of a better name that we could use as an alias?

2012-06-13 16:11:32 -0500 answered a question How to "recover" real number from expression?

You can use the pyobject method:

sage: b = RealField(200)(5)
sage: bb = (b^x).operands()[0]
sage: bb.pyobject(), type(bb.pyobject()) 
(5.0000000000000000000000000000000000000000000000000000000000, <type 'sage.rings.real_mpfr.RealNumber'>)
2012-06-13 07:00:06 -0500 received badge  Great Answer (source)
2012-06-13 07:00:06 -0500 received badge  Guru (source)
2012-05-29 00:26:18 -0500 received badge  Good Answer (source)
2012-05-28 09:23:59 -0500 received badge  Nice Answer (source)
2012-05-28 08:14:39 -0500 edited question Spam..........

Spam..........

2012-05-27 16:32:42 -0500 commented answer Polynomial identity

You can put this in ~/.sage/init.sage and it will be loaded each time you start Sage. You can also run "%cpaste" from the command line, paste the code in, and then put in "--" to finish the paste.

2012-05-27 12:03:28 -0500 answered a question small group library

You should be able to run

sage -i database_gap

to install it.

2012-05-27 11:35:53 -0500 answered a question Polynomial identity

Here is some code which "linearizes" your problem:

def polynomial_identity(polys):
    monomials = set()
    for p in polys:
        monomials.update(p.monomials())
        base_ring = p.base_ring()
    monomial_order = list(monomials)
    m = []
    for p in polys:
        row = []
        for monomial in monomial_order:
            try:
                row.append(base_ring(p.coefficient(monomial)))
            except TypeError:
                row.append(base_ring(0))
        m.append(row)
    m = matrix(m)
    return m.kernel()

The result is a vector space which gives you all of your solutions. Your example

sage: polynomial_identity([x^2 + y^2, x*y + x*z, x*y*z])
Vector space of degree 3 and dimension 0 over Rational Field
Basis matrix:
[]

shows that (0,0,0) is the only answer. Another example:

sage: polynomial_identity([x+y, 2*x+2*y, 3*(x+y)])        
Vector space of degree 3 and dimension 2 over Rational Field
Basis matrix:
[   1    0 -1/3]
[   0    1 -2/3]
2012-05-25 18:32:08 -0500 answered a question How to find the path of the maximal distance between two vertices on a complete digraph?

One way to do the general case uses the all_paths method:

sage: [path for path in g.all_paths(0,1) if len(path) == 5]
[[0, 2, 3, 4, 1], [0, 2, 4, 3, 1], [0, 3, 2, 4, 1], [0, 3, 4, 2, 1], [0, 4, 2, 3, 1], [0, 4, 3, 2, 1]]
sage: [path for path in g.all_paths(0,1) if len(path) == 4]
[[0, 2, 3, 1], [0, 2, 4, 1], [0, 3, 2, 1], [0, 3, 4, 1], [0, 4, 2, 1], [0, 4, 3, 1]]
sage: [path for path in g.all_paths(0,1) if len(path) == 3]
[[0, 2, 1], [0, 3, 1], [0, 4, 1]]
sage: [path for path in g.all_paths(0,1) if len(path) == 2]
[[0, 1]]

There is also a longest_path method that takes source and destination as input parameters, but there seems to be a bug with directed graphs. I've made this #13019.

At the theoretical level, the problem is really easy for this specific graph since there are edges between all the vertices. Thus, you can just pick the endpoints and take any permutation of the remaining vertices (or subset of them) to get a path of a fixed length.

2012-05-19 07:08:15 -0500 commented question Error compiling 5.0: scipy-0.9.p1

Can you post some more information from the log about how it failed?

2012-05-18 11:27:22 -0500 answered a question how to use sage's f2py from linux command line?

Try running

$ sage -sh

from the command-line first. When you then run,

$ f2py -m -c rw2 rw2.f90

it will pick up Sage's copy of f2py (which will use Sage's Python).

2012-05-17 18:55:19 -0500 received badge  Good Answer (source)
2012-05-17 18:55:19 -0500 received badge  Nice Answer (source)
2012-05-15 16:37:46 -0500 received badge  Nice Answer (source)