Search code examples
sympysimplifypiecewise

Sympy Piecewise and refine


I try to simplify this Piecewise expression using refine without success. I use sympy version 1.8.

import sympy as sp

x,y = sp.symbols('x,y', real=True, positive=True)

expr = sp.Piecewise((1, x>=y),(0,  True))

expr variable contain

⎧1  for x ≥ y
⎨            
⎩0  otherwise

now I try to obtain 1 assuming that x>y

sp.refine(expr, sp.Q.gt(x,y))

but I obtain the same expression

⎧1  for x ≥ y
⎨            
⎩0  otherwise

Any ideas to force this simplification ?

Thank you for your help


Solution

  • If you give expr a value for x that satisfies the requirement, it will evaluate:

    >>> eps = Symbol('eps', positive=True)
    >>> expr.subs(x, y + eps).simplify()
    1