Ask Your Question

shacsmuggler's profile - activity

2022-06-08 18:28:46 +0200 received badge  Notable Question (source)
2022-05-19 16:55:58 +0200 received badge  Notable Question (source)
2022-02-18 22:09:33 +0200 received badge  Famous Question (source)
2019-10-10 13:12:51 +0200 received badge  Popular Question (source)
2018-04-09 15:30:16 +0200 received badge  Popular Question (source)
2018-01-11 12:42:53 +0200 received badge  Notable Question (source)
2018-01-11 12:42:53 +0200 received badge  Popular Question (source)
2017-05-11 19:32:54 +0200 received badge  Famous Question (source)
2016-07-27 21:51:17 +0200 received badge  Good Question (source)
2016-06-17 09:23:27 +0200 received badge  Notable Question (source)
2016-05-18 15:15:33 +0200 received badge  Notable Question (source)
2015-11-26 23:13:15 +0200 received badge  Famous Question (source)
2015-09-15 15:32:29 +0200 received badge  Popular Question (source)
2015-03-27 04:07:00 +0200 marked best answer Suppressing warning messages

When I do the following sage code, I get a warning message::

sage: R.<x,y,z> = QQbar[]
sage: poly = x^3 + y^3 + z^3
sage: mr = poly.parent().quo(poly.jacobian_ideal()); mr
Quotient of Multivariate Polynomial Ring in x, y, z over Algebraic Field by the ideal (3*x^2, 3*y^2, 3*z^2)
sage: project = mr.cover()
verbose 0 (2416: multi_polynomial_ideal.py, groebner_basis) Warning: falling back to very slow toy implementation.

