Question Details

No question body available.

Tags

python sympy

Answers (1)

November 2, 2025 Score: 2 Rep: 13,790 Quality: Medium Completeness: 60%

Note that:

Qrotated.equals(a * xrot2 + 2bxrot*yrot + c * yrot2)

False

The problem is this substitution:

Qrotated = Qoriginal.subs({x: xrot, y: yrot})

SymPy first substitues x with xrot, some evaluation happens, then it substitutes y with yrot and some other evaluation happens.

What you want to do is to delay the evaluation by setting simultaneous=True.

Qrotated = Qoriginal.subs({x: xrot, y: yrot}, simultaneous=True)

After that, you'll get the expected result.

According to the docs, help(Qoriginal.sub):

If the keyword simultaneous is True, the subexpressions will not be evaluated until all the substitutions have been made.

The docs also shows a couple of nice examples about this behavior.