[Python] sympy simplify cannot recognize square of a binomial

Discussão em 'Python' iniciado por Stack, Julho 10, 2025.

  1. Stack

    Stack Membro Participativo

    I have several expression where simplification would drastically improve if simplify would be able to recognize the square of a binomial just as in the screenshot.

    [​IMG]

    Is there any way to let sympy/simplify do this?

    import sympy as sp
    a, b = sp.symbols('a, b', positive=True)
    sp.simplify(sp.sqrt(a**2))
    test = a + b - sp.sqrt(a**2+b**2+2*a*b)
    sp.simplify(test)

    Continue reading...

Compartilhe esta Página