← All challenges
hardsympy/sympy · v1.8

`refine()` does not understand how to simplify complex arguments

Try this bug with AI

Fix it in the original repo with an AI agent and get feedback on how you worked.

2 free rounds each week

Round mode
  • Time limit60 min
  • Token budgetup to 1M
  • Worth up to310 XP
Sign up or sign in to start

Read the sample report

From a simulated Django round

You changed code before reproducing the bug.

Run the failing test before the first edit, so you know the failure you are fixing and can tell when it is gone.

Problem statement

Just learned about the refine-function, which would come in handy frequently for me. But
refine() does not recognize that argument functions simplify for real numbers.

>>> from sympy import *                                                     
>>> var('a,x')                                                              
>>> J = Integral(sin(x)*exp(-a*x),(x,0,oo))                                     
>>> J.doit()
	Piecewise((1/(a**2 + 1), 2*Abs(arg(a)) < pi), (Integral(exp(-a*x)*sin(x), (x, 0, oo)), True))
>>> refine(J.doit(),Q.positive(a))                                                 
        Piecewise((1/(a**2 + 1), 2*Abs(arg(a)) < pi), (Integral(exp(-a*x)*sin(x), (x, 0, oo)), True))
>>> refine(abs(a),Q.positive(a))                                            
	a
>>> refine(arg(a),Q.positive(a))                                            
	arg(a)

I cann't find any open issues identifying this. Easy to fix, though.

The environment starts at commit 748ce73479ee (sympy/sympy 1.8), dependencies installed and tests runnable from the first minute. You are graded by hidden tests taken from the fix that was actually merged upstream.