This piece of code is repeated several times in a larger project, and all the warning messages are messing up the output. Is there a way to turn them off? (Yes, I do need to use QQbar, even though this example didn't use it.)

Thanks!

2015-02-16 15:04:25 +0200 received badge  Nice Question (source)
2014-06-29 11:34:32 +0200 received badge  Notable Question (source)
2014-06-29 11:34:32 +0200 received badge  Popular Question (source)
2014-06-29 11:34:32 +0200 received badge  Famous Question (source)
2014-06-18 16:12:38 +0200 commented answer algebra of differential operators

Thanks! This is a great solution.

2014-06-18 16:11:28 +0200 marked best answer algebra of differential operators

Here is an implementation combining the other two ideas here:

var('t,z')

def op(func,variable,n_max):
    """
    Input a function, a variable, and a number
    Returns operator applied to function
    """
    output = func
    for i in range(1,n_max+1):
        output = variable*output.derivative(variable) - i*output

    return output

If you just want to see the operator, you can apply op to a symbolic function:

sage: symb_f = function('f',t)

sage: op(symb_f,t,2)  # the first two operators composed
t^2*D[0, 0](f)(t) - 2*t*D[0](f)(t) + 2*f(t)

sage: op(symb_f,t,3)  # the first three operators composed
t^3*D[0, 0, 0](f)(t) - 3*t^2*D[0, 0](f)(t) + 6*t*D[0](f)(t) - 6*f(t)

Here's how to use it for your example:

sage: g = op(z*t*exp(t/z),t,5)
sage: g
t^5*(t*e^(t/z)/z^4 + 5*e^(t/z)/z^3) - 5*t^4*(t*e^(t/z)/z^3 + 4*e^(t/z)/z^2) + 20*t^3*(t*e^(t/z)/z^2 + 3*e^(t/z)/z) - 60*t^2*(t*e^(t/z)/z + 2*e^(t/z)) - 120*t*z*e^(t/z) + 120*(t*e^(t/z) + z*e^(t/z))*t

You can simplify symbolic expressions like this:

sage: g.simplify_full()
t^6*e^(t/z)/z^4
2014-06-18 09:14:02 +0200 received badge  Good Question (source)
2014-06-16 22:41:40 +0200 received badge  Nice Question (source)
2014-06-12 21:23:22 +0200 commented answer algebra of differential operators

This is not what I meant. I've added a clarification in my post. Is the clarification clearer?

2014-06-12 18:22:02 +0200 asked a question algebra of differential operators

I'm trying to use Sage to check if an explicit function satisfies a PDE. As an example, I would like to be able to apply the operator $\prod_{n=1}^5(t \frac{\partial}{\partial t} - n)$ to $zt e^{t/z}$. What are my options for doing this in Sage?

I found a relevant post on this site, which almost does what I want, but not quite. In the context of that post, I'd like to be able to do something like this:

def Dt(f):
    return t*f.derivative(t)

operator = prod([ Dt - n-1 for n in range(5) ])
operator(z*t*exp(t/z))

But of course, this doesn't work. Thanks!

To be clear, I'm asking about the following operator: $$\prod_{n=1}^5(t \frac{\partial}{\partial t} - n) = (t\frac{\partial}{\partial t} - 1)(t\frac{\partial}{\partial t}-2)(t\frac{\partial}{\partial t}-3)$$ $$=\bigg(t\frac{\partial}{\partial t}-1\bigg)\bigg(\big(t\frac{\partial}{\partial t} + t^2 \frac{\partial^2}{\partial t^2}\big) - 5t\frac{\partial}{\partial t} + 6\bigg)$$ $$= \ldots $$ I don't want to finish the expansion by hand. I want Sage to do it for me, and then apply the whole mess to the function $zt e^{t/z}$.

2014-02-11 23:51:09 +0200 received badge  Popular Question (source)
2014-01-01 19:14:20 +0200 received badge  Popular Question (source)
2013-11-30 13:18:01 +0200 received badge  Notable Question (source)
2013-03-18 16:18:57 +0200 received badge  Popular Question (source)
2013-02-26 19:16:31 +0200 asked a question Sage notebook tab completion for attached files

My research group recently published a worksheet on the alpha.sagenb.org website ("LGModels worksheet", if you want to look) as a way to make our code available to other people working on LG mirror symmetry. We uploaded our code using the "data" option on the worksheet.

My issue is, the tab completion doesn't work for objects defined in the uploaded files. Does anyone know why this is or if there is a way to fix it?

Additional question: does anyone know the future of the alpha.sagenb website?

Thanks!

2012-11-20 15:49:15 +0200 answered a question matrix entry-wise comparison (masking)

This is a follow-up to DSM's answer. Just for future reference, I found that I can turn the Trues and Falses into 1's and 0's in the following way:

sage: M = Matrix([[1,2,3],[0,4,5],[0,0,6]])
sage: 1 * ( M.numpy() == 0 )
array([[0, 0, 0],
       [1, 0, 0],
       [1, 1, 0]])
2012-11-20 15:44:54 +0200 marked best answer matrix entry-wise comparison (masking)

That's how numpy matrices work, so one possibility is to write:

sage: M = Matrix([[1,2,3],[0,4,5],[0,0,6]])
sage: M.numpy()                            
array([[1, 2, 3],
       [0, 4, 5],
       [0, 0, 6]])
sage: M.numpy() == 0
array([[False, False, False],
       [ True, False, False],
       [ True,  True, False]], dtype=bool)
sage: M.numpy() == zero_matrix(ZZ, 3)
array([[False, False, False],
       [ True, False, False],
       [ True,  True, False]], dtype=bool)
2012-11-20 13:43:49 +0200 asked a question matrix entry-wise comparison (masking)

Hello,

I've heard that in some programming languages it is possible to "mask" your matrix. That is, I should be able to do something like

sage: M = Matrix([[1,2,3],[0,4,5],[0,0,6]])
sage: Z = zero_matrix(ZZ, 3)
sage: ( M == Z )
[False False False]
[True  False False]
[True  True  False]

Or perhaps the matrix outputted would have 0's and 1's (that would be more convenient). Is there a way to do this in Sage, perhaps using some object other than a matrix?

Thanks!

2012-08-30 21:30:49 +0200 answered a question inheriting from CombinatorialFreeModule

So, I asked my question just a few minutes too soon. I had two problems: I needed to define the TestRingElement before TestRing, and I needed to specify the Element attribute of TestRing. After the right things are imported, the following code runs as expected:

class TestRingElement(CombinatorialFreeModuleElement):

    def __init__(self, M, x):
        super(TestRingElement, self).__init__(M, x)
        self.data = x

class TestRing(CombinatorialFreeModule):

    Element = TestRingElement

    def __init__(self, R, G):
        super(TestRing, self).__init__(R, G)

I am still curious, though, if anyone can answer my other question about passing in lists to the constructor.

2012-08-30 21:14:32 +0200 received badge  Editor (source)
2012-08-30 21:14:32 +0200 edited question inheriting from CombinatorialFreeModule

I am trying to write a class that inherits from CombinatorialFreeModule. My problem is correctly inheriting from the element class. I have the following code:

from sage.sets.family import Family
from sage.categories.all import GradedAlgebrasWithBasis
from sage.combinat.free_module import CombinatorialFreeModule, CombinatorialFreeModuleElement
from sage.categories.all import tensor

class TestRing(CombinatorialFreeModule):

    def __init__(self, R, G):
        super(TestRing, self).__init__(R, G)

class TestRingElement(CombinatorialFreeModuleElement):

    def __init__(self, M, x):
        super(TestRingElement, self).__init__(M, x)
        self.data = x

I can create a TestRing object and get its basis elements as follows:

sage: R = TestRing(QQ, ('a','b'))
sage: a,b = R.basis()

My problem is that a and b have no data attribute. They are not instances of the TestRingElement class:

sage: a.d
a.db     a.dump   a.dumps  
sage: isinstance( a, TestRingElement )
False

I want to be able to add more attributes to the elements of my module. Can someone tell me the correct way to do this?

Incidentally, this code breaks when I call TestRing with a list as its second argument, instead of a tuple. Though, if I create a list inside the constructor (based on input to the constructor) and use that when I call the parent constructor, everything runs fine. Can anyone tell me why the code breaks in the first instance? Or, why does it work in the second instance?

Thanks!