2019-05-22 10:44:04 -0500 received badge ● Notable Question (source) 2016-03-25 16:31:46 -0500 received badge ● Popular Question (source) 2014-11-07 05:11:58 -0500 received badge ● Famous Question (source) 2014-07-16 13:02:53 -0500 received badge ● Nice Question (source) 2014-04-02 18:55:44 -0500 received badge ● Notable Question (source) 2013-11-08 10:11:13 -0500 received badge ● Popular Question (source) 2013-11-06 00:46:53 -0500 commented answer [style] Choose between multiple inheritance I actually want to implement Askey-Wilson polynomials (http://en.wikipedia.org/wiki/Askey%E2%80%93Wilson_polynomials), but I want to give the polynomials some extra functions so that you can do something like: Askey_Wilson(n, z, a, b, c, d, q).three_term() and you get a triple with the three term recurrence relation. So if n is an integer I can use Expression, but if n is a variable I want to use an other object. Your answer does work, except that I don't want to call askey_wilson.I all the time, but just without the I. 2013-11-03 07:22:42 -0500 asked a question [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. 2012-12-01 09:00:20 -0500 received badge ● Editor (source) 2012-12-01 08:59:51 -0500 answered a question Square root in FunctionField I found the answer myself. Instead of using AA you should use the SR (Symbolic Ring). An example: sage: q = var('q') sage: F. = FreeAlgebra(SR, 4) sage: (1+q)**(1/2)*b*a (sqrt(q+1))*b*a  This SR ring is still a bit of a mystery to me, but it seems to work. 2012-11-29 01:39:45 -0500 asked a question Square root in FunctionField Hi, I'm working with $q$-functions and I would like to define a free algebra over the algebraic field with an extra parameter $q$ for which I can also take roots i.e. I would like to do something like this sage: F. = FunctionAlgebra(AA) sage: A. = FreeAlgebra(F, 4) sage: (1+q)**(1/2)*a*b sqrt(1+q)*a*b  The function FunctionAlgebra is not the correct function, since it only includes (integer) powers of $q$. Is it possible to extend this FunctionAlgebra to something where sums of powers of $q$ also have roots? Or is there an other function for which I can do this? Best, Noud 2012-10-26 22:10:02 -0500 marked best answer Check that variable is integer I don't think there's a method that queries the assumptions data. You can write a simple function to test this using the output of assumptions(): sage: a=var('a') sage: assume(a, 'integer') sage: any('a is integer' in str(x) for x in assumptions()) True sage: any('a is real' in str(x) for x in assumptions()) False  The assumptions function returns a list of GenericDeclaration objects which are turned into strings above. sage: type(assumptions()[0])  Beware that the only subsystem of Sage that respects (or takes account of) symbolic assumptions is Maxima. So some symbolic operations will "know" about the assumptions (the ones that use Maxima under the hood) and some won't. 2012-10-26 22:09:59 -0500 commented answer Check that variable is integer I agree with you that it is indeed quite hard and maybe even impossible to do it in a nice way. Let me see if I can bury it in a new method of the symbolic expression type. This will give me some more insight in how Sage works. I'll mark your solution as the solution, since it is obvious a solution. ;) Thank you! 2012-10-25 20:49:23 -0500 commented answer Check that variable is integer Sorry to say this to you, but I think this is an extremely ugly solution. Is there an other solution to give a variable properties like being positive, or having real part, etc. So I might should have asked, is there a way to give variables extra properties, like being real, having real part, being imaginary, etc? 2012-10-24 10:35:45 -0500 asked a question Check that variable is integer Dear Sage, I define the following variable sage: a = var('a') sage: assume(a, 'integer')  How do I check that is variable is an integer? The following doese not seem to work in sage 5.2. sage: a in ZZ False sage: 2 in ZZ True sage: assumptions() [a is integer]  How should I check the assumption that a is an integer? Best, Noud 2012-10-10 01:20:46 -0500 commented answer Weird behavior BuiltinFunction Nice! Thank you for this fix! 2012-10-10 01:20:21 -0500 received badge ● Scholar (source) 2012-10-10 01:20:21 -0500 marked best answer Weird behavior BuiltinFunction Some debug output after the lines pasted in the question: sage: %debug > /home/burcin/sage/ask_qpoch.py(28)_eval_() 27 if len(args) != self.m + 2: ---> 28 raise RuntimeError, args 29 ipdb> print self qPochhammer(3) ipdb> self.name() 'qPochhammer(3)'  Note that the function in use is not qPochhammer(3). ATM, we expect each BuiltinFunction to be instantiated once. In other words, each class corresponds to exactly one symbolic function. This is evident in the check on line 827 of sage/symbolic/function.pyx. Changing this to also check for the name of the function fixes your problem. Patch waiting for review on trac ticket #13586. 2012-10-10 01:20:19 -0500 received badge ● Supporter (source) 2012-10-05 00:22:43 -0500 asked a question Weird behavior BuiltinFunction Dear Sage, I'm trying to program qPochhammer functions which can interact with sage in a nice way. However I encounter some weird behavior of these new BuiltinFunctions. This is what I made: from sage.symbolic.function import BuiltinFunction class qPochhammer(BuiltinFunction): def __init__(self, m=1, expand_exp=False): self.m = m self.expand_exp = expand_exp self.has_arguments = False BuiltinFunction.__init__(self, 'qPochhammer(%i)' % self.m, nargs=(m+2)) def _latex_(self): if self.has_arguments: return '(%s; %s)_{%s}' % (self.a, self.q, self.n) return 'qPochhammer' def _qPochhammer1(self, a, q, n): if n == 0: return 1 return (1 - a*q**(n-1))*self._qPochhammer1(a, q, n-1) def _expand(self): return prod([self._qPochhammer1(elm, self.q, self.n) \ for elm in self.a]) def _eval_(self, *args): if len(args) != self.m + 2: raise RuntimeError, args if self.expand_exp: return self.evaluate(args[:self.m], args[-2], args[-1]) return None def _evalf_(self, *args, **kwds): if type(self.a) == tuple: return self._expand() return self._qPochhammer1(self.a, self.q, self.n) def evaluate(self, a, q, n): self.a = a self.q = q self.n = n self.has_arguments = True if type(self.a) == tuple: return self._expand() return self._qPochhammer1(self.a, self.q, self.n)  Now I try the following the the sage console: sage: a, b, c, q = var('a b c q') sage: qshift3 = qPochhammer(m=3, expand_exp=True) sage: qshift3(a, b, c, q, 2) (c - 1)*(b - 1)*(a - 1)*(c*q - 1)*(b*q - 1)*(a*q - 1) sage: qshift2 = qPochhammer(m=2, expand_exp=True) sage: qshift2(a, b, q, 2) --------------------------------------------------------------------------- RuntimeError Traceback (most recent call last) /home/noud/work/sage/local/lib/python2.7/site-packages/sage/all_cmdline.pyc in () ----> 1 2 3 4 5 /home/noud/work/sage/local/lib/python2.7/site-packages/sage/symbolic/function.so in sage.symbolic.function.Function.__call__ (sage/symbolic/function.cpp:4941)() 430 431 --> 432 433 434 /home/noud/work/sage/local/lib/python2.7/site-packages/sage/all_cmdline.pyc in _eval_(self, *args) 27 28 ---> 29 30 31 RuntimeError: (a, b, q, 2)  Can someone explain to my why I get a RuntimeError and how to solve this? Best regards, Noud 2012-03-22 21:12:08 -0500 commented question Non-commutative ring with inverses Thank you Simon! I'm looking forward to an answer on the sage-combinat-devel mailinglist. 2012-03-22 01:06:24 -0500 commented question Non-commutative ring with inverses I tried to do this, but I do not know how to make the generators of infinite order. I define FreeAlgebra(QQ, 2n, 'x') and define with FreeAlgebraQuotient relations $x_i x_{2n-i} = 1 = x_{2n-i} x_i$. But how do you define that $x_i^k = x_i^k$ (this looks a bit ambiguous)? In the examples in this reference everything has finite order. 2012-03-21 13:32:06 -0500 received badge ● Nice Question (source) 2012-03-21 08:09:01 -0500 received badge ● Student (source) 2012-03-21 02:26:28 -0500 asked a question Non-commutative ring with inverses Hello Sage, I would like to make a ring over $\mathbb{Q}$ with $n$ variables which are non-commutative and also include their inverses. So I want to generate the free algebra over $\mathbb{Q}$ with generates $x_1, x_2, ..., x_n$ and $x_1^{-1}, x_2^{-1}, ..., x_n^{-1}$. How can I do this? Best regards, Noud