Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

[style] Chooce between multiple inheritance

Dear Sage people,

I want to create a new (mathematical) object that sometimes is an Expression and sometimes a SymbolicFunction, depending on the arguments. You can think of this for example like $f(a, b, t) = \int_0^t a^b e^{-x^2} dx$. For special values of $t$ I would like to see it as an Expression ($t=0$ or $t=\infty$), but in all other cases I want it to be a BuiltinFunction (or something alike).

In Sage I can do something like:

class MyObjectExpression(Expression):
    def __init__(self, a, b, t):
        Expression.__init__(self, integral(a**b*e**(-x**2), x, 0, t))
    # More (override) stuff below

class MyObjectFunction(BuiltinFunction):
    def __init__(self, a, b, t):
        BuiltinFunction.__init__(self, 'f(a,b,t)', nargs=1)
    # More (override) stuff below

def MyObject(a, b, t):
    if t == 0 or t == infty:
        return MyObjectExpression(a, b, t)
    else:
        return MyObjectFunction(a, b, t)

Is it possible to combine these three things into one class? So I want to create a class which is sometimes an Expression and sometimes an much more abstract class, is this possible?

Best, Noud

[style] Chooce Choose between multiple inheritance

Dear Sage people,

I want to create a new (mathematical) object that sometimes is an Expression and sometimes a SymbolicFunction, depending on the arguments. You can think of this for example like $f(a, b, t) = \int_0^t a^b e^{-x^2} dx$. For special values of $t$ I would like to see it as an Expression ($t=0$ or $t=\infty$), but in all other cases I want it to be a BuiltinFunction (or something alike).

In Sage I can do something like:

class MyObjectExpression(Expression):
    def __init__(self, a, b, t):
        Expression.__init__(self, integral(a**b*e**(-x**2), x, 0, t))
    # More (override) stuff below

class MyObjectFunction(BuiltinFunction):
    def __init__(self, a, b, t):
        BuiltinFunction.__init__(self, 'f(a,b,t)', nargs=1)
    # More (override) stuff below

def MyObject(a, b, t):
    if t == 0 or t == infty:
        return MyObjectExpression(a, b, t)
    else:
        return MyObjectFunction(a, b, t)

Is it possible to combine these three things into one class? So I want to create a class which is sometimes an Expression and sometimes an much more abstract class, is this possible?

Best, Noud

[style] Choose between multiple inheritance

Dear Sage people,

I want to create a new (mathematical) object that sometimes is an Expression and sometimes a SymbolicFunction, depending on the arguments. You can think of this for example like $f(a, b, t) = \int_0^t a^b e^{-x^2} dx$. For special values of $t$ I would like to see it as an Expression ($t=0$ or $t=\infty$), but in all other cases I want it to be a BuiltinFunction (or something alike).

In Sage I can do something like:

class MyObjectExpression(Expression):
    def __init__(self, a, b, t):
        Expression.__init__(self, integral(a**b*e**(-x**2), x, 0, t))
    # More (override) stuff below

class MyObjectFunction(BuiltinFunction):
    def __init__(self, a, b, t):
        BuiltinFunction.__init__(self, 'f(a,b,t)', nargs=1)
    # More (override) stuff below

def MyObject(a, b, t):
    if t == 0 or t == infty:
        return MyObjectExpression(a, b, t)
    else:
        return MyObjectFunction(a, b, t)

Is it possible to combine these three things into one class? So I want to create a class which is sometimes an Expression and sometimes an much more abstract class, is this possible?

Best, Noud

Edit: What I actually want to do is programming Askey-Wilson polynomials and give them extra options, like a three term recurrence relation. But this depends on $n$. I already programmed this.

class Askey_Wilson(SageObject):
    def __init__(self, SR, n, z, a, b, c, d, q):
        self.n = n
        self.z = z
        self.q = q
        self.a = a
        self.b = b
        self.c = c
        self.d = d
        self.param = [a, b, c, d]

        if self.n in ZZ:
            self.I = self.evaluate()
        else:
            self.I = var('askey_wilson')

    def __repr__(self):
        return 'p_%i(%s;%s,%s,%s,%s|%s)' % (
            self.n, self.z, self.a, self.b, self.c, self.d, self.q
        )

    def evaluate(self):
        n, q, z, a, b, c, d = [self.n, self.q, self.z] + self.param

        lc = qPochhammerSymbol(SR, [a*b, a*c, a*d], q, n) / a**n
        poly = BasicHypergeometricSeries(SR,
            [q**(-n), a*b*c*d*q**(n-1), a*z, a*z**(-1)],
            [a*b, a*c, a*d], q, q)
        return lc*poly

    def three_term_recurrence(self):
        A, B, C = 0, 0, 0
        # compute three term recurrence relation
        return A, B, C

But now every time I want to know the explicit value of the Askey-Wilson polynomials I have to call askey_wilson.I. I want to get rid of the I.