Fix issue sympy/sympy#7282.