Repository: sympy/sympy
File: sympy/polys/tests/test_polytools.py (Python)

Code before:
         64*b0**2*b1*b3 + 64*b0**2*b1*b4 - 64*b0**2*b2**2 + 64*b0**2*b2*b3 -
         64*b0**2*b3**2 + 64*b0**2*b3*b4 - 128*b0**2*b4**2 - 64*b0*b1**2*b3 -
         64*b0*b1**2*b4 + 64*b0*b1*b2*b3 - 128*b0*b1*b2*b4 + 128*b0*b1*b3*b4 +
         64*b0*b1*b4**2 + 128*b0*b2**2*b4 - 64*b0*b2*b3**2 - 128*b0*b2*b3*b4 +
         64*b0*b3**3 - 64*b0*b3**2*b4 + 64*b0*b3*b4**2 + 64*b1**3*b4 -
         64*b1**2*b2*b4 - 64*b1**2*b4**2 + 64*b1*b2*b3*b4 + 64*b1*b2*b4**2 -
         64*b1*b3**2*b4 + 64*b1*b3*b4**2 - 64*b1*b4**3 - 64*b2**2*b4**2 +
         64*b2*b3*b4**2 - 64*b3*b4**3 + 64*b4**4),
        (b0**2 + 2*b0*b2 + 2*b0*b4 - b1**2 - 2*b1*b3 + b2**2 + 2*b2*b4 -
         b3**2 + b4**2)]
    assert p1_.schur_conditions() == [
        Mul(-2, Add(b3, Mul(-1, b1), Mul(-2, b4), Mul(2, b0)),
            Add(b0, b2, b4, Mul(-1, b1), Mul(-1, b3)), evaluate=False),
        Add(Mul(-4, Add(Mul(-1, b2), Mul(3, b0), Mul(3, b4)),
            Add(b3, Mul(-1, b1), Mul(-2, b4), Mul(2, b0))),
            Mul(2, Add(b1, Mul(-1, b3), Mul(-2, b4), Mul(2, b0)),
            Add(b0, b2, b4, Mul(-1, b1), Mul(-1, b3)))),
        Mul(-8, Add(Mul(
            Add(Mul(-1, Add(b1, Mul(-1, b3), Mul(-2, b4), Mul(2, b0)),
            Add(b0, b2, b4, Mul(-1, b1), Mul(-1, b3))), Mul(2, Add(Mul(-1, b2),
            Mul(3, b0), Mul(3, b4)), Add(b3, Mul(-1, b1), Mul(-2, b4),
            Mul(2, b0)))), Add(b1, Mul(-1, b3), Mul(-2, b4), Mul(2, b0))),
            Mul(-1,Pow(Add(b3, Mul(-1, b1), Mul(-2, b4),Mul(2, b0)), 2),
            Add(b0, b1, b2, b3, b4))), Add(b3, Mul(-1, b1), Mul(-2, b4),
            Mul(2, b0))),
        Mul(-2, Add(b3, Mul(-1, b1), Mul(-2, b4), Mul(2, b0)), Add(b0, b1, b2, b3, b4))]

    p2 = Poly((x+0.4531)*(x-0.98321)*(x+0.2328)*(x+0.4), x)
    assert all(c > 0 for c in p2.schur_conditions())

    p3 = Poly((x+0.4531)*(x-0.64536)*(x+0.2328)*(x+1.0021), x)
    assert any(c <= 0 for c in p3.schur_conditions())

    p4 = Poly((x+0.4531)*(x-0.64536)*(x+0.2328)*(x+1), x)
    assert any(c <= 0 for c in p4.schur_conditions())

    p5 = Poly((x+0.4)*(x+0.012)*(x**2-1.52*x+0.9872), x)
    assert all(c > 0 for c in p5.schur_conditions())

    assert all(c > 0 for c in p5.set_domain(QQ).schur_conditions())
    assert all(c > 0 for c in p5.set_domain(EXRAW).schur_conditions())

    p6 = Poly((x+0.3)*(x+0.24)*(x-0.1942)*(x**2-1.6*x+1), x)
    assert any(c <= 0 for c in p6.schur_conditions())

    assert any(c <= 0 for c in p6.set_domain(QQ).schur_conditions())
    assert any(c <= 0 for c in p6.set_domain(EXRAW).schur_conditions())


