Help needed with SymPy nonlinear/exponential integration issue : integrate(x/(exp(x)-1), x) #30167

88 views
Skip to first unread message

Shaik Suhail

unread,
Aug 28, 2026, 2:01:31 AMAug 28
to sympy

Dear SymPy Developers and Contributors,

I am currently working on a SymPy integration issue involving the following integral:

from sympy import symbols, exp, integrate x = symbols('x') integrate(x/(exp(x) - 1), x)

Currently, SymPy leaves this integral unevaluated. The expected result is an antiderivative equivalent to:

x*log(1 - exp(-x)) - polylog(2, exp(-x))

I have been investigating the issue in sympy/integrals/manualintegrate.py, particularly the functions substitution_rule(), find_substitutions(), test_subterm(), manual_subs(), and URule.

During the investigation, I found that find_substitutions() is already generating the required candidate:

exp(x) - 1

For the substitution

SymPy calculates:

du/dx = exp(x)

and obtains the transformed expression:

x*exp(-x)/_u

However, this is rejected by:

if substituted.has_free(symbol): return False

because x is still present.

I then investigated the inverse substitution and found that SymPy can already determine:

solve(Eq(u, exp(x) - 1), x)

which gives:

[log(u + 1)]

Using this inverse transformation, the expression becomes:

log(u + 1)/(u*(u + 1))

which is the desired transformed integral.

I also inspected manual_subs(). It already contains additional logic for certain invertible functions, particularly logarithms, but it does not appear to handle this type of inverse substitution.

I also checked URule. However, URule does not seem to be the initial source of the problem because the substitution is rejected inside test_subterm() before a URule is created.

At this point, I am unsure about the best way to implement the fix. The obvious approach would be to use something like:

solve(Eq(u_var, u), symbol)

to obtain the inverse substitution, but I am concerned that using the general solve() inside the integration machinery could introduce performance, branch, and assumption/domain issues.

Therefore, I would appreciate guidance on the following:

  1. Is there an existing SymPy utility for finding inverse substitutions that I should use?
  2. Should this logic be implemented in find_substitutions(), manual_subs(), or elsewhere?
  3. Is using solve() for this purpose acceptable?
  4. Are there similar existing cases or tests that I should study before implementing the fix?

I have not made a permanent change yet because I would like to make sure the solution addresses the underlying substitution problem rather than hard-coding this particular integral.

Thank you for your time and guidance.

Best regards,
Suhail

Oldřich Klimánek

unread,
Aug 28, 2026, 6:16:59 AMAug 28
to sy...@googlegroups.com
Hi there,
I was working on it and have come up with this:


I still haven’t started implementing it but it might help you to do so.

Best,
Oldrich

28. 8. 2026 v 8:01, Shaik Suhail <suhailsh...@gmail.com>:

--
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/sympy/f1c50dbf-1aca-425e-b652-b74924121008n%40googlegroups.com.

Shaik Suhail

unread,
Aug 28, 2026, 6:24:06 AMAug 28
to sy...@googlegroups.com
Hi Oldrich,
Thank you for sharing the repository. I’ll go through it and try to understand the approach.
Since I’m planning to work on implementing this in SymPy, could you please give me some guidance on how the approach in your repository could be adapted to SymPy? In particular, I’d like to understand which parts of the work would be useful as a starting point and how you think the implementation should fit into SymPy’s existing structure.
I’ll also try to investigate the relevant SymPy code and work out a possible implementation myself before asking further questions.
Thanks again for your help!

Chris Smith

unread,
Sep 20, 2026, 1:04:59 AMSep 20
to sympy
Perhaps the existing linear-u fallback in test_subterm could be generalized to expressions that are linear in a single explicitly invertible generator, e.g. exp(x), log(x), or 1/x. Poly could be used after replacing that generator with a dummy Symbol to obtain the linear relation, avoiding a general call to solve. Then the known inverse of the generator can be used to eliminate the remaining x.  

/c

Chris Smith

unread,
Sep 20, 2026, 1:14:30 AMSep 20
to sympy
Actually,  there is already inverse u-substitution machinery in Integral.transform, and it transforms this particular integral correctly. Could test_subterm use that as its fallback when direct substitution leaves the original integration variable?  

>>>  Integral(x/(exp(x) - 1), x).transform(exp(x) - 1, u) ->  Integral(log(u + 1)/(u*(u + 1)), u)

/c
Reply all
Reply to author
Forward
0 new messages