Ask Your Question

Revision history [back]

If you want to make a symbolic sum then all the terms should be symbolic. Your example does not work because qbin(n,k) is not defined for symbolic n.

What you can do is to make qbin a callable symbolic expression with custom typesetting:

var('q')
def qbin_latex(self, n, k):
    return '{' + str(n) + ' \choose ' + str(k) + '}_{' + str(q) + '}'
qbin = function('qbin', nargs=2, print_latex_func=qbin_latex)
var('k,n')
show(sum(qbin(n,k),k,0,n))

$$\sum_{k=0}^{n} {n \choose k}_{q}$$

To check the identities that you are interested in, you will probably have to do some substitutions by hand, and/or pass an evalf_func parameter to function in the definition of qbin. Have a look at the documentation for symbolic functions.

If you want to make a symbolic sum then all the terms should be symbolic. Your example does not work because qbin(n,k) is not defined for symbolic n.

What you can do is to make qbin a callable symbolic expression function with custom typesetting:

var('q')
def qbin_latex(self, n, k):
    return '{' + str(n) + ' \choose ' + str(k) + '}_{' + str(q) + '}'
qbin = function('qbin', nargs=2, print_latex_func=qbin_latex)
var('k,n')
show(sum(qbin(n,k),k,0,n))

$$\sum_{k=0}^{n} {n \choose k}_{q}$$

To check the identities that you are interested in, you will probably have to do some substitutions by hand, and/or pass an evalf_func parameter to function in the definition of qbin. Have a look at the documentation for symbolic functions. .