The Python Oracle

Sympy generating broken `Piecewise` conditions when simplifying

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Romantic Lands Beckon

--

Chapters
00:00 Sympy Generating Broken `Piecewise` Conditions When Simplifying
02:06 Accepted Answer Score 1
02:38 Thank you

--

Full question
https://stackoverflow.com/questions/5328...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #sympy

#avk47



ACCEPTED ANSWER

Score 1


The output is not "broken" or "nonsensical". It is logically correct, although not presented in the simplest form possible.

The condition if n == 3 and n != 0 could be simplified to if n == 3. There is a difference between "could be simplified" and "is completely nonsensical".

But yes, please report it on SymPy tracker, since the simplification is incomplete; a better result would be Piecewise((0, Ne(n, 3)), (-1.0, True)).