Ask Your Question
2

Simplify symbolic product

asked 2021-01-27 15:21:13 +0100

tigerjack gravatar image

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 flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2021-01-27 17:29:05 +0100

tmonteil gravatar image

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.

edit flag offensive delete link more

Comments

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

tigerjack gravatar imagetigerjack ( 2021-01-28 08:59:45 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2021-01-27 15:21:13 +0100

Seen: 708 times

Last updated: Jan 27 '21