Simplify symbolic product

As per the title, I want to simplify this product somehow.

var('i,r')
exp = product(1-2**(-i), i, 1, r)


This can be also expressed as

q_pochhammer(r, 2, 2)


However, the latest expression does not accept the symbolic variable r, but only a real integer.

The main problem is that the actual computation (f.e. exp.unhold().subs({r: 12345}) takes a huge amount of time. Is there any way to simplify this product in sage or accelerate this computation somehow? I've already tried all the simplify/expand methods, but also the combsimp method of sympy.

As a side question, is there any way to use the q_pochhammer function symbolically? Maybe I can use the hypergeometric simplifications on it.

edit retag close merge delete

Sort by » oldest newest most voted

Regarding your main problem, you should not use a symbolic expression but a Python function:

sage: exp = lambda r : prod(1-2**(-i) for i in range(1,r-1))


Or, equivalently:

sage: def exp(r):
....:     return prod(1-2**(-i) for i in range(1,r-1))


Then you can do:

sage: a = exp(12345)


which is a rational number with huge numerator and denominator, but you can get an approximation with:

sage: RDF(a)
0.2887880950866024


Regarding your side question, i did not see anything like that in Sage source code, so i guess you have to define such a symbolic function yourself.

more

Thanks for your reply. Indeed, the function is quite faster. I wonder why, during variable substitutions, it doesn't apply this procedure.

( 2021-01-28 08:59:45 +0200 )edit