Ask Your Question

Revision history [back]

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 = t*output.derivative(variable) - i

    return output

Here's how to use it for your example (I haven't checked whether the output makes sense or not!)

sage: g = op(z*t*exp(t/z),t,5)
sage: g
((((t*(t*e^(t/z)/z^4 + 5*e^(t/z)/z^3) + 4*t*e^(t/z)/z^3 + 16*e^(t/z)/z^2)*t + 3*t*(t*e^(t/z)/z^3 + 4*e^(t/z)/z^2) + 9*t*e^(t/z)/z^2 + 27*e^(t/z)/z)*t + 2*(t*(t*e^(t/z)/z^3 + 4*e^(t/z)/z^2) + 3*t*e^(t/z)/z^2 + 9*e^(t/z)/z)*t + 4*t*(t*e^(t/z)/z^2 + 3*e^(t/z)/z) + 8*t*e^(t/z)/z + 16*e^(t/z))*t + ((t*(t*e^(t/z)/z^3 + 4*e^(t/z)/z^2) + 3*t*e^(t/z)/z^2 + 9*e^(t/z)/z)*t + 2*t*(t*e^(t/z)/z^2 + 3*e^(t/z)/z) + 4*t*e^(t/z)/z + 8*e^(t/z))*t + (t*(t*e^(t/z)/z^2 + 3*e^(t/z)/z) + 2*t*e^(t/z)/z + 4*e^(t/z))*t + t*(t*e^(t/z)/z + 2*e^(t/z)) + t*e^(t/z) + z*e^(t/z))*t - 5

You can simply symbolic expressions like this:

sage: g.simplify_full()
-(5*z^4 - (t^6 + 15*t^5*z + 65*t^4*z^2 + 90*t^3*z^3 + 31*t^2*z^4 + t*z^5)*e^(t/z))/z^4
click to hide/show revision 2
checked and then corrected the algorithm

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 = t*output.derivative(variable) - i
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 (I haven't checked whether the output makes sense or not!)

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

You can simply symbolic expressions like this:

sage: g.simplify_full()
-(5*z^4 - (t^6 + 15*t^5*z + 65*t^4*z^2 + 90*t^3*z^3 + 31*t^2*z^4 + t*z^5)*e^(t/z))/z^4
t^6*e^(t/z)/z^4
click to hide/show revision 3
I have checked the output now :)

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 = t*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 (I haven't checked whether the output makes sense or not!)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 simply symbolic expressions like this:

sage: g.simplify_full()
t^6*e^(t/z)/z^4

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 = t*output.derivative(variable) 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 simply simplify symbolic expressions like this:

sage: g.simplify_full()
t^6*e^(t/z)/z^4