Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to do mul(function, i=1..n); like in Maple?

I want to a product of polynomials which I define in Maple as

f := n->mul((1+x^k),k=1..n);

The obvious choice, mimicking Sage's 'sum' command does not work. I can't do

def f(n):
    return mul((1+x^k),k,1,n)

Instead I had to use

def S(n,k):
    return mul(1+x^(k+1) for k in range(n))

Maybe my problem is another, so I'll post my whole problem and traceback:

 def S(n,k):
    s = mul(1+x^(i+1) for i in range(n))
    return s.expand().coeff(x^k)
def H(n,k):
    return sum(sum( S(2*i+1,b)*S(n-2*i-3,k-(2*i+2)-b),b,0,k-(2*i+2)),i,0,floor((n-5)/4))
H(121,4)

Traceback (most recent call last):        return sum(sum( S(2*i+1,b)*S(n-2*i-3,k-(2*i+2)-b),b,0,k-(2*i+2)),i,0,floor((n-5)/4))
  File "", line 1, in <module>

  File "/tmp/tmpKvQFbK/___code___.py", line 10, in <module>
    exec compile(u'H(_sage_const_121 ,_sage_const_4 )
  File "", line 1, in <module>

  File "/tmp/tmpKvQFbK/___code___.py", line 9, in H
    return sum(sum( S(_sage_const_2 *i+_sage_const_1 ,b)*S(n-_sage_const_2 *i-_sage_const_3 ,k-(_sage_const_2 *i+_sage_const_2 )-b),b,_sage_const_0 ,k-(_sage_const_2 *i+_sage_const_2 )),i,_sage_const_0 ,floor((n-_sage_const_5 )/_sage_const_4 ))
  File "/tmp/tmpKvQFbK/___code___.py", line 4, in S
    s = mul(_sage_const_1 +x**(i+_sage_const_1 ) for i in range(n))
TypeError: range() integer end argument expected, got sage.symbolic.expression.Expression.

All advice is welcome.