[Python] Sympy having trouble simplifying fractions, which are easily simplified by hand

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

  1. Stack

    Stack Membro Participativo

    I have found this annoying problem in sympy. I want to simply the following simple fraction expression below but can't make it work... Sympy even recognizes the two equations as equal making it even more frustrating.

    import sympy as sp
    a,b,c,d = sp.symbols('a, b, c, d', positive = True)
    expr = (a*b*c+2*d*a*c+b*c*d)/(2*a+b)
    correct_simpl = c*(d + a*b/(2*a+b))
    display(expr)
    display(expr.simplify())
    display(correct_simpl)
    correct_simpl.equals(expr)


    Returns: [​IMG]

    Continue reading...

Compartilhe esta Página