[Python] How to simplify a logic expresion in sympy?

Discussão em 'Python' iniciado por Stack, Agosto 19, 2025.

  1. Stack

    Stack Membro Participativo

    I'm not sure if I'm doing something wrong, I have the following script:

    X = sympy.Symbol('X', real=True)
    Y = sympy.Symbol('Y', real=True)
    ex = ((X >= 1.4) & (X <= 1.6) & (Y <= 0.5) & (Y > 0.2) & (Y >= 0)).simplify()
    ex = sympy.logic.boolalg.simplify_logic(ex, force=True, deep=True)
    print(ex)


    The result is:

    (X >= 1.4) & (X <= 1.6) & (Y <= 0.5) & (Y > 0.2) & (Y >= 0)


    But I would expect that the 3 comparisons with the variable Y to be reduced to:

    (Y <= 0.5) & (Y > 0.2)


    Any advise on how to do this?

    Continue reading...

Compartilhe esta Página