Ask Your Question

Saul Schleimer's profile - activity

2018-05-02 08:32:02 -0500 received badge  Nice Answer (source)
2017-08-31 11:39:40 -0500 received badge  Teacher (source)
2016-08-09 14:27:30 -0500 received badge  Nice Question (source)
2016-08-06 15:51:29 -0500 received badge  Student (source)
2016-08-05 14:03:59 -0500 commented answer How can I override the __call__ method of a matrix

Ok, after thinking about it, I realise that this isn't quite what I want. The whole point of using Matrix is I don't have to commit to (or even think about) the base field or ring - the initialisation procedure for Matrix takes care of that for me.

2016-08-05 13:17:59 -0500 answered a question Forming a polytope from only its combinatorial data

If by "visualize" you mean "give a geometric realization of" then I think that the answer should be "no" as I rather suspect that there are high-dimensional combinatorial polytopes that have no geometric realization. Even for three-dimensional polytopes the realization problem is delicate - there are even several layout algorithms for planar graphs. (There is at least one such implemented in sage - see:

http --- fix --- doc.sagemath.org/html/en/reference/plotting/sage/graphs/graph_plot.html

). On the other hand, if you want to see the face poset in a graphical way, this is much easier. For example see this post:

https --- fix --- sheaves.github.io/Subgroup-Lattice/

and pay attention to the "plot" method of a Poset.

2016-08-05 12:52:51 -0500 commented answer canonicalize_radical for matrices.

In the end, I went with

M = Matrix([v.canonicalize_radical() for v in M])

because it feels a bit more "pythonic". I suppose what I really want is to be told how to make a feature request. I'll add that to the original question.

2016-08-05 12:48:34 -0500 received badge  Commentator
2016-08-05 12:48:34 -0500 commented question How can I override the __call__ method of a matrix

Ok, I understand that Matrix is a metaclass, not a class. But I really want the functionality of Matrix, not some special case. In my particular usecase I don't know how the matrix will be given. I just know that the __init__ that comes with Matrix can handle the input. For example - what if the input has entries in some number field? Those are not integers...

2016-08-03 16:28:09 -0500 received badge  Editor (source)
2016-08-03 16:25:40 -0500 commented answer How can I override the __call__ method of a matrix

Ok, I see that perhaps I can't use the same __init__ method, as I want a MyMatrix, not a Matrix. But we haven't gotten there yet - my toy example throws an error on the first line, not when I try to use it. I'll add the error message to the post.

Regarding the call that is already implemented - it is exactly that method which I wish to override.

2016-08-03 16:21:31 -0500 commented answer How can I override the __call__ method of a matrix

Neat - thanks for this.

2016-08-02 15:14:55 -0500 commented answer canonicalize_radical for matrices.

Yes, I know that I can write some code to do want I want (and I have done so!). However, as my question states, I am asking for a feature to be implemented - namely the simplify methods should work the same for "scalars", "vectors", and "matrices". In any case, thank you for the reply.

2016-08-02 13:46:22 -0500 asked a question canonicalize_radical for matrices.

The following all works

sage: a = sqrt(2)*sqrt(3)*sqrt(6)
sage: v = vector([a])
sage: M = Matrix([v, v])
sage: a.canonicalize_radical()
6
sage: v.canonicalize_radical()
(6)

However the following doesn't work:

sage: M = Matrix([v, v])
sage: M.canonicalize_radical()

EDIT: Could somebody please tell me the right place to ask for "vectorization of canonicalize_radical for matrices" as a new feature of sage?

2016-08-02 13:35:48 -0500 commented answer How can I override the __call__ method of a matrix

Yes, I see that. But there should be a way to define a new class (or new metaclass) that inherits from matrix and does what I want?

2016-08-02 13:33:36 -0500 commented question How to make matrices act like linear operators (ie like functions)?

Thanks - the webpage was being slow...

2016-08-02 13:06:29 -0500 asked a question How to make matrices act like linear operators (ie like functions)?

I'd like to override the __call__ method of a matrix so that M(v) returns M*v. That is, I'd like to use functional notation (to maintain compatibility with a pre-existing body of code). So I tried the following:

class MyMatrix(Matrix):
    def __call__(self, v):
        return self*v

but this doesn't work because Matrix is a MatrixFactory (?) ie it is a metaclass, not a class. I don't know anything about metaclasses, so, after banging my head against various walls, I am asking here.

2016-08-02 13:06:29 -0500 asked a question How can I override the __call__ method of a matrix

I'd like to override the __call__ method of a matrix so that M(v) returns M*v. That is, I'd like to use functional notation. So I tried the following:

class MyMatrix(Matrix):
    def __call__(self, v):
        return self*v

but this doesn't work. Here is the error message I get when I try the above code in sage:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-88-e8d789594dd8> in <module>()
----> 1 class MyMatrix(Matrix):
      2             def __call__(self, v):
      3                     return self*v
      4 

TypeError: Error when calling the metaclass bases
    object() takes no parameters

I don't know anything about metaclasses. After banging my head against various walls, trying to learn, I am asking here.

2015-09-08 20:26:07 -0500 commented answer How to use linear algebra inside of MixedIntegerLinearPrograms?

Thanks for finding a partial solution, and for the reference to linear_program. I'll take a look.

2015-09-08 20:23:25 -0500 received badge  Scholar (source)
2015-09-06 21:41:48 -0500 asked a question How to use linear algebra inside of MixedIntegerLinearPrograms?

I have a largish matrix M that defines a polytope P, via a bunch of constraints of the form u.v > b. Here u is the vector of variables and v ranges over the columns of the matrix M. I want to optimize a simple linear functional over P. I can use a MixedIntegerLinearProgram to solve this problem. But I have to roll my own dot_prod function, because sage will not let me treat u as a vector. Is there something I've missed?

Here is the code -

def dot_prod(u, v):
    dim = len(v)
    return sum(u[i]*v[i] for i in range(dim))

def farkas(M):
    '''Look for edge vector u so that all entries of u*M are positive.  If
    one exists, return True.'''
    N = Matrix(M)
    q = MixedIntegerLinearProgram( maximization=False, solver='GLPK'  )
    u = q.new_variable( real=True, nonnegative=False )
    for v in N.columns():
        q.add_constraint( dot_prod(u, v), min = 1 ) # unpleasant
    q.set_objective( sum( dot_prod(u, v) for v in N.columns() ) ) # likewise
    try:
        q.solve()
        return True
    except MIPSolverException:
        return False
2015-09-06 21:23:14 -0500 commented answer Why do I get the "unable to find a common ring for all elements" error message?

Basically, you are reimplementing the dot product. That seems like a "bad thing". Obviously linear algebra and linear programming should play well together - can this actually be done?

2013-12-18 05:35:36 -0500 answered a question Does Sage "Show Its Work"?

I think that http://ask.sagemath.org/question/474/... has the answer to your question, which unfortunately is "no". You should consider asking the sage developers this question.

Note that there are various sites on-line that offer homework help. The first that springs to mind is http://math.stackexchange.com/ which states "Mathematics Stack Exchange is a question and answer site for people studying math at any level".

2013-12-17 10:56:53 -0500 commented answer Does Sage "Show Its Work"?

For example, Wolfram Alpha can do something like this - see http://blog.wolframalpha.com/2012/09/26/introducing-expanded-step-by-step-math-solutions/ I'll note that the one time I tried to use this feature, WA fell over. :)

2013-12-17 10:53:58 -0500 commented answer Does Sage "Show Its Work"?

I think the questioner is asking "Can I see the steps whereby sage arrived at this answer?" This is not very well-defined, but in some cases, "showing steps" would be a useful feature.