Review comment (suggestion):
The answer can be written as normal looking expressions e.g. the first item is `-2*((2*b_0 - b_1 + b_3 - 2*b_4)*(b_0 - b_1 + b_2 - b_3 + b_4))`

Code after:
        (64*b0**4 - 64*b0**3*b1 - 64*b0**3*b3 + 64*b0**2*b1*b2 +
         64*b0**2*b1*b3 + 64*b0**2*b1*b4 - 64*b0**2*b2**2 + 64*b0**2*b2*b3 -
         64*b0**2*b3**2 + 64*b0**2*b3*b4 - 128*b0**2*b4**2 - 64*b0*b1**2*b3 -
         64*b0*b1**2*b4 + 64*b0*b1*b2*b3 - 128*b0*b1*b2*b4 + 128*b0*b1*b3*b4 +
         64*b0*b1*b4**2 + 128*b0*b2**2*b4 - 64*b0*b2*b3**2 - 128*b0*b2*b3*b4 +
         64*b0*b3**3 - 64*b0*b3**2*b4 + 64*b0*b3*b4**2 + 64*b1**3*b4 -
         64*b1**2*b2*b4 - 64*b1**2*b4**2 + 64*b1*b2*b3*b4 + 64*b1*b2*b4**2 -
         64*b1*b3**2*b4 + 64*b1*b3*b4**2 - 64*b1*b4**3 - 64*b2**2*b4**2 +
         64*b2*b3*b4**2 - 64*b3*b4**3 + 64*b4**4),
        (b0**2 + 2*b0*b2 + 2*b0*b4 - b1**2 - 2*b1*b3 + b2**2 + 2*b2*b4 -
         b3**2 + b4**2)]
    assert p1_.schur_conditions() == [
        -2*((2*b0 - b1 + b3 - 2*b4)*(b0 - b1 + b2 - b3 + b4)),
        (-4*((3*b0 - b2 + 3*b4)*(2*b0 - b1 + b3 - 2*b4)) +
         2*((2*b0 + b1 - b3 - 2*b4)*(b0 - b1 + b2 - b3 + b4))),
        (-8*(((2*((3*b0 - b2 + 3*b4)*(2*b0 - b1 + b3 - 2*b4)) -
         (2*b0 + b1 - b3 - 2*b4)*(b0 - b1 + b2 - b3 + b4))*
         (2*b0 + b1 - b3 - 2*b4) - (2*b0 - b1 + b3 - 2*b4)**2*
         (b0 + b1 + b2 + b3 + b4))*(2*b0 - b1 + b3 - 2*b4))),
        -2*((2*b0 - b1 + b3 - 2*b4)*(b0 + b1 + b2 + b3 + b4))]

    p2 = Poly((x+0.4531)*(x-0.98321)*(x+0.2328)*(x+0.4), x)
    assert all(c > 0 for c in p2.schur_conditions())

    p3 = Poly((x+0.4531)*(x-0.64536)*(x+0.2328)*(x+1.0021), x)
    assert any(c <= 0 for c in p3.schur_conditions())

    p4 = Poly((x+0.4531)*(x-0.64536)*(x+0.2328)*(x+1), x)
    assert any(c <= 0 for c in p4.schur_conditions())

    p5 = Poly((x+0.4)*(x+0.012)*(x**2-1.52*x+0.9872), x)
    assert all(c > 0 for c in p5.schur_conditions())

    assert all(c > 0 for c in p5.set_domain(QQ).schur_conditions())
    assert all(c > 0 for c in p5.set_domain(EXRAW).schur_conditions())

    p6 = Poly((x+0.3)*(x+0.24)*(x-0.1942)*(x**2-1.6*x+1), x)
    assert any(c <= 0 for c in p6.schur_conditions())

    assert any(c <= 0 for c in p6.set_domain(QQ).schur_conditions())
    assert any(c <= 0 for c in p6.set_domain(EXRAW).schur_conditions())