Example #1
0
"""Tools for polynomial factorization routines in characteristic zero."""

import functools
import operator

import pytest

from diofant import (EX, FF, QQ, RR, ZZ, DomainError, ExtraneousFactors, I,
                     nextprime, pi, ring, sin, sqrt)
from diofant.polys.polyconfig import using
from diofant.polys.specialpolys import f_polys, w_polys

__all__ = ()

f_0, f_1, f_2, f_3, f_4, f_5, f_6 = f_polys()
w_1, w_2 = w_polys()


def test__trial_division():
    R, x = ring('x', ZZ)

    assert R._trial_division(
        x**5 + 8 * x**4 + 25 * x**3 + 38 * x**2 + 28 * x + 8,
        (x + 1, x + 2)) == [(x + 1, 2), (x + 2, 3)]

    R, x, y = ring('x y', ZZ)

    assert R._trial_division(
        x**5 + 8 * x**4 + 25 * x**3 + 38 * x**2 + 28 * x + 8,
        (x + 1, x + 2)) == [(x + 1, 2), (x + 2, 3)]
Example #2
0
import pytest

from diofant import I, nextprime, sin, sqrt
from diofant.domains import EX, FF, QQ, RR, ZZ
from diofant.polys import polyconfig as config
from diofant.polys.factortools import dmp_irreducible_p, dmp_zz_diophantine
from diofant.polys.polyerrors import DomainError
from diofant.polys.rings import ring
from diofant.polys.specialpolys import f_polys, w_polys


__all__ = ()

f_0, f_1, f_2, f_3, f_4, f_5, f_6 = f_polys()
w_1, w_2 = w_polys()


def test_dmp_trial_division():
    R, x = ring("x", ZZ)
    assert R.dmp_trial_division(x**5 + 8*x**4 + 25*x**3 + 38*x**2 + 28*x + 8, (x + 1, x + 2)) == [(x + 1, 2), (x + 2, 3)]

    R, x, y = ring("x,y", ZZ)
    assert R.dmp_trial_division(x**5 + 8*x**4 + 25*x**3 + 38*x**2 + 28*x + 8, (x + 1, x + 2)) == [(x + 1, 2), (x + 2, 3)]


def test_dmp_zz_mignotte_bound():
    R, x = ring("x", ZZ)
    assert R.dmp_zz_mignotte_bound(2*x**2 + 3*x + 4) == 32

    R, x, y = ring("x,y", ZZ)