# 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 <module>()
----> 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