Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- pllava/lib/python3.10/site-packages/sympy/polys/numberfields/__pycache__/__init__.cpython-310.pyc +0 -0
- pllava/lib/python3.10/site-packages/sympy/polys/numberfields/__pycache__/basis.cpython-310.pyc +0 -0
- pllava/lib/python3.10/site-packages/sympy/polys/numberfields/__pycache__/galois_resolvents.cpython-310.pyc +0 -0
- pllava/lib/python3.10/site-packages/sympy/polys/numberfields/__pycache__/minpoly.cpython-310.pyc +0 -0
- pllava/lib/python3.10/site-packages/sympy/polys/numberfields/__pycache__/resolvent_lookup.cpython-310.pyc +0 -0
- pllava/lib/python3.10/site-packages/sympy/polys/numberfields/__pycache__/utilities.cpython-310.pyc +0 -0
- pllava/lib/python3.10/site-packages/sympy/polys/numberfields/tests/__init__.py +0 -0
- pllava/lib/python3.10/site-packages/sympy/polys/numberfields/tests/__pycache__/test_basis.cpython-310.pyc +0 -0
- pllava/lib/python3.10/site-packages/sympy/polys/numberfields/tests/__pycache__/test_galoisgroups.cpython-310.pyc +0 -0
- pllava/lib/python3.10/site-packages/sympy/polys/numberfields/tests/__pycache__/test_modules.cpython-310.pyc +0 -0
- pllava/lib/python3.10/site-packages/sympy/polys/numberfields/tests/__pycache__/test_utilities.cpython-310.pyc +0 -0
- pllava/lib/python3.10/site-packages/sympy/polys/numberfields/tests/test_basis.py +85 -0
- pllava/lib/python3.10/site-packages/sympy/polys/numberfields/tests/test_galoisgroups.py +143 -0
- pllava/lib/python3.10/site-packages/sympy/polys/numberfields/tests/test_minpoly.py +474 -0
- pllava/lib/python3.10/site-packages/sympy/polys/numberfields/tests/test_numbers.py +202 -0
- pllava/lib/python3.10/site-packages/sympy/polys/numberfields/tests/test_primes.py +296 -0
- pllava/lib/python3.10/site-packages/sympy/polys/tests/__init__.py +0 -0
- pllava/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_appellseqs.cpython-310.pyc +0 -0
- pllava/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_constructor.cpython-310.pyc +0 -0
- pllava/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_densearith.cpython-310.pyc +0 -0
- pllava/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_densebasic.cpython-310.pyc +0 -0
- pllava/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_densetools.cpython-310.pyc +0 -0
- pllava/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_dispersion.cpython-310.pyc +0 -0
- pllava/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_distributedmodules.cpython-310.pyc +0 -0
- pllava/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_euclidtools.cpython-310.pyc +0 -0
- pllava/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_factortools.cpython-310.pyc +0 -0
- pllava/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_groebnertools.cpython-310.pyc +0 -0
- pllava/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_heuristicgcd.cpython-310.pyc +0 -0
- pllava/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_orderings.cpython-310.pyc +0 -0
- pllava/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_partfrac.cpython-310.pyc +0 -0
- pllava/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_polymatrix.cpython-310.pyc +0 -0
- pllava/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_polyoptions.cpython-310.pyc +0 -0
- pllava/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_polyutils.cpython-310.pyc +0 -0
- pllava/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_ring_series.cpython-310.pyc +0 -0
- pllava/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_specialpolys.cpython-310.pyc +0 -0
- pllava/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_sqfreetools.cpython-310.pyc +0 -0
- pllava/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_subresultants_qq_zz.cpython-310.pyc +0 -0
- pllava/lib/python3.10/site-packages/sympy/polys/tests/test_appellseqs.py +91 -0
- pllava/lib/python3.10/site-packages/sympy/polys/tests/test_constructor.py +208 -0
- pllava/lib/python3.10/site-packages/sympy/polys/tests/test_densearith.py +997 -0
- pllava/lib/python3.10/site-packages/sympy/polys/tests/test_densebasic.py +730 -0
- pllava/lib/python3.10/site-packages/sympy/polys/tests/test_densetools.py +715 -0
- pllava/lib/python3.10/site-packages/sympy/polys/tests/test_dispersion.py +95 -0
- pllava/lib/python3.10/site-packages/sympy/polys/tests/test_distributedmodules.py +208 -0
- pllava/lib/python3.10/site-packages/sympy/polys/tests/test_euclidtools.py +712 -0
- pllava/lib/python3.10/site-packages/sympy/polys/tests/test_factortools.py +784 -0
- pllava/lib/python3.10/site-packages/sympy/polys/tests/test_fields.py +362 -0
- pllava/lib/python3.10/site-packages/sympy/polys/tests/test_galoistools.py +875 -0
- pllava/lib/python3.10/site-packages/sympy/polys/tests/test_groebnertools.py +533 -0
- pllava/lib/python3.10/site-packages/sympy/polys/tests/test_heuristicgcd.py +152 -0
pllava/lib/python3.10/site-packages/sympy/polys/numberfields/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (663 Bytes). View file
|
|
|
pllava/lib/python3.10/site-packages/sympy/polys/numberfields/__pycache__/basis.cpython-310.pyc
ADDED
|
Binary file (7.25 kB). View file
|
|
|
pllava/lib/python3.10/site-packages/sympy/polys/numberfields/__pycache__/galois_resolvents.cpython-310.pyc
ADDED
|
Binary file (24.3 kB). View file
|
|
|
pllava/lib/python3.10/site-packages/sympy/polys/numberfields/__pycache__/minpoly.cpython-310.pyc
ADDED
|
Binary file (24.4 kB). View file
|
|
|
pllava/lib/python3.10/site-packages/sympy/polys/numberfields/__pycache__/resolvent_lookup.cpython-310.pyc
ADDED
|
Binary file (59.9 kB). View file
|
|
|
pllava/lib/python3.10/site-packages/sympy/polys/numberfields/__pycache__/utilities.cpython-310.pyc
ADDED
|
Binary file (12.8 kB). View file
|
|
|
pllava/lib/python3.10/site-packages/sympy/polys/numberfields/tests/__init__.py
ADDED
|
File without changes
|
pllava/lib/python3.10/site-packages/sympy/polys/numberfields/tests/__pycache__/test_basis.cpython-310.pyc
ADDED
|
Binary file (3.57 kB). View file
|
|
|
pllava/lib/python3.10/site-packages/sympy/polys/numberfields/tests/__pycache__/test_galoisgroups.cpython-310.pyc
ADDED
|
Binary file (4.97 kB). View file
|
|
|
pllava/lib/python3.10/site-packages/sympy/polys/numberfields/tests/__pycache__/test_modules.cpython-310.pyc
ADDED
|
Binary file (28 kB). View file
|
|
|
pllava/lib/python3.10/site-packages/sympy/polys/numberfields/tests/__pycache__/test_utilities.cpython-310.pyc
ADDED
|
Binary file (4.82 kB). View file
|
|
|
pllava/lib/python3.10/site-packages/sympy/polys/numberfields/tests/test_basis.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sympy.abc import x
|
| 2 |
+
from sympy.core import S
|
| 3 |
+
from sympy.core.numbers import AlgebraicNumber
|
| 4 |
+
from sympy.functions.elementary.miscellaneous import sqrt
|
| 5 |
+
from sympy.polys import Poly, cyclotomic_poly
|
| 6 |
+
from sympy.polys.domains import QQ
|
| 7 |
+
from sympy.polys.matrices import DomainMatrix, DM
|
| 8 |
+
from sympy.polys.numberfields.basis import round_two
|
| 9 |
+
from sympy.testing.pytest import raises
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def test_round_two():
|
| 13 |
+
# Poly must be irreducible, and over ZZ or QQ:
|
| 14 |
+
raises(ValueError, lambda: round_two(Poly(x ** 2 - 1)))
|
| 15 |
+
raises(ValueError, lambda: round_two(Poly(x ** 2 + sqrt(2))))
|
| 16 |
+
|
| 17 |
+
# Test on many fields:
|
| 18 |
+
cases = (
|
| 19 |
+
# A couple of cyclotomic fields:
|
| 20 |
+
(cyclotomic_poly(5), DomainMatrix.eye(4, QQ), 125),
|
| 21 |
+
(cyclotomic_poly(7), DomainMatrix.eye(6, QQ), -16807),
|
| 22 |
+
# A couple of quadratic fields (one 1 mod 4, one 3 mod 4):
|
| 23 |
+
(x ** 2 - 5, DM([[1, (1, 2)], [0, (1, 2)]], QQ), 5),
|
| 24 |
+
(x ** 2 - 7, DM([[1, 0], [0, 1]], QQ), 28),
|
| 25 |
+
# Dedekind's example of a field with 2 as essential disc divisor:
|
| 26 |
+
(x ** 3 + x ** 2 - 2 * x + 8, DM([[1, 0, 0], [0, 1, 0], [0, (1, 2), (1, 2)]], QQ).transpose(), -503),
|
| 27 |
+
# A bunch of cubics with various forms for F -- all of these require
|
| 28 |
+
# second or third enlargements. (Five of them require a third, while the rest require just a second.)
|
| 29 |
+
# F = 2^2
|
| 30 |
+
(x**3 + 3 * x**2 - 4 * x + 4, DM([((1, 2), (1, 4), (1, 4)), (0, (1, 2), (1, 2)), (0, 0, 1)], QQ).transpose(), -83),
|
| 31 |
+
# F = 2^2 * 3
|
| 32 |
+
(x**3 + 3 * x**2 + 3 * x - 3, DM([((1, 2), 0, (1, 2)), (0, 1, 0), (0, 0, 1)], QQ).transpose(), -108),
|
| 33 |
+
# F = 2^3
|
| 34 |
+
(x**3 + 5 * x**2 - x + 3, DM([((1, 4), 0, (3, 4)), (0, (1, 2), (1, 2)), (0, 0, 1)], QQ).transpose(), -31),
|
| 35 |
+
# F = 2^2 * 5
|
| 36 |
+
(x**3 + 5 * x**2 - 5 * x - 5, DM([((1, 2), 0, (1, 2)), (0, 1, 0), (0, 0, 1)], QQ).transpose(), 1300),
|
| 37 |
+
# F = 3^2
|
| 38 |
+
(x**3 + 3 * x**2 + 5, DM([((1, 3), (1, 3), (1, 3)), (0, 1, 0), (0, 0, 1)], QQ).transpose(), -135),
|
| 39 |
+
# F = 3^3
|
| 40 |
+
(x**3 + 6 * x**2 + 3 * x - 1, DM([((1, 3), (1, 3), (1, 3)), (0, 1, 0), (0, 0, 1)], QQ).transpose(), 81),
|
| 41 |
+
# F = 2^2 * 3^2
|
| 42 |
+
(x**3 + 6 * x**2 + 4, DM([((1, 3), (2, 3), (1, 3)), (0, 1, 0), (0, 0, (1, 2))], QQ).transpose(), -108),
|
| 43 |
+
# F = 2^3 * 7
|
| 44 |
+
(x**3 + 7 * x**2 + 7 * x - 7, DM([((1, 4), 0, (3, 4)), (0, (1, 2), (1, 2)), (0, 0, 1)], QQ).transpose(), 49),
|
| 45 |
+
# F = 2^2 * 13
|
| 46 |
+
(x**3 + 7 * x**2 - x + 5, DM([((1, 2), 0, (1, 2)), (0, 1, 0), (0, 0, 1)], QQ).transpose(), -2028),
|
| 47 |
+
# F = 2^4
|
| 48 |
+
(x**3 + 7 * x**2 - 5 * x + 5, DM([((1, 4), 0, (3, 4)), (0, (1, 2), (1, 2)), (0, 0, 1)], QQ).transpose(), -140),
|
| 49 |
+
# F = 5^2
|
| 50 |
+
(x**3 + 4 * x**2 - 3 * x + 7, DM([((1, 5), (4, 5), (4, 5)), (0, 1, 0), (0, 0, 1)], QQ).transpose(), -175),
|
| 51 |
+
# F = 7^2
|
| 52 |
+
(x**3 + 8 * x**2 + 5 * x - 1, DM([((1, 7), (6, 7), (2, 7)), (0, 1, 0), (0, 0, 1)], QQ).transpose(), 49),
|
| 53 |
+
# F = 2 * 5 * 7
|
| 54 |
+
(x**3 + 8 * x**2 - 2 * x + 6, DM([(1, 0, 0), (0, 1, 0), (0, 0, 1)], QQ).transpose(), -14700),
|
| 55 |
+
# F = 2^2 * 3 * 5
|
| 56 |
+
(x**3 + 6 * x**2 - 3 * x + 8, DM([(1, 0, 0), (0, (1, 4), (1, 4)), (0, 0, 1)], QQ).transpose(), -675),
|
| 57 |
+
# F = 2 * 3^2 * 7
|
| 58 |
+
(x**3 + 9 * x**2 + 6 * x - 8, DM([(1, 0, 0), (0, (1, 2), (1, 2)), (0, 0, 1)], QQ).transpose(), 3969),
|
| 59 |
+
# F = 2^2 * 3^2 * 7
|
| 60 |
+
(x**3 + 15 * x**2 - 9 * x + 13, DM([((1, 6), (1, 3), (1, 6)), (0, 1, 0), (0, 0, 1)], QQ).transpose(), -5292),
|
| 61 |
+
# Polynomial need not be monic
|
| 62 |
+
(5*x**3 + 5*x**2 - 10 * x + 40, DM([[1, 0, 0], [0, 1, 0], [0, (1, 2), (1, 2)]], QQ).transpose(), -503),
|
| 63 |
+
# Polynomial can have non-integer rational coeffs
|
| 64 |
+
(QQ(5, 3)*x**3 + QQ(5, 3)*x**2 - QQ(10, 3)*x + QQ(40, 3), DM([[1, 0, 0], [0, 1, 0], [0, (1, 2), (1, 2)]], QQ).transpose(), -503),
|
| 65 |
+
)
|
| 66 |
+
for f, B_exp, d_exp in cases:
|
| 67 |
+
K = QQ.alg_field_from_poly(f)
|
| 68 |
+
B = K.maximal_order().QQ_matrix
|
| 69 |
+
d = K.discriminant()
|
| 70 |
+
assert d == d_exp
|
| 71 |
+
# The computed basis need not equal the expected one, but their quotient
|
| 72 |
+
# must be unimodular:
|
| 73 |
+
assert (B.inv()*B_exp).det()**2 == 1
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def test_AlgebraicField_integral_basis():
|
| 77 |
+
alpha = AlgebraicNumber(sqrt(5), alias='alpha')
|
| 78 |
+
k = QQ.algebraic_field(alpha)
|
| 79 |
+
B0 = k.integral_basis()
|
| 80 |
+
B1 = k.integral_basis(fmt='sympy')
|
| 81 |
+
B2 = k.integral_basis(fmt='alg')
|
| 82 |
+
assert B0 == [k([1]), k([S.Half, S.Half])]
|
| 83 |
+
assert B1 == [1, S.Half + alpha/2]
|
| 84 |
+
assert B2 == [k.ext.field_element([1]),
|
| 85 |
+
k.ext.field_element([S.Half, S.Half])]
|
pllava/lib/python3.10/site-packages/sympy/polys/numberfields/tests/test_galoisgroups.py
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for computing Galois groups. """
|
| 2 |
+
|
| 3 |
+
from sympy.abc import x
|
| 4 |
+
from sympy.combinatorics.galois import (
|
| 5 |
+
S1TransitiveSubgroups, S2TransitiveSubgroups, S3TransitiveSubgroups,
|
| 6 |
+
S4TransitiveSubgroups, S5TransitiveSubgroups, S6TransitiveSubgroups,
|
| 7 |
+
)
|
| 8 |
+
from sympy.polys.domains.rationalfield import QQ
|
| 9 |
+
from sympy.polys.numberfields.galoisgroups import (
|
| 10 |
+
tschirnhausen_transformation,
|
| 11 |
+
galois_group,
|
| 12 |
+
_galois_group_degree_4_root_approx,
|
| 13 |
+
_galois_group_degree_5_hybrid,
|
| 14 |
+
)
|
| 15 |
+
from sympy.polys.numberfields.subfield import field_isomorphism
|
| 16 |
+
from sympy.polys.polytools import Poly
|
| 17 |
+
from sympy.testing.pytest import raises
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def test_tschirnhausen_transformation():
|
| 21 |
+
for T in [
|
| 22 |
+
Poly(x**2 - 2),
|
| 23 |
+
Poly(x**2 + x + 1),
|
| 24 |
+
Poly(x**4 + 1),
|
| 25 |
+
Poly(x**4 - x**3 + x**2 - x + 1),
|
| 26 |
+
]:
|
| 27 |
+
_, U = tschirnhausen_transformation(T)
|
| 28 |
+
assert U.degree() == T.degree()
|
| 29 |
+
assert U.is_monic
|
| 30 |
+
assert U.is_irreducible
|
| 31 |
+
K = QQ.alg_field_from_poly(T)
|
| 32 |
+
L = QQ.alg_field_from_poly(U)
|
| 33 |
+
assert field_isomorphism(K.ext, L.ext) is not None
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
# Test polys are from:
|
| 37 |
+
# Cohen, H. *A Course in Computational Algebraic Number Theory*.
|
| 38 |
+
test_polys_by_deg = {
|
| 39 |
+
# Degree 1
|
| 40 |
+
1: [
|
| 41 |
+
(x, S1TransitiveSubgroups.S1, True)
|
| 42 |
+
],
|
| 43 |
+
# Degree 2
|
| 44 |
+
2: [
|
| 45 |
+
(x**2 + x + 1, S2TransitiveSubgroups.S2, False)
|
| 46 |
+
],
|
| 47 |
+
# Degree 3
|
| 48 |
+
3: [
|
| 49 |
+
(x**3 + x**2 - 2*x - 1, S3TransitiveSubgroups.A3, True),
|
| 50 |
+
(x**3 + 2, S3TransitiveSubgroups.S3, False),
|
| 51 |
+
],
|
| 52 |
+
# Degree 4
|
| 53 |
+
4: [
|
| 54 |
+
(x**4 + x**3 + x**2 + x + 1, S4TransitiveSubgroups.C4, False),
|
| 55 |
+
(x**4 + 1, S4TransitiveSubgroups.V, True),
|
| 56 |
+
(x**4 - 2, S4TransitiveSubgroups.D4, False),
|
| 57 |
+
(x**4 + 8*x + 12, S4TransitiveSubgroups.A4, True),
|
| 58 |
+
(x**4 + x + 1, S4TransitiveSubgroups.S4, False),
|
| 59 |
+
],
|
| 60 |
+
# Degree 5
|
| 61 |
+
5: [
|
| 62 |
+
(x**5 + x**4 - 4*x**3 - 3*x**2 + 3*x + 1, S5TransitiveSubgroups.C5, True),
|
| 63 |
+
(x**5 - 5*x + 12, S5TransitiveSubgroups.D5, True),
|
| 64 |
+
(x**5 + 2, S5TransitiveSubgroups.M20, False),
|
| 65 |
+
(x**5 + 20*x + 16, S5TransitiveSubgroups.A5, True),
|
| 66 |
+
(x**5 - x + 1, S5TransitiveSubgroups.S5, False),
|
| 67 |
+
],
|
| 68 |
+
# Degree 6
|
| 69 |
+
6: [
|
| 70 |
+
(x**6 + x**5 + x**4 + x**3 + x**2 + x + 1, S6TransitiveSubgroups.C6, False),
|
| 71 |
+
(x**6 + 108, S6TransitiveSubgroups.S3, False),
|
| 72 |
+
(x**6 + 2, S6TransitiveSubgroups.D6, False),
|
| 73 |
+
(x**6 - 3*x**2 - 1, S6TransitiveSubgroups.A4, True),
|
| 74 |
+
(x**6 + 3*x**3 + 3, S6TransitiveSubgroups.G18, False),
|
| 75 |
+
(x**6 - 3*x**2 + 1, S6TransitiveSubgroups.A4xC2, False),
|
| 76 |
+
(x**6 - 4*x**2 - 1, S6TransitiveSubgroups.S4p, True),
|
| 77 |
+
(x**6 - 3*x**5 + 6*x**4 - 7*x**3 + 2*x**2 + x - 4, S6TransitiveSubgroups.S4m, False),
|
| 78 |
+
(x**6 + 2*x**3 - 2, S6TransitiveSubgroups.G36m, False),
|
| 79 |
+
(x**6 + 2*x**2 + 2, S6TransitiveSubgroups.S4xC2, False),
|
| 80 |
+
(x**6 + 10*x**5 + 55*x**4 + 140*x**3 + 175*x**2 + 170*x + 25, S6TransitiveSubgroups.PSL2F5, True),
|
| 81 |
+
(x**6 + 10*x**5 + 55*x**4 + 140*x**3 + 175*x**2 - 3019*x + 25, S6TransitiveSubgroups.PGL2F5, False),
|
| 82 |
+
(x**6 + 6*x**4 + 2*x**3 + 9*x**2 + 6*x - 4, S6TransitiveSubgroups.G36p, True),
|
| 83 |
+
(x**6 + 2*x**4 + 2*x**3 + x**2 + 2*x + 2, S6TransitiveSubgroups.G72, False),
|
| 84 |
+
(x**6 + 24*x - 20, S6TransitiveSubgroups.A6, True),
|
| 85 |
+
(x**6 + x + 1, S6TransitiveSubgroups.S6, False),
|
| 86 |
+
],
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
def test_galois_group():
|
| 91 |
+
"""
|
| 92 |
+
Try all the test polys.
|
| 93 |
+
"""
|
| 94 |
+
for deg in range(1, 7):
|
| 95 |
+
polys = test_polys_by_deg[deg]
|
| 96 |
+
for T, G, alt in polys:
|
| 97 |
+
assert galois_group(T, by_name=True) == (G, alt)
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
def test_galois_group_degree_out_of_bounds():
|
| 101 |
+
raises(ValueError, lambda: galois_group(Poly(0, x)))
|
| 102 |
+
raises(ValueError, lambda: galois_group(Poly(1, x)))
|
| 103 |
+
raises(ValueError, lambda: galois_group(Poly(x ** 7 + 1)))
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
def test_galois_group_not_by_name():
|
| 107 |
+
"""
|
| 108 |
+
Check at least one polynomial of each supported degree, to see that
|
| 109 |
+
conversion from name to group works.
|
| 110 |
+
"""
|
| 111 |
+
for deg in range(1, 7):
|
| 112 |
+
T, G_name, _ = test_polys_by_deg[deg][0]
|
| 113 |
+
G, _ = galois_group(T)
|
| 114 |
+
assert G == G_name.get_perm_group()
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
def test_galois_group_not_monic_over_ZZ():
|
| 118 |
+
"""
|
| 119 |
+
Check that we can work with polys that are not monic over ZZ.
|
| 120 |
+
"""
|
| 121 |
+
for deg in range(1, 7):
|
| 122 |
+
T, G, alt = test_polys_by_deg[deg][0]
|
| 123 |
+
assert galois_group(T/2, by_name=True) == (G, alt)
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
def test__galois_group_degree_4_root_approx():
|
| 127 |
+
for T, G, alt in test_polys_by_deg[4]:
|
| 128 |
+
assert _galois_group_degree_4_root_approx(Poly(T)) == (G, alt)
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
def test__galois_group_degree_5_hybrid():
|
| 132 |
+
for T, G, alt in test_polys_by_deg[5]:
|
| 133 |
+
assert _galois_group_degree_5_hybrid(Poly(T)) == (G, alt)
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
def test_AlgebraicField_galois_group():
|
| 137 |
+
k = QQ.alg_field_from_poly(Poly(x**4 + 1))
|
| 138 |
+
G, _ = k.galois_group(by_name=True)
|
| 139 |
+
assert G == S4TransitiveSubgroups.V
|
| 140 |
+
|
| 141 |
+
k = QQ.alg_field_from_poly(Poly(x**4 - 2))
|
| 142 |
+
G, _ = k.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import (AlgebraicNumber, I, Rational, oo, pi)
|
| 6 |
+
from sympy.core.power import Pow
|
| 7 |
+
from sympy.core.singleton import S
|
| 8 |
+
from sympy.functions.elementary.exponential import exp
|
| 9 |
+
from sympy.functions.elementary.miscellaneous import (cbrt, sqrt)
|
| 10 |
+
from sympy.functions.elementary.trigonometric import (cos, sin, tan)
|
| 11 |
+
from sympy.polys.polytools import Poly
|
| 12 |
+
from sympy.polys.rootoftools import CRootOf
|
| 13 |
+
from sympy.solvers.solveset import nonlinsolve
|
| 14 |
+
from sympy.geometry import Circle, intersection
|
| 15 |
+
from sympy.testing.pytest import raises, slow
|
| 16 |
+
from sympy.sets.sets import FiniteSet
|
| 17 |
+
from sympy.geometry.point import Point2D
|
| 18 |
+
from sympy.polys.numberfields.minpoly import (
|
| 19 |
+
minimal_polynomial,
|
| 20 |
+
_choose_factor,
|
| 21 |
+
_minpoly_op_algebraic_element,
|
| 22 |
+
_separate_sq,
|
| 23 |
+
_minpoly_groebner,
|
| 24 |
+
)
|
| 25 |
+
from sympy.polys.partfrac import apart
|
| 26 |
+
from sympy.polys.polyerrors import (
|
| 27 |
+
NotAlgebraic,
|
| 28 |
+
GeneratorsError,
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
from sympy.polys.domains import QQ
|
| 32 |
+
from sympy.polys.rootoftools import rootof
|
| 33 |
+
from sympy.polys.polytools import degree
|
| 34 |
+
|
| 35 |
+
from sympy.abc import x, y, z
|
| 36 |
+
|
| 37 |
+
Q = Rational
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def test_minimal_polynomial():
|
| 41 |
+
assert minimal_polynomial(-7, x) == x + 7
|
| 42 |
+
assert minimal_polynomial(-1, x) == x + 1
|
| 43 |
+
assert minimal_polynomial( 0, x) == x
|
| 44 |
+
assert minimal_polynomial( 1, x) == x - 1
|
| 45 |
+
assert minimal_polynomial( 7, x) == x - 7
|
| 46 |
+
|
| 47 |
+
assert minimal_polynomial(sqrt(2), x) == x**2 - 2
|
| 48 |
+
assert minimal_polynomial(sqrt(5), x) == x**2 - 5
|
| 49 |
+
assert minimal_polynomial(sqrt(6), x) == x**2 - 6
|
| 50 |
+
|
| 51 |
+
assert minimal_polynomial(2*sqrt(2), x) == x**2 - 8
|
| 52 |
+
assert minimal_polynomial(3*sqrt(5), x) == x**2 - 45
|
| 53 |
+
assert minimal_polynomial(4*sqrt(6), x) == x**2 - 96
|
| 54 |
+
|
| 55 |
+
assert minimal_polynomial(2*sqrt(2) + 3, x) == x**2 - 6*x + 1
|
| 56 |
+
assert minimal_polynomial(3*sqrt(5) + 6, x) == x**2 - 12*x - 9
|
| 57 |
+
assert minimal_polynomial(4*sqrt(6) + 7, x) == x**2 - 14*x - 47
|
| 58 |
+
|
| 59 |
+
assert minimal_polynomial(2*sqrt(2) - 3, x) == x**2 + 6*x + 1
|
| 60 |
+
assert minimal_polynomial(3*sqrt(5) - 6, x) == x**2 + 12*x - 9
|
| 61 |
+
assert minimal_polynomial(4*sqrt(6) - 7, x) == x**2 + 14*x - 47
|
| 62 |
+
|
| 63 |
+
assert minimal_polynomial(sqrt(1 + sqrt(6)), x) == x**4 - 2*x**2 - 5
|
| 64 |
+
assert minimal_polynomial(sqrt(I + sqrt(6)), x) == x**8 - 10*x**4 + 49
|
| 65 |
+
|
| 66 |
+
assert minimal_polynomial(2*I + sqrt(2 + I), x) == x**4 + 4*x**2 + 8*x + 37
|
| 67 |
+
|
| 68 |
+
assert minimal_polynomial(sqrt(2) + sqrt(3), x) == x**4 - 10*x**2 + 1
|
| 69 |
+
assert minimal_polynomial(
|
| 70 |
+
sqrt(2) + sqrt(3) + sqrt(6), x) == x**4 - 22*x**2 - 48*x - 23
|
| 71 |
+
|
| 72 |
+
a = 1 - 9*sqrt(2) + 7*sqrt(3)
|
| 73 |
+
|
| 74 |
+
assert minimal_polynomial(
|
| 75 |
+
1/a, x) == 392*x**4 - 1232*x**3 + 612*x**2 + 4*x - 1
|
| 76 |
+
assert minimal_polynomial(
|
| 77 |
+
1/sqrt(a), x) == 392*x**8 - 1232*x**6 + 612*x**4 + 4*x**2 - 1
|
| 78 |
+
|
| 79 |
+
raises(NotAlgebraic, lambda: minimal_polynomial(oo, x))
|
| 80 |
+
raises(NotAlgebraic, lambda: minimal_polynomial(2**y, x))
|
| 81 |
+
raises(NotAlgebraic, lambda: minimal_polynomial(sin(1), x))
|
| 82 |
+
|
| 83 |
+
assert minimal_polynomial(sqrt(2)).dummy_eq(x**2 - 2)
|
| 84 |
+
assert minimal_polynomial(sqrt(2), x) == x**2 - 2
|
| 85 |
+
|
| 86 |
+
assert minimal_polynomial(sqrt(2), polys=True) == Poly(x**2 - 2)
|
| 87 |
+
assert minimal_polynomial(sqrt(2), x, polys=True) == Poly(x**2 - 2, domain='QQ')
|
| 88 |
+
assert minimal_polynomial(sqrt(2), x, polys=True, compose=False) == Poly(x**2 - 2, domain='QQ')
|
| 89 |
+
|
| 90 |
+
a = AlgebraicNumber(sqrt(2))
|
| 91 |
+
b = AlgebraicNumber(sqrt(3))
|
| 92 |
+
|
| 93 |
+
assert minimal_polynomial(a, x) == x**2 - 2
|
| 94 |
+
assert minimal_polynomial(b, x) == x**2 - 3
|
| 95 |
+
|
| 96 |
+
assert minimal_polynomial(a, x, polys=True) == Poly(x**2 - 2, domain='QQ')
|
| 97 |
+
assert minimal_polynomial(b, x, polys=True) == Poly(x**2 - 3, domain='QQ')
|
| 98 |
+
|
| 99 |
+
assert minimal_polynomial(sqrt(a/2 + 17), x) == 2*x**4 - 68*x**2 + 577
|
| 100 |
+
assert minimal_polynomial(sqrt(b/2 + 17), x) == 4*x**4 - 136*x**2 + 1153
|
| 101 |
+
|
| 102 |
+
a, b = sqrt(2)/3 + 7, AlgebraicNumber(sqrt(2)/3 + 7)
|
| 103 |
+
|
| 104 |
+
f = 81*x**8 - 2268*x**6 - 4536*x**5 + 22644*x**4 + 63216*x**3 - \
|
| 105 |
+
31608*x**2 - 189648*x + 141358
|
| 106 |
+
|
| 107 |
+
assert minimal_polynomial(sqrt(a) + sqrt(sqrt(a)), x) == f
|
| 108 |
+
assert minimal_polynomial(sqrt(b) + sqrt(sqrt(b)), x) == f
|
| 109 |
+
|
| 110 |
+
assert minimal_polynomial(
|
| 111 |
+
a**Q(3, 2), x) == 729*x**4 - 506898*x**2 + 84604519
|
| 112 |
+
|
| 113 |
+
# issue 5994
|
| 114 |
+
eq = S('''
|
| 115 |
+
-1/(800*sqrt(-1/240 + 1/(18000*(-1/17280000 +
|
| 116 |
+
sqrt(15)*I/28800000)**(1/3)) + 2*(-1/17280000 +
|
| 117 |
+
sqrt(15)*I/28800000)**(1/3)))''')
|
| 118 |
+
assert minimal_polynomial(eq, x) == 8000*x**2 - 1
|
| 119 |
+
|
| 120 |
+
ex = (sqrt(5)*sqrt(I)/(5*sqrt(1 + 125*I))
|
| 121 |
+
+ 25*sqrt(5)/(I**Q(5,2)*(1 + 125*I)**Q(3,2))
|
| 122 |
+
+ 3125*sqrt(5)/(I**Q(11,2)*(1 + 125*I)**Q(3,2))
|
| 123 |
+
+ 5*I*sqrt(1 - I/125))
|
| 124 |
+
mp = minimal_polynomial(ex, x)
|
| 125 |
+
assert mp == 25*x**4 + 5000*x**2 + 250016
|
| 126 |
+
|
| 127 |
+
ex = 1 + sqrt(2) + sqrt(3)
|
| 128 |
+
mp = minimal_polynomial(ex, x)
|
| 129 |
+
assert mp == x**4 - 4*x**3 - 4*x**2 + 16*x - 8
|
| 130 |
+
|
| 131 |
+
ex = 1/(1 + sqrt(2) + sqrt(3))
|
| 132 |
+
mp = minimal_polynomial(ex, x)
|
| 133 |
+
assert mp == 8*x**4 - 16*x**3 + 4*x**2 + 4*x - 1
|
| 134 |
+
|
| 135 |
+
p = (expand((1 + sqrt(2) - 2*sqrt(3) + sqrt(7))**3))**Rational(1, 3)
|
| 136 |
+
mp = minimal_polynomial(p, x)
|
| 137 |
+
assert mp == x**8 - 8*x**7 - 56*x**6 + 448*x**5 + 480*x**4 - 5056*x**3 + 1984*x**2 + 7424*x - 3008
|
| 138 |
+
p = expand((1 + sqrt(2) - 2*sqrt(3) + sqrt(7))**3)
|
| 139 |
+
mp = minimal_polynomial(p, x)
|
| 140 |
+
assert mp == x**8 - 512*x**7 - 118208*x**6 + 31131136*x**5 + 647362560*x**4 - 56026611712*x**3 + 116994310144*x**2 + 404854931456*x - 27216576512
|
| 141 |
+
|
| 142 |
+
assert minimal_polynomial(S("-sqrt(5)/2 - 1/2 + (-sqrt(5)/2 - 1/2)**2"), x) == x - 1
|
| 143 |
+
a = 1 + sqrt(2)
|
| 144 |
+
assert minimal_polynomial((a*sqrt(2) + a)**3, x) == x**2 - 198*x + 1
|
| 145 |
+
|
| 146 |
+
p = 1/(1 + sqrt(2) + sqrt(3))
|
| 147 |
+
assert minimal_polynomial(p, x, compose=False) == 8*x**4 - 16*x**3 + 4*x**2 + 4*x - 1
|
| 148 |
+
|
| 149 |
+
p = 2/(1 + sqrt(2) + sqrt(3))
|
| 150 |
+
assert minimal_polynomial(p, x, compose=False) == x**4 - 4*x**3 + 2*x**2 + 4*x - 2
|
| 151 |
+
|
| 152 |
+
assert minimal_polynomial(1 + sqrt(2)*I, x, compose=False) == x**2 - 2*x + 3
|
| 153 |
+
assert minimal_polynomial(1/(1 + sqrt(2)) + 1, x, compose=False) == x**2 - 2
|
| 154 |
+
assert minimal_polynomial(sqrt(2)*I + I*(1 + sqrt(2)), x,
|
| 155 |
+
compose=False) == x**4 + 18*x**2 + 49
|
| 156 |
+
|
| 157 |
+
# minimal polynomial of I
|
| 158 |
+
assert minimal_polynomial(I, x, domain=QQ.algebraic_field(I)) == x - I
|
| 159 |
+
K = QQ.algebraic_field(I*(sqrt(2) + 1))
|
| 160 |
+
assert minimal_polynomial(I, x, domain=K) == x - I
|
| 161 |
+
assert minimal_polynomial(I, x, domain=QQ) == x**2 + 1
|
| 162 |
+
assert minimal_polynomial(I, x, domain='QQ(y)') == x**2 + 1
|
| 163 |
+
|
| 164 |
+
#issue 11553
|
| 165 |
+
assert minimal_polynomial(GoldenRatio, x) == x**2 - x - 1
|
| 166 |
+
assert minimal_polynomial(TribonacciConstant + 3, x) == x**3 - 10*x**2 + 32*x - 34
|
| 167 |
+
assert minimal_polynomial(GoldenRatio, x, domain=QQ.algebraic_field(sqrt(5))) == \
|
| 168 |
+
2*x - sqrt(5) - 1
|
| 169 |
+
assert minimal_polynomial(TribonacciConstant, x, domain=QQ.algebraic_field(cbrt(19 - 3*sqrt(33)))) == \
|
| 170 |
+
48*x - 19*(19 - 3*sqrt(33))**Rational(2, 3) - 3*sqrt(33)*(19 - 3*sqrt(33))**Rational(2, 3) \
|
| 171 |
+
- 16*(19 - 3*sqrt(33))**Rational(1, 3) - 16
|
| 172 |
+
|
| 173 |
+
# AlgebraicNumber with an alias.
|
| 174 |
+
# Wester H24
|
| 175 |
+
phi = AlgebraicNumber(S.GoldenRatio.expand(func=True), alias='phi')
|
| 176 |
+
assert minimal_polynomial(phi, x) == x**2 - x - 1
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
def test_minimal_polynomial_issue_19732():
|
| 180 |
+
# https://github.com/sympy/sympy/issues/19732
|
| 181 |
+
expr = (-280898097948878450887044002323982963174671632174995451265117559518123750720061943079105185551006003416773064305074191140286225850817291393988597615/(-488144716373031204149459129212782509078221364279079444636386844223983756114492222145074506571622290776245390771587888364089507840000000*sqrt(238368341569)*sqrt(S(11918417078450)/63568729
|
| 182 |
+
- 24411360*sqrt(238368341569)/63568729) +
|
| 183 |
+
238326799225996604451373809274348704114327860564921529846705817404208077866956345381951726531296652901169111729944612727047670549086208000000*sqrt(S(11918417078450)/63568729
|
| 184 |
+
- 24411360*sqrt(238368341569)/63568729)) -
|
| 185 |
+
180561807339168676696180573852937120123827201075968945871075967679148461189459480842956689723484024031016208588658753107/(-59358007109636562851035004992802812513575019937126272896569856090962677491318275291141463850327474176000000*sqrt(238368341569)*sqrt(S(11918417078450)/63568729
|
| 186 |
+
- 24411360*sqrt(238368341569)/63568729) +
|
| 187 |
+
28980348180319251787320809875930301310576055074938369007463004788921613896002936637780993064387310446267596800000*sqrt(S(11918417078450)/63568729
|
| 188 |
+
- 24411360*sqrt(238368341569)/63568729)))
|
| 189 |
+
poly = (2151288870990266634727173620565483054187142169311153766675688628985237817262915166497766867289157986631135400926544697981091151416655364879773546003475813114962656742744975460025956167152918469472166170500512008351638710934022160294849059721218824490226159355197136265032810944357335461128949781377875451881300105989490353140886315677977149440000000000000000000000*x**4
|
| 190 |
+
- 5773274155644072033773937864114266313663195672820501581692669271302387257492905909558846459600429795784309388968498783843631580008547382703258503404023153694528041873101120067477617592651525155101107144042679962433039557235772239171616433004024998230222455940044709064078962397144550855715640331680262171410099614469231080995436488414164502751395405398078353242072696360734131090111239998110773292915337556205692674790561090109440000000000000*x**2
|
| 191 |
+
+ 211295968822207088328287206509522887719741955693091053353263782924470627623790749534705683380138972642560898936171035770539616881000369889020398551821767092685775598633794696371561234818461806577723412581353857653829324364446419444210520602157621008010129702779407422072249192199762604318993590841636967747488049176548615614290254356975376588506729604345612047361483789518445332415765213187893207704958013682516462853001964919444736320672860140355089)
|
| 192 |
+
assert minimal_polynomial(expr, x) == poly
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
def test_minimal_polynomial_hi_prec():
|
| 196 |
+
p = 1/sqrt(1 - 9*sqrt(2) + 7*sqrt(3) + Rational(1, 10)**30)
|
| 197 |
+
mp = minimal_polynomial(p, x)
|
| 198 |
+
# checked with Wolfram Alpha
|
| 199 |
+
assert mp.coeff(x**6) == -1232000000000000000000000000001223999999999999999999999999999987999999999999999999999999999996000000000000000000000000000000
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
def test_minimal_polynomial_sq():
|
| 203 |
+
from sympy.core.add import Add
|
| 204 |
+
from sympy.core.function import expand_multinomial
|
| 205 |
+
p = expand_multinomial((1 + 5*sqrt(2) + 2*sqrt(3))**3)
|
| 206 |
+
mp = minimal_polynomial(p**Rational(1, 3), x)
|
| 207 |
+
assert mp == x**4 - 4*x**3 - 118*x**2 + 244*x + 1321
|
| 208 |
+
p = expand_multinomial((1 + sqrt(2) - 2*sqrt(3) + sqrt(7))**3)
|
| 209 |
+
mp = minimal_polynomial(p**Rational(1, 3), x)
|
| 210 |
+
assert mp == x**8 - 8*x**7 - 56*x**6 + 448*x**5 + 480*x**4 - 5056*x**3 + 1984*x**2 + 7424*x - 3008
|
| 211 |
+
p = Add(*[sqrt(i) for i in range(1, 12)])
|
| 212 |
+
mp = minimal_polynomial(p, x)
|
| 213 |
+
assert mp.subs({x: 0}) == -71965773323122507776
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
def test_minpoly_compose():
|
| 217 |
+
# issue 6868
|
| 218 |
+
eq = S('''
|
| 219 |
+
-1/(800*sqrt(-1/240 + 1/(18000*(-1/17280000 +
|
| 220 |
+
sqrt(15)*I/28800000)**(1/3)) + 2*(-1/17280000 +
|
| 221 |
+
sqrt(15)*I/28800000)**(1/3)))''')
|
| 222 |
+
mp = minimal_polynomial(eq + 3, x)
|
| 223 |
+
assert mp == 8000*x**2 - 48000*x + 71999
|
| 224 |
+
|
| 225 |
+
# issue 5888
|
| 226 |
+
assert minimal_polynomial(exp(I*pi/8), x) == x**8 + 1
|
| 227 |
+
|
| 228 |
+
mp = minimal_polynomial(sin(pi/7) + sqrt(2), x)
|
| 229 |
+
assert mp == 4096*x**12 - 63488*x**10 + 351488*x**8 - 826496*x**6 + \
|
| 230 |
+
770912*x**4 - 268432*x**2 + 28561
|
| 231 |
+
mp = minimal_polynomial(cos(pi/7) + sqrt(2), x)
|
| 232 |
+
assert mp == 64*x**6 - 64*x**5 - 432*x**4 + 304*x**3 + 712*x**2 - \
|
| 233 |
+
232*x - 239
|
| 234 |
+
mp = minimal_polynomial(exp(I*pi/7) + sqrt(2), x)
|
| 235 |
+
assert mp == x**12 - 2*x**11 - 9*x**10 + 16*x**9 + 43*x**8 - 70*x**7 - 97*x**6 + 126*x**5 + 211*x**4 - 212*x**3 - 37*x**2 + 142*x + 127
|
| 236 |
+
|
| 237 |
+
mp = minimal_polynomial(sin(pi/7) + sqrt(2), x)
|
| 238 |
+
assert mp == 4096*x**12 - 63488*x**10 + 351488*x**8 - 826496*x**6 + \
|
| 239 |
+
770912*x**4 - 268432*x**2 + 28561
|
| 240 |
+
mp = minimal_polynomial(cos(pi/7) + sqrt(2), x)
|
| 241 |
+
assert mp == 64*x**6 - 64*x**5 - 432*x**4 + 304*x**3 + 712*x**2 - \
|
| 242 |
+
232*x - 239
|
| 243 |
+
mp = minimal_polynomial(exp(I*pi/7) + sqrt(2), x)
|
| 244 |
+
assert mp == x**12 - 2*x**11 - 9*x**10 + 16*x**9 + 43*x**8 - 70*x**7 - 97*x**6 + 126*x**5 + 211*x**4 - 212*x**3 - 37*x**2 + 142*x + 127
|
| 245 |
+
|
| 246 |
+
mp = minimal_polynomial(exp(I*pi*Rational(2, 7)), x)
|
| 247 |
+
assert mp == x**6 + x**5 + x**4 + x**3 + x**2 + x + 1
|
| 248 |
+
mp = minimal_polynomial(exp(I*pi*Rational(2, 15)), x)
|
| 249 |
+
assert mp == x**8 - x**7 + x**5 - x**4 + x**3 - x + 1
|
| 250 |
+
mp = minimal_polynomial(cos(pi*Rational(2, 7)), x)
|
| 251 |
+
assert mp == 8*x**3 + 4*x**2 - 4*x - 1
|
| 252 |
+
mp = minimal_polynomial(sin(pi*Rational(2, 7)), x)
|
| 253 |
+
ex = (5*cos(pi*Rational(2, 7)) - 7)/(9*cos(pi/7) - 5*cos(pi*Rational(3, 7)))
|
| 254 |
+
mp = minimal_polynomial(ex, x)
|
| 255 |
+
assert mp == x**3 + 2*x**2 - x - 1
|
| 256 |
+
assert minimal_polynomial(-1/(2*cos(pi/7)), x) == x**3 + 2*x**2 - x - 1
|
| 257 |
+
assert minimal_polynomial(sin(pi*Rational(2, 15)), x) == \
|
| 258 |
+
256*x**8 - 448*x**6 + 224*x**4 - 32*x**2 + 1
|
| 259 |
+
assert minimal_polynomial(sin(pi*Rational(5, 14)), x) == 8*x**3 - 4*x**2 - 4*x + 1
|
| 260 |
+
assert minimal_polynomial(cos(pi/15), x) == 16*x**4 + 8*x**3 - 16*x**2 - 8*x + 1
|
| 261 |
+
|
| 262 |
+
ex = rootof(x**3 +x*4 + 1, 0)
|
| 263 |
+
mp = minimal_polynomial(ex, x)
|
| 264 |
+
assert mp == x**3 + 4*x + 1
|
| 265 |
+
mp = minimal_polynomial(ex + 1, x)
|
| 266 |
+
assert mp == x**3 - 3*x**2 + 7*x - 4
|
| 267 |
+
assert minimal_polynomial(exp(I*pi/3), x) == x**2 - x + 1
|
| 268 |
+
assert minimal_polynomial(exp(I*pi/4), x) == x**4 + 1
|
| 269 |
+
assert minimal_polynomial(exp(I*pi/6), x) == x**4 - x**2 + 1
|
| 270 |
+
assert minimal_polynomial(exp(I*pi/9), x) == x**6 - x**3 + 1
|
| 271 |
+
assert minimal_polynomial(exp(I*pi/10), x) == x**8 - x**6 + x**4 - x**2 + 1
|
| 272 |
+
assert minimal_polynomial(sin(pi/9), x) == 64*x**6 - 96*x**4 + 36*x**2 - 3
|
| 273 |
+
assert minimal_polynomial(sin(pi/11), x) == 1024*x**10 - 2816*x**8 + \
|
| 274 |
+
2816*x**6 - 1232*x**4 + 220*x**2 - 11
|
| 275 |
+
assert minimal_polynomial(sin(pi/21), x) == 4096*x**12 - 11264*x**10 + \
|
| 276 |
+
11264*x**8 - 4992*x**6 + 960*x**4 - 64*x**2 + 1
|
| 277 |
+
assert minimal_polynomial(cos(pi/9), x) == 8*x**3 - 6*x - 1
|
| 278 |
+
|
| 279 |
+
ex = 2**Rational(1, 3)*exp(2*I*pi/3)
|
| 280 |
+
assert minimal_polynomial(ex, x) == x**3 - 2
|
| 281 |
+
|
| 282 |
+
raises(NotAlgebraic, lambda: minimal_polynomial(cos(pi*sqrt(2)), x))
|
| 283 |
+
raises(NotAlgebraic, lambda: minimal_polynomial(sin(pi*sqrt(2)), x))
|
| 284 |
+
raises(NotAlgebraic, lambda: minimal_polynomial(exp(1.618*I*pi), x))
|
| 285 |
+
raises(NotAlgebraic, lambda: minimal_polynomial(exp(I*pi*sqrt(2)), x))
|
| 286 |
+
|
| 287 |
+
# issue 5934
|
| 288 |
+
ex = 1/(-36000 - 7200*sqrt(5) + (12*sqrt(10)*sqrt(sqrt(5) + 5) +
|
| 289 |
+
24*sqrt(10)*sqrt(-sqrt(5) + 5))**2) + 1
|
| 290 |
+
raises(ZeroDivisionError, lambda: minimal_polynomial(ex, x))
|
| 291 |
+
|
| 292 |
+
ex = sqrt(1 + 2**Rational(1,3)) + sqrt(1 + 2**Rational(1,4)) + sqrt(2)
|
| 293 |
+
mp = minimal_polynomial(ex, x)
|
| 294 |
+
assert degree(mp) == 48 and mp.subs({x:0}) == -16630256576
|
| 295 |
+
|
| 296 |
+
ex = tan(pi/5, evaluate=False)
|
| 297 |
+
mp = minimal_polynomial(ex, x)
|
| 298 |
+
assert mp == x**4 - 10*x**2 + 5
|
| 299 |
+
assert mp.subs(x, tan(pi/5)).is_zero
|
| 300 |
+
|
| 301 |
+
ex = tan(pi/6, evaluate=False)
|
| 302 |
+
mp = minimal_polynomial(ex, x)
|
| 303 |
+
assert mp == 3*x**2 - 1
|
| 304 |
+
assert mp.subs(x, tan(pi/6)).is_zero
|
| 305 |
+
|
| 306 |
+
ex = tan(pi/10, evaluate=False)
|
| 307 |
+
mp = minimal_polynomial(ex, x)
|
| 308 |
+
assert mp == 5*x**4 - 10*x**2 + 1
|
| 309 |
+
assert mp.subs(x, tan(pi/10)).is_zero
|
| 310 |
+
|
| 311 |
+
raises(NotAlgebraic, lambda: minimal_polynomial(tan(pi*sqrt(2)), x))
|
| 312 |
+
|
| 313 |
+
|
| 314 |
+
def test_minpoly_issue_7113():
|
| 315 |
+
# see discussion in https://github.com/sympy/sympy/pull/2234
|
| 316 |
+
from sympy.simplify.simplify import nsimplify
|
| 317 |
+
r = nsimplify(pi, tolerance=0.000000001)
|
| 318 |
+
mp = minimal_polynomial(r, x)
|
| 319 |
+
assert mp == 1768292677839237920489538677417507171630859375*x**109 - \
|
| 320 |
+
2734577732179183863586489182929671773182898498218854181690460140337930774573792597743853652058046464
|
| 321 |
+
|
| 322 |
+
|
| 323 |
+
def test_minpoly_issue_23677():
|
| 324 |
+
r1 = CRootOf(4000000*x**3 - 239960000*x**2 + 4782399900*x - 31663998001, 0)
|
| 325 |
+
r2 = CRootOf(4000000*x**3 - 239960000*x**2 + 4782399900*x - 31663998001, 1)
|
| 326 |
+
num = (7680000000000000000*r1**4*r2**4 - 614323200000000000000*r1**4*r2**3
|
| 327 |
+
+ 18458112576000000000000*r1**4*r2**2 - 246896663036160000000000*r1**4*r2
|
| 328 |
+
+ 1240473830323209600000000*r1**4 - 614323200000000000000*r1**3*r2**4
|
| 329 |
+
- 1476464424954240000000000*r1**3*r2**2 - 99225501687553535904000000*r1**3
|
| 330 |
+
+ 18458112576000000000000*r1**2*r2**4 - 1476464424954240000000000*r1**2*r2**3
|
| 331 |
+
- 593391458458356671712000000*r1**2*r2 + 2981354896834339226880720000*r1**2
|
| 332 |
+
- 246896663036160000000000*r1*r2**4 - 593391458458356671712000000*r1*r2**2
|
| 333 |
+
- 39878756418031796275267195200*r1 + 1240473830323209600000000*r2**4
|
| 334 |
+
- 99225501687553535904000000*r2**3 + 2981354896834339226880720000*r2**2 -
|
| 335 |
+
39878756418031796275267195200*r2 + 200361370275616536577343808012)
|
| 336 |
+
mp = (x**3 + 59426520028417434406408556687919*x**2 +
|
| 337 |
+
1161475464966574421163316896737773190861975156439163671112508400*x +
|
| 338 |
+
7467465541178623874454517208254940823818304424383315270991298807299003671748074773558707779600)
|
| 339 |
+
assert minimal_polynomial(num, x) == mp
|
| 340 |
+
|
| 341 |
+
|
| 342 |
+
def test_minpoly_issue_7574():
|
| 343 |
+
ex = -(-1)**Rational(1, 3) + (-1)**Rational(2,3)
|
| 344 |
+
assert minimal_polynomial(ex, x) == x + 1
|
| 345 |
+
|
| 346 |
+
|
| 347 |
+
def test_choose_factor():
|
| 348 |
+
# Test that this does not enter an infinite loop:
|
| 349 |
+
bad_factors = [Poly(x-2, x), Poly(x+2, x)]
|
| 350 |
+
raises(NotImplementedError, lambda: _choose_factor(bad_factors, x, sqrt(3)))
|
| 351 |
+
|
| 352 |
+
|
| 353 |
+
def test_minpoly_fraction_field():
|
| 354 |
+
assert minimal_polynomial(1/x, y) == -x*y + 1
|
| 355 |
+
assert minimal_polynomial(1 / (x + 1), y) == (x + 1)*y - 1
|
| 356 |
+
|
| 357 |
+
assert minimal_polynomial(sqrt(x), y) == y**2 - x
|
| 358 |
+
assert minimal_polynomial(sqrt(x + 1), y) == y**2 - x - 1
|
| 359 |
+
assert minimal_polynomial(sqrt(x) / x, y) == x*y**2 - 1
|
| 360 |
+
assert minimal_polynomial(sqrt(2) * sqrt(x), y) == y**2 - 2 * x
|
| 361 |
+
assert minimal_polynomial(sqrt(2) + sqrt(x), y) == \
|
| 362 |
+
y**4 + (-2*x - 4)*y**2 + x**2 - 4*x + 4
|
| 363 |
+
|
| 364 |
+
assert minimal_polynomial(x**Rational(1,3), y) == y**3 - x
|
| 365 |
+
assert minimal_polynomial(x**Rational(1,3) + sqrt(x), y) == \
|
| 366 |
+
y**6 - 3*x*y**4 - 2*x*y**3 + 3*x**2*y**2 - 6*x**2*y - x**3 + x**2
|
| 367 |
+
|
| 368 |
+
assert minimal_polynomial(sqrt(x) / z, y) == z**2*y**2 - x
|
| 369 |
+
assert minimal_polynomial(sqrt(x) / (z + 1), y) == (z**2 + 2*z + 1)*y**2 - x
|
| 370 |
+
|
| 371 |
+
assert minimal_polynomial(1/x, y, polys=True) == Poly(-x*y + 1, y, domain='ZZ(x)')
|
| 372 |
+
assert minimal_polynomial(1 / (x + 1), y, polys=True) == \
|
| 373 |
+
Poly((x + 1)*y - 1, y, domain='ZZ(x)')
|
| 374 |
+
assert minimal_polynomial(sqrt(x), y, polys=True) == Poly(y**2 - x, y, domain='ZZ(x)')
|
| 375 |
+
assert minimal_polynomial(sqrt(x) / z, y, polys=True) == \
|
| 376 |
+
Poly(z**2*y**2 - x, y, domain='ZZ(x, z)')
|
| 377 |
+
|
| 378 |
+
# this is (sqrt(1 + x**3)/x).integrate(x).diff(x) - sqrt(1 + x**3)/x
|
| 379 |
+
a = sqrt(x)/sqrt(1 + x**(-3)) - sqrt(x**3 + 1)/x + 1/(x**Rational(5, 2)* \
|
| 380 |
+
(1 + x**(-3))**Rational(3, 2)) + 1/(x**Rational(11, 2)*(1 + x**(-3))**Rational(3, 2))
|
| 381 |
+
|
| 382 |
+
assert minimal_polynomial(a, y) == y
|
| 383 |
+
|
| 384 |
+
raises(NotAlgebraic, lambda: minimal_polynomial(exp(x), y))
|
| 385 |
+
raises(GeneratorsError, lambda: minimal_polynomial(sqrt(x), x))
|
| 386 |
+
raises(GeneratorsError, lambda: minimal_polynomial(sqrt(x) - y, x))
|
| 387 |
+
raises(NotImplementedError, lambda: minimal_polynomial(sqrt(x), y, compose=False))
|
| 388 |
+
|
| 389 |
+
@slow
|
| 390 |
+
def test_minpoly_fraction_field_slow():
|
| 391 |
+
assert minimal_polynomial(minimal_polynomial(sqrt(x**Rational(1,5) - 1),
|
| 392 |
+
y).subs(y, sqrt(x**Rational(1,5) - 1)), z) == z
|
| 393 |
+
|
| 394 |
+
def test_minpoly_domain():
|
| 395 |
+
assert minimal_polynomial(sqrt(2), x, domain=QQ.algebraic_field(sqrt(2))) == \
|
| 396 |
+
x - sqrt(2)
|
| 397 |
+
assert minimal_polynomial(sqrt(8), x, domain=QQ.algebraic_field(sqrt(2))) == \
|
| 398 |
+
x - 2*sqrt(2)
|
| 399 |
+
assert minimal_polynomial(sqrt(Rational(3,2)), x,
|
| 400 |
+
domain=QQ.algebraic_field(sqrt(2))) == 2*x**2 - 3
|
| 401 |
+
|
| 402 |
+
raises(NotAlgebraic, lambda: minimal_polynomial(y, x, domain=QQ))
|
| 403 |
+
|
| 404 |
+
|
| 405 |
+
def test_issue_14831():
|
| 406 |
+
a = -2*sqrt(2)*sqrt(12*sqrt(2) + 17)
|
| 407 |
+
assert minimal_polynomial(a, x) == x**2 + 16*x - 8
|
| 408 |
+
e = (-3*sqrt(12*sqrt(2) + 17) + 12*sqrt(2) +
|
| 409 |
+
17 - 2*sqrt(2)*sqrt(12*sqrt(2) + 17))
|
| 410 |
+
assert minimal_polynomial(e, x) == x
|
| 411 |
+
|
| 412 |
+
|
| 413 |
+
def test_issue_18248():
|
| 414 |
+
assert nonlinsolve([x*y**3-sqrt(2)/3, x*y**6-4/(9*(sqrt(3)))],x,y) == \
|
| 415 |
+
FiniteSet((sqrt(3)/2, sqrt(6)/3), (sqrt(3)/2, -sqrt(6)/6 - sqrt(2)*I/2),
|
| 416 |
+
(sqrt(3)/2, -sqrt(6)/6 + sqrt(2)*I/2))
|
| 417 |
+
|
| 418 |
+
|
| 419 |
+
def test_issue_13230():
|
| 420 |
+
c1 = Circle(Point2D(3, sqrt(5)), 5)
|
| 421 |
+
c2 = Circle(Point2D(4, sqrt(7)), 6)
|
| 422 |
+
assert intersection(c1, c2) == [Point2D(-1 + (-sqrt(7) + sqrt(5))*(-2*sqrt(7)/29
|
| 423 |
+
+ 9*sqrt(5)/29 + sqrt(196*sqrt(35) + 1941)/29), -2*sqrt(7)/29 + 9*sqrt(5)/29
|
| 424 |
+
+ sqrt(196*sqrt(35) + 1941)/29), Point2D(-1 + (-sqrt(7) + sqrt(5))*(-sqrt(196*sqrt(35)
|
| 425 |
+
+ 1941)/29 - 2*sqrt(7)/29 + 9*sqrt(5)/29), -sqrt(196*sqrt(35) + 1941)/29 - 2*sqrt(7)/29 + 9*sqrt(5)/29)]
|
| 426 |
+
|
| 427 |
+
def test_issue_19760():
|
| 428 |
+
e = 1/(sqrt(1 + sqrt(2)) - sqrt(2)*sqrt(1 + sqrt(2))) + 1
|
| 429 |
+
mp_expected = x**4 - 4*x**3 + 4*x**2 - 2
|
| 430 |
+
|
| 431 |
+
for comp in (True, False):
|
| 432 |
+
mp = Poly(minimal_polynomial(e, compose=comp))
|
| 433 |
+
assert mp(x) == mp_expected, "minimal_polynomial(e, compose=%s) = %s; %s expected" % (comp, mp(x), mp_expected)
|
| 434 |
+
|
| 435 |
+
|
| 436 |
+
def test_issue_20163():
|
| 437 |
+
assert apart(1/(x**6+1), extension=[sqrt(3), I]) == \
|
| 438 |
+
(sqrt(3) + I)/(2*x + sqrt(3) + I)/6 + \
|
| 439 |
+
(sqrt(3) - I)/(2*x + sqrt(3) - I)/6 - \
|
| 440 |
+
(sqrt(3) - I)/(2*x - sqrt(3) + I)/6 - \
|
| 441 |
+
(sqrt(3) + I)/(2*x - sqrt(3) - I)/6 + \
|
| 442 |
+
I/(x + I)/6 - I/(x - I)/6
|
| 443 |
+
|
| 444 |
+
|
| 445 |
+
def test_issue_22559():
|
| 446 |
+
alpha = AlgebraicNumber(sqrt(2))
|
| 447 |
+
assert minimal_polynomial(alpha**3, x) == x**2 - 8
|
| 448 |
+
|
| 449 |
+
|
| 450 |
+
def test_issue_22561():
|
| 451 |
+
a = AlgebraicNumber(sqrt(2) + sqrt(3), [S(1) / 2, 0, S(-9) / 2, 0], gen=x)
|
| 452 |
+
assert a.as_expr() == sqrt(2)
|
| 453 |
+
assert minimal_polynomial(a, x) == x**2 - 2
|
| 454 |
+
assert minimal_polynomial(a**3, x) == x**2 - 8
|
| 455 |
+
|
| 456 |
+
|
| 457 |
+
def test_separate_sq_not_impl():
|
| 458 |
+
raises(NotImplementedError, lambda: _separate_sq(x**(S(1)/3) + x))
|
| 459 |
+
|
| 460 |
+
|
| 461 |
+
def test_minpoly_op_algebraic_element_not_impl():
|
| 462 |
+
raises(NotImplementedError,
|
| 463 |
+
lambda: _minpoly_op_algebraic_element(Pow, sqrt(2), sqrt(3), x, QQ))
|
| 464 |
+
|
| 465 |
+
|
| 466 |
+
def test_minpoly_groebner():
|
| 467 |
+
assert _minpoly_groebner(S(2)/3, x, Poly) == 3*x - 2
|
| 468 |
+
assert _minpoly_groebner(
|
| 469 |
+
(sqrt(2) + 3)*(sqrt(2) + 1), x, Poly) == x**2 - 10*x - 7
|
| 470 |
+
assert _minpoly_groebner((sqrt(2) + 3)**(S(1)/3)*(sqrt(2) + 1)**(S(1)/3),
|
| 471 |
+
x, Poly) == x**6 - 10*x**3 - 7
|
| 472 |
+
assert _minpoly_groebner((sqrt(2) + 3)**(-S(1)/3)*(sqrt(2) + 1)**(S(1)/3),
|
| 473 |
+
x, Poly) == 7*x**6 - 2*x**3 - 1
|
| 474 |
+
raises(NotAlgebraic, lambda: _minpoly_groebner(pi**2, x, Poly))
|
pllava/lib/python3.10/site-packages/sympy/polys/numberfields/tests/test_numbers.py
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests on algebraic numbers. """
|
| 2 |
+
|
| 3 |
+
from sympy.core.containers import Tuple
|
| 4 |
+
from sympy.core.numbers import (AlgebraicNumber, I, Rational)
|
| 5 |
+
from sympy.core.singleton import S
|
| 6 |
+
from sympy.core.symbol import Symbol
|
| 7 |
+
from sympy.functions.elementary.miscellaneous import sqrt
|
| 8 |
+
from sympy.polys.polytools import Poly
|
| 9 |
+
from sympy.polys.numberfields.subfield import to_number_field
|
| 10 |
+
from sympy.polys.polyclasses import DMP
|
| 11 |
+
from sympy.polys.domains import QQ
|
| 12 |
+
from sympy.polys.rootoftools import CRootOf
|
| 13 |
+
from sympy.abc import x, y
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def test_AlgebraicNumber():
|
| 17 |
+
minpoly, root = x**2 - 2, sqrt(2)
|
| 18 |
+
|
| 19 |
+
a = AlgebraicNumber(root, gen=x)
|
| 20 |
+
|
| 21 |
+
assert a.rep == DMP([QQ(1), QQ(0)], QQ)
|
| 22 |
+
assert a.root == root
|
| 23 |
+
assert a.alias is None
|
| 24 |
+
assert a.minpoly == minpoly
|
| 25 |
+
assert a.is_number
|
| 26 |
+
|
| 27 |
+
assert a.is_aliased is False
|
| 28 |
+
|
| 29 |
+
assert a.coeffs() == [S.One, S.Zero]
|
| 30 |
+
assert a.native_coeffs() == [QQ(1), QQ(0)]
|
| 31 |
+
|
| 32 |
+
a = AlgebraicNumber(root, gen=x, alias='y')
|
| 33 |
+
|
| 34 |
+
assert a.rep == DMP([QQ(1), QQ(0)], QQ)
|
| 35 |
+
assert a.root == root
|
| 36 |
+
assert a.alias == Symbol('y')
|
| 37 |
+
assert a.minpoly == minpoly
|
| 38 |
+
assert a.is_number
|
| 39 |
+
|
| 40 |
+
assert a.is_aliased is True
|
| 41 |
+
|
| 42 |
+
a = AlgebraicNumber(root, gen=x, alias=Symbol('y'))
|
| 43 |
+
|
| 44 |
+
assert a.rep == DMP([QQ(1), QQ(0)], QQ)
|
| 45 |
+
assert a.root == root
|
| 46 |
+
assert a.alias == Symbol('y')
|
| 47 |
+
assert a.minpoly == minpoly
|
| 48 |
+
assert a.is_number
|
| 49 |
+
|
| 50 |
+
assert a.is_aliased is True
|
| 51 |
+
|
| 52 |
+
assert AlgebraicNumber(sqrt(2), []).rep == DMP([], QQ)
|
| 53 |
+
assert AlgebraicNumber(sqrt(2), ()).rep == DMP([], QQ)
|
| 54 |
+
assert AlgebraicNumber(sqrt(2), (0, 0)).rep == DMP([], QQ)
|
| 55 |
+
|
| 56 |
+
assert AlgebraicNumber(sqrt(2), [8]).rep == DMP([QQ(8)], QQ)
|
| 57 |
+
assert AlgebraicNumber(sqrt(2), [Rational(8, 3)]).rep == DMP([QQ(8, 3)], QQ)
|
| 58 |
+
|
| 59 |
+
assert AlgebraicNumber(sqrt(2), [7, 3]).rep == DMP([QQ(7), QQ(3)], QQ)
|
| 60 |
+
assert AlgebraicNumber(
|
| 61 |
+
sqrt(2), [Rational(7, 9), Rational(3, 2)]).rep == DMP([QQ(7, 9), QQ(3, 2)], QQ)
|
| 62 |
+
|
| 63 |
+
assert AlgebraicNumber(sqrt(2), [1, 2, 3]).rep == DMP([QQ(2), QQ(5)], QQ)
|
| 64 |
+
|
| 65 |
+
a = AlgebraicNumber(AlgebraicNumber(root, gen=x), [1, 2])
|
| 66 |
+
|
| 67 |
+
assert a.rep == DMP([QQ(1), QQ(2)], QQ)
|
| 68 |
+
assert a.root == root
|
| 69 |
+
assert a.alias is None
|
| 70 |
+
assert a.minpoly == minpoly
|
| 71 |
+
assert a.is_number
|
| 72 |
+
|
| 73 |
+
assert a.is_aliased is False
|
| 74 |
+
|
| 75 |
+
assert a.coeffs() == [S.One, S(2)]
|
| 76 |
+
assert a.native_coeffs() == [QQ(1), QQ(2)]
|
| 77 |
+
|
| 78 |
+
a = AlgebraicNumber((minpoly, root), [1, 2])
|
| 79 |
+
|
| 80 |
+
assert a.rep == DMP([QQ(1), QQ(2)], QQ)
|
| 81 |
+
assert a.root == root
|
| 82 |
+
assert a.alias is None
|
| 83 |
+
assert a.minpoly == minpoly
|
| 84 |
+
assert a.is_number
|
| 85 |
+
|
| 86 |
+
assert a.is_aliased is False
|
| 87 |
+
|
| 88 |
+
a = AlgebraicNumber((Poly(minpoly), root), [1, 2])
|
| 89 |
+
|
| 90 |
+
assert a.rep == DMP([QQ(1), QQ(2)], QQ)
|
| 91 |
+
assert a.root == root
|
| 92 |
+
assert a.alias is None
|
| 93 |
+
assert a.minpoly == minpoly
|
| 94 |
+
assert a.is_number
|
| 95 |
+
|
| 96 |
+
assert a.is_aliased is False
|
| 97 |
+
|
| 98 |
+
assert AlgebraicNumber( sqrt(3)).rep == DMP([ QQ(1), QQ(0)], QQ)
|
| 99 |
+
assert AlgebraicNumber(-sqrt(3)).rep == DMP([ QQ(1), QQ(0)], QQ)
|
| 100 |
+
|
| 101 |
+
a = AlgebraicNumber(sqrt(2))
|
| 102 |
+
b = AlgebraicNumber(sqrt(2))
|
| 103 |
+
|
| 104 |
+
assert a == b
|
| 105 |
+
|
| 106 |
+
c = AlgebraicNumber(sqrt(2), gen=x)
|
| 107 |
+
|
| 108 |
+
assert a == b
|
| 109 |
+
assert a == c
|
| 110 |
+
|
| 111 |
+
a = AlgebraicNumber(sqrt(2), [1, 2])
|
| 112 |
+
b = AlgebraicNumber(sqrt(2), [1, 3])
|
| 113 |
+
|
| 114 |
+
assert a != b and a != sqrt(2) + 3
|
| 115 |
+
|
| 116 |
+
assert (a == x) is False and (a != x) is True
|
| 117 |
+
|
| 118 |
+
a = AlgebraicNumber(sqrt(2), [1, 0])
|
| 119 |
+
b = AlgebraicNumber(sqrt(2), [1, 0], alias=y)
|
| 120 |
+
|
| 121 |
+
assert a.as_poly(x) == Poly(x, domain='QQ')
|
| 122 |
+
assert b.as_poly() == Poly(y, domain='QQ')
|
| 123 |
+
|
| 124 |
+
assert a.as_expr() == sqrt(2)
|
| 125 |
+
assert a.as_expr(x) == x
|
| 126 |
+
assert b.as_expr() == sqrt(2)
|
| 127 |
+
assert b.as_expr(x) == x
|
| 128 |
+
|
| 129 |
+
a = AlgebraicNumber(sqrt(2), [2, 3])
|
| 130 |
+
b = AlgebraicNumber(sqrt(2), [2, 3], alias=y)
|
| 131 |
+
|
| 132 |
+
p = a.as_poly()
|
| 133 |
+
|
| 134 |
+
assert p == Poly(2*p.gen + 3)
|
| 135 |
+
|
| 136 |
+
assert a.as_poly(x) == Poly(2*x + 3, domain='QQ')
|
| 137 |
+
assert b.as_poly() == Poly(2*y + 3, domain='QQ')
|
| 138 |
+
|
| 139 |
+
assert a.as_expr() == 2*sqrt(2) + 3
|
| 140 |
+
assert a.as_expr(x) == 2*x + 3
|
| 141 |
+
assert b.as_expr() == 2*sqrt(2) + 3
|
| 142 |
+
assert b.as_expr(x) == 2*x + 3
|
| 143 |
+
|
| 144 |
+
a = AlgebraicNumber(sqrt(2))
|
| 145 |
+
b = to_number_field(sqrt(2))
|
| 146 |
+
assert a.args == b.args == (sqrt(2), Tuple(1, 0))
|
| 147 |
+
b = AlgebraicNumber(sqrt(2), alias='alpha')
|
| 148 |
+
assert b.args == (sqrt(2), Tuple(1, 0), Symbol('alpha'))
|
| 149 |
+
|
| 150 |
+
a = AlgebraicNumber(sqrt(2), [1, 2, 3])
|
| 151 |
+
assert a.args == (sqrt(2), Tuple(1, 2, 3))
|
| 152 |
+
|
| 153 |
+
a = AlgebraicNumber(sqrt(2), [1, 2], "alpha")
|
| 154 |
+
b = AlgebraicNumber(a)
|
| 155 |
+
c = AlgebraicNumber(a, alias="gamma")
|
| 156 |
+
assert a == b
|
| 157 |
+
assert c.alias.name == "gamma"
|
| 158 |
+
|
| 159 |
+
a = AlgebraicNumber(sqrt(2) + sqrt(3), [S(1)/2, 0, S(-9)/2, 0])
|
| 160 |
+
b = AlgebraicNumber(a, [1, 0, 0])
|
| 161 |
+
assert b.root == a.root
|
| 162 |
+
assert a.to_root() == sqrt(2)
|
| 163 |
+
assert b.to_root() == 2
|
| 164 |
+
|
| 165 |
+
a = AlgebraicNumber(2)
|
| 166 |
+
assert a.is_primitive_element is True
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
def test_to_algebraic_integer():
|
| 170 |
+
a = AlgebraicNumber(sqrt(3), gen=x).to_algebraic_integer()
|
| 171 |
+
|
| 172 |
+
assert a.minpoly == x**2 - 3
|
| 173 |
+
assert a.root == sqrt(3)
|
| 174 |
+
assert a.rep == DMP([QQ(1), QQ(0)], QQ)
|
| 175 |
+
|
| 176 |
+
a = AlgebraicNumber(2*sqrt(3), gen=x).to_algebraic_integer()
|
| 177 |
+
assert a.minpoly == x**2 - 12
|
| 178 |
+
assert a.root == 2*sqrt(3)
|
| 179 |
+
assert a.rep == DMP([QQ(1), QQ(0)], QQ)
|
| 180 |
+
|
| 181 |
+
a = AlgebraicNumber(sqrt(3)/2, gen=x).to_algebraic_integer()
|
| 182 |
+
|
| 183 |
+
assert a.minpoly == x**2 - 12
|
| 184 |
+
assert a.root == 2*sqrt(3)
|
| 185 |
+
assert a.rep == DMP([QQ(1), QQ(0)], QQ)
|
| 186 |
+
|
| 187 |
+
a = AlgebraicNumber(sqrt(3)/2, [Rational(7, 19), 3], gen=x).to_algebraic_integer()
|
| 188 |
+
|
| 189 |
+
assert a.minpoly == x**2 - 12
|
| 190 |
+
assert a.root == 2*sqrt(3)
|
| 191 |
+
assert a.rep == DMP([QQ(7, 19), QQ(3)], QQ)
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
def test_AlgebraicNumber_to_root():
|
| 195 |
+
assert AlgebraicNumber(sqrt(2)).to_root() == sqrt(2)
|
| 196 |
+
|
| 197 |
+
zeta5_squared = AlgebraicNumber(CRootOf(x**5 - 1, 4), coeffs=[1, 0, 0])
|
| 198 |
+
assert zeta5_squared.to_root() == CRootOf(x**4 + x**3 + x**2 + x + 1, 1)
|
| 199 |
+
|
| 200 |
+
zeta3_squared = AlgebraicNumber(CRootOf(x**3 - 1, 2), coeffs=[1, 0, 0])
|
| 201 |
+
assert zeta3_squared.to_root() == -S(1)/2 - sqrt(3)*I/2
|
| 202 |
+
assert zeta3_squared.to_root(radicals=False) == CRootOf(x**2 + x + 1, 0)
|
pllava/lib/python3.10/site-packages/sympy/polys/numberfields/tests/test_primes.py
ADDED
|
@@ -0,0 +1,296 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from math import prod
|
| 2 |
+
|
| 3 |
+
from sympy import QQ, ZZ
|
| 4 |
+
from sympy.abc import x, theta
|
| 5 |
+
from sympy.ntheory import factorint
|
| 6 |
+
from sympy.ntheory.residue_ntheory import n_order
|
| 7 |
+
from sympy.polys import Poly, cyclotomic_poly
|
| 8 |
+
from sympy.polys.matrices import DomainMatrix
|
| 9 |
+
from sympy.polys.numberfields.basis import round_two
|
| 10 |
+
from sympy.polys.numberfields.exceptions import StructureError
|
| 11 |
+
from sympy.polys.numberfields.modules import PowerBasis, to_col
|
| 12 |
+
from sympy.polys.numberfields.primes import (
|
| 13 |
+
prime_decomp, _two_elt_rep,
|
| 14 |
+
_check_formal_conditions_for_maximal_order,
|
| 15 |
+
)
|
| 16 |
+
from sympy.testing.pytest import raises
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def test_check_formal_conditions_for_maximal_order():
|
| 20 |
+
T = Poly(cyclotomic_poly(5, x))
|
| 21 |
+
A = PowerBasis(T)
|
| 22 |
+
B = A.submodule_from_matrix(2 * DomainMatrix.eye(4, ZZ))
|
| 23 |
+
C = B.submodule_from_matrix(3 * DomainMatrix.eye(4, ZZ))
|
| 24 |
+
D = A.submodule_from_matrix(DomainMatrix.eye(4, ZZ)[:, :-1])
|
| 25 |
+
# Is a direct submodule of a power basis, but lacks 1 as first generator:
|
| 26 |
+
raises(StructureError, lambda: _check_formal_conditions_for_maximal_order(B))
|
| 27 |
+
# Is not a direct submodule of a power basis:
|
| 28 |
+
raises(StructureError, lambda: _check_formal_conditions_for_maximal_order(C))
|
| 29 |
+
# Is direct submod of pow basis, and starts with 1, but not sq/max rank/HNF:
|
| 30 |
+
raises(StructureError, lambda: _check_formal_conditions_for_maximal_order(D))
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def test_two_elt_rep():
|
| 34 |
+
ell = 7
|
| 35 |
+
T = Poly(cyclotomic_poly(ell))
|
| 36 |
+
ZK, dK = round_two(T)
|
| 37 |
+
for p in [29, 13, 11, 5]:
|
| 38 |
+
P = prime_decomp(p, T)
|
| 39 |
+
for Pi in P:
|
| 40 |
+
# We have Pi in two-element representation, and, because we are
|
| 41 |
+
# looking at a cyclotomic field, this was computed by the "easy"
|
| 42 |
+
# method that just factors T mod p. We will now convert this to
|
| 43 |
+
# a set of Z-generators, then convert that back into a two-element
|
| 44 |
+
# rep. The latter need not be identical to the two-elt rep we
|
| 45 |
+
# already have, but it must have the same HNF.
|
| 46 |
+
H = p*ZK + Pi.alpha*ZK
|
| 47 |
+
gens = H.basis_element_pullbacks()
|
| 48 |
+
# Note: we could supply f = Pi.f, but prefer to test behavior without it.
|
| 49 |
+
b = _two_elt_rep(gens, ZK, p)
|
| 50 |
+
if b != Pi.alpha:
|
| 51 |
+
H2 = p*ZK + b*ZK
|
| 52 |
+
assert H2 == H
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def test_valuation_at_prime_ideal():
|
| 56 |
+
p = 7
|
| 57 |
+
T = Poly(cyclotomic_poly(p))
|
| 58 |
+
ZK, dK = round_two(T)
|
| 59 |
+
P = prime_decomp(p, T, dK=dK, ZK=ZK)
|
| 60 |
+
assert len(P) == 1
|
| 61 |
+
P0 = P[0]
|
| 62 |
+
v = P0.valuation(p*ZK)
|
| 63 |
+
assert v == P0.e
|
| 64 |
+
# Test easy 0 case:
|
| 65 |
+
assert P0.valuation(5*ZK) == 0
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def test_decomp_1():
|
| 69 |
+
# All prime decompositions in cyclotomic fields are in the "easy case,"
|
| 70 |
+
# since the index is unity.
|
| 71 |
+
# Here we check the ramified prime.
|
| 72 |
+
T = Poly(cyclotomic_poly(7))
|
| 73 |
+
raises(ValueError, lambda: prime_decomp(7))
|
| 74 |
+
P = prime_decomp(7, T)
|
| 75 |
+
assert len(P) == 1
|
| 76 |
+
P0 = P[0]
|
| 77 |
+
assert P0.e == 6
|
| 78 |
+
assert P0.f == 1
|
| 79 |
+
# Test powers:
|
| 80 |
+
assert P0**0 == P0.ZK
|
| 81 |
+
assert P0**1 == P0
|
| 82 |
+
assert P0**6 == 7 * P0.ZK
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def test_decomp_2():
|
| 86 |
+
# More easy cyclotomic cases, but here we check unramified primes.
|
| 87 |
+
ell = 7
|
| 88 |
+
T = Poly(cyclotomic_poly(ell))
|
| 89 |
+
for p in [29, 13, 11, 5]:
|
| 90 |
+
f_exp = n_order(p, ell)
|
| 91 |
+
g_exp = (ell - 1) // f_exp
|
| 92 |
+
P = prime_decomp(p, T)
|
| 93 |
+
assert len(P) == g_exp
|
| 94 |
+
for Pi in P:
|
| 95 |
+
assert Pi.e == 1
|
| 96 |
+
assert Pi.f == f_exp
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
def test_decomp_3():
|
| 100 |
+
T = Poly(x ** 2 - 35)
|
| 101 |
+
rad = {}
|
| 102 |
+
ZK, dK = round_two(T, radicals=rad)
|
| 103 |
+
# 35 is 3 mod 4, so field disc is 4*5*7, and theory says each of the
|
| 104 |
+
# rational primes 2, 5, 7 should be the square of a prime ideal.
|
| 105 |
+
for p in [2, 5, 7]:
|
| 106 |
+
P = prime_decomp(p, T, dK=dK, ZK=ZK, radical=rad.get(p))
|
| 107 |
+
assert len(P) == 1
|
| 108 |
+
assert P[0].e == 2
|
| 109 |
+
assert P[0]**2 == p*ZK
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
def test_decomp_4():
|
| 113 |
+
T = Poly(x ** 2 - 21)
|
| 114 |
+
rad = {}
|
| 115 |
+
ZK, dK = round_two(T, radicals=rad)
|
| 116 |
+
# 21 is 1 mod 4, so field disc is 3*7, and theory says the
|
| 117 |
+
# rational primes 3, 7 should be the square of a prime ideal.
|
| 118 |
+
for p in [3, 7]:
|
| 119 |
+
P = prime_decomp(p, T, dK=dK, ZK=ZK, radical=rad.get(p))
|
| 120 |
+
assert len(P) == 1
|
| 121 |
+
assert P[0].e == 2
|
| 122 |
+
assert P[0]**2 == p*ZK
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
def test_decomp_5():
|
| 126 |
+
# Here is our first test of the "hard case" of prime decomposition.
|
| 127 |
+
# We work in a quadratic extension Q(sqrt(d)) where d is 1 mod 4, and
|
| 128 |
+
# we consider the factorization of the rational prime 2, which divides
|
| 129 |
+
# the index.
|
| 130 |
+
# Theory says the form of p's factorization depends on the residue of
|
| 131 |
+
# d mod 8, so we consider both cases, d = 1 mod 8 and d = 5 mod 8.
|
| 132 |
+
for d in [-7, -3]:
|
| 133 |
+
T = Poly(x ** 2 - d)
|
| 134 |
+
rad = {}
|
| 135 |
+
ZK, dK = round_two(T, radicals=rad)
|
| 136 |
+
p = 2
|
| 137 |
+
P = prime_decomp(p, T, dK=dK, ZK=ZK, radical=rad.get(p))
|
| 138 |
+
if d % 8 == 1:
|
| 139 |
+
assert len(P) == 2
|
| 140 |
+
assert all(P[i].e == 1 and P[i].f == 1 for i in range(2))
|
| 141 |
+
assert prod(Pi**Pi.e for Pi in P) == p * ZK
|
| 142 |
+
else:
|
| 143 |
+
assert d % 8 == 5
|
| 144 |
+
assert len(P) == 1
|
| 145 |
+
assert P[0].e == 1
|
| 146 |
+
assert P[0].f == 2
|
| 147 |
+
assert P[0].as_submodule() == p * ZK
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
def test_decomp_6():
|
| 151 |
+
# Another case where 2 divides the index. This is Dedekind's example of
|
| 152 |
+
# an essential discriminant divisor. (See Cohen, Exercise 6.10.)
|
| 153 |
+
T = Poly(x ** 3 + x ** 2 - 2 * x + 8)
|
| 154 |
+
rad = {}
|
| 155 |
+
ZK, dK = round_two(T, radicals=rad)
|
| 156 |
+
p = 2
|
| 157 |
+
P = prime_decomp(p, T, dK=dK, ZK=ZK, radical=rad.get(p))
|
| 158 |
+
assert len(P) == 3
|
| 159 |
+
assert all(Pi.e == Pi.f == 1 for Pi in P)
|
| 160 |
+
assert prod(Pi**Pi.e for Pi in P) == p*ZK
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
def test_decomp_7():
|
| 164 |
+
# Try working through an AlgebraicField
|
| 165 |
+
T = Poly(x ** 3 + x ** 2 - 2 * x + 8)
|
| 166 |
+
K = QQ.alg_field_from_poly(T)
|
| 167 |
+
p = 2
|
| 168 |
+
P = K.primes_above(p)
|
| 169 |
+
ZK = K.maximal_order()
|
| 170 |
+
assert len(P) == 3
|
| 171 |
+
assert all(Pi.e == Pi.f == 1 for Pi in P)
|
| 172 |
+
assert prod(Pi**Pi.e for Pi in P) == p*ZK
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
def test_decomp_8():
|
| 176 |
+
# This time we consider various cubics, and try factoring all primes
|
| 177 |
+
# dividing the index.
|
| 178 |
+
cases = (
|
| 179 |
+
x ** 3 + 3 * x ** 2 - 4 * x + 4,
|
| 180 |
+
x ** 3 + 3 * x ** 2 + 3 * x - 3,
|
| 181 |
+
x ** 3 + 5 * x ** 2 - x + 3,
|
| 182 |
+
x ** 3 + 5 * x ** 2 - 5 * x - 5,
|
| 183 |
+
x ** 3 + 3 * x ** 2 + 5,
|
| 184 |
+
x ** 3 + 6 * x ** 2 + 3 * x - 1,
|
| 185 |
+
x ** 3 + 6 * x ** 2 + 4,
|
| 186 |
+
x ** 3 + 7 * x ** 2 + 7 * x - 7,
|
| 187 |
+
x ** 3 + 7 * x ** 2 - x + 5,
|
| 188 |
+
x ** 3 + 7 * x ** 2 - 5 * x + 5,
|
| 189 |
+
x ** 3 + 4 * x ** 2 - 3 * x + 7,
|
| 190 |
+
x ** 3 + 8 * x ** 2 + 5 * x - 1,
|
| 191 |
+
x ** 3 + 8 * x ** 2 - 2 * x + 6,
|
| 192 |
+
x ** 3 + 6 * x ** 2 - 3 * x + 8,
|
| 193 |
+
x ** 3 + 9 * x ** 2 + 6 * x - 8,
|
| 194 |
+
x ** 3 + 15 * x ** 2 - 9 * x + 13,
|
| 195 |
+
)
|
| 196 |
+
def display(T, p, radical, P, I, J):
|
| 197 |
+
"""Useful for inspection, when running test manually."""
|
| 198 |
+
print('=' * 20)
|
| 199 |
+
print(T, p, radical)
|
| 200 |
+
for Pi in P:
|
| 201 |
+
print(f' ({Pi!r})')
|
| 202 |
+
print("I: ", I)
|
| 203 |
+
print("J: ", J)
|
| 204 |
+
print(f'Equal: {I == J}')
|
| 205 |
+
inspect = False
|
| 206 |
+
for g in cases:
|
| 207 |
+
T = Poly(g)
|
| 208 |
+
rad = {}
|
| 209 |
+
ZK, dK = round_two(T, radicals=rad)
|
| 210 |
+
dT = T.discriminant()
|
| 211 |
+
f_squared = dT // dK
|
| 212 |
+
F = factorint(f_squared)
|
| 213 |
+
for p in F:
|
| 214 |
+
radical = rad.get(p)
|
| 215 |
+
P = prime_decomp(p, T, dK=dK, ZK=ZK, radical=radical)
|
| 216 |
+
I = prod(Pi**Pi.e for Pi in P)
|
| 217 |
+
J = p * ZK
|
| 218 |
+
if inspect:
|
| 219 |
+
display(T, p, radical, P, I, J)
|
| 220 |
+
assert I == J
|
| 221 |
+
|
| 222 |
+
|
| 223 |
+
def test_PrimeIdeal_eq():
|
| 224 |
+
# `==` should fail on objects of different types, so even a completely
|
| 225 |
+
# inert PrimeIdeal should test unequal to the rational prime it divides.
|
| 226 |
+
T = Poly(cyclotomic_poly(7))
|
| 227 |
+
P0 = prime_decomp(5, T)[0]
|
| 228 |
+
assert P0.f == 6
|
| 229 |
+
assert P0.as_submodule() == 5 * P0.ZK
|
| 230 |
+
assert P0 != 5
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
def test_PrimeIdeal_add():
|
| 234 |
+
T = Poly(cyclotomic_poly(7))
|
| 235 |
+
P0 = prime_decomp(7, T)[0]
|
| 236 |
+
# Adding ideals computes their GCD, so adding the ramified prime dividing
|
| 237 |
+
# 7 to 7 itself should reproduce this prime (as a submodule).
|
| 238 |
+
assert P0 + 7 * P0.ZK == P0.as_submodule()
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
def test_str():
|
| 242 |
+
# Without alias:
|
| 243 |
+
k = QQ.alg_field_from_poly(Poly(x**2 + 7))
|
| 244 |
+
frp = k.primes_above(2)[0]
|
| 245 |
+
assert str(frp) == '(2, 3*_x/2 + 1/2)'
|
| 246 |
+
|
| 247 |
+
frp = k.primes_above(3)[0]
|
| 248 |
+
assert str(frp) == '(3)'
|
| 249 |
+
|
| 250 |
+
# With alias:
|
| 251 |
+
k = QQ.alg_field_from_poly(Poly(x ** 2 + 7), alias='alpha')
|
| 252 |
+
frp = k.primes_above(2)[0]
|
| 253 |
+
assert str(frp) == '(2, 3*alpha/2 + 1/2)'
|
| 254 |
+
|
| 255 |
+
frp = k.primes_above(3)[0]
|
| 256 |
+
assert str(frp) == '(3)'
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
def test_repr():
|
| 260 |
+
T = Poly(x**2 + 7)
|
| 261 |
+
ZK, dK = round_two(T)
|
| 262 |
+
P = prime_decomp(2, T, dK=dK, ZK=ZK)
|
| 263 |
+
assert repr(P[0]) == '[ (2, (3*x + 1)/2) e=1, f=1 ]'
|
| 264 |
+
assert P[0].repr(field_gen=theta) == '[ (2, (3*theta + 1)/2) e=1, f=1 ]'
|
| 265 |
+
assert P[0].repr(field_gen=theta, just_gens=True) == '(2, (3*theta + 1)/2)'
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
def test_PrimeIdeal_reduce():
|
| 269 |
+
k = QQ.alg_field_from_poly(Poly(x ** 3 + x ** 2 - 2 * x + 8))
|
| 270 |
+
Zk = k.maximal_order()
|
| 271 |
+
P = k.primes_above(2)
|
| 272 |
+
frp = P[2]
|
| 273 |
+
|
| 274 |
+
# reduce_element
|
| 275 |
+
a = Zk.parent(to_col([23, 20, 11]), denom=6)
|
| 276 |
+
a_bar_expected = Zk.parent(to_col([11, 5, 2]), denom=6)
|
| 277 |
+
a_bar = frp.reduce_element(a)
|
| 278 |
+
assert a_bar == a_bar_expected
|
| 279 |
+
|
| 280 |
+
# reduce_ANP
|
| 281 |
+
a = k([QQ(11, 6), QQ(20, 6), QQ(23, 6)])
|
| 282 |
+
a_bar_expected = k([QQ(2, 6), QQ(5, 6), QQ(11, 6)])
|
| 283 |
+
a_bar = frp.reduce_ANP(a)
|
| 284 |
+
assert a_bar == a_bar_expected
|
| 285 |
+
|
| 286 |
+
# reduce_alg_num
|
| 287 |
+
a = k.to_alg_num(a)
|
| 288 |
+
a_bar_expected = k.to_alg_num(a_bar_expected)
|
| 289 |
+
a_bar = frp.reduce_alg_num(a)
|
| 290 |
+
assert a_bar == a_bar_expected
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
def test_issue_23402():
|
| 294 |
+
k = QQ.alg_field_from_poly(Poly(x ** 3 + x ** 2 - 2 * x + 8))
|
| 295 |
+
P = k.primes_above(3)
|
| 296 |
+
assert P[0].alpha.equiv(0)
|
pllava/lib/python3.10/site-packages/sympy/polys/tests/__init__.py
ADDED
|
File without changes
|
pllava/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_appellseqs.cpython-310.pyc
ADDED
|
Binary file (4.48 kB). View file
|
|
|
pllava/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_constructor.cpython-310.pyc
ADDED
|
Binary file (5.45 kB). View file
|
|
|
pllava/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_densearith.cpython-310.pyc
ADDED
|
Binary file (38.3 kB). View file
|
|
|
pllava/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_densebasic.cpython-310.pyc
ADDED
|
Binary file (24.7 kB). View file
|
|
|
pllava/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_densetools.cpython-310.pyc
ADDED
|
Binary file (26 kB). View file
|
|
|
pllava/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_dispersion.cpython-310.pyc
ADDED
|
Binary file (2.43 kB). View file
|
|
|
pllava/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_distributedmodules.cpython-310.pyc
ADDED
|
Binary file (9.02 kB). View file
|
|
|
pllava/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_euclidtools.cpython-310.pyc
ADDED
|
Binary file (18.8 kB). View file
|
|
|
pllava/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_factortools.cpython-310.pyc
ADDED
|
Binary file (24.7 kB). View file
|
|
|
pllava/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_groebnertools.cpython-310.pyc
ADDED
|
Binary file (20.3 kB). View file
|
|
|
pllava/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_heuristicgcd.cpython-310.pyc
ADDED
|
Binary file (4.19 kB). View file
|
|
|
pllava/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_orderings.cpython-310.pyc
ADDED
|
Binary file (4.1 kB). View file
|
|
|
pllava/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_partfrac.cpython-310.pyc
ADDED
|
Binary file (9.37 kB). View file
|
|
|
pllava/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_polymatrix.cpython-310.pyc
ADDED
|
Binary file (8.46 kB). View file
|
|
|
pllava/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_polyoptions.cpython-310.pyc
ADDED
|
Binary file (14.7 kB). View file
|
|
|
pllava/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_polyutils.cpython-310.pyc
ADDED
|
Binary file (10.9 kB). View file
|
|
|
pllava/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_ring_series.cpython-310.pyc
ADDED
|
Binary file (30.1 kB). View file
|
|
|
pllava/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_specialpolys.cpython-310.pyc
ADDED
|
Binary file (6.54 kB). View file
|
|
|
pllava/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_sqfreetools.cpython-310.pyc
ADDED
|
Binary file (5.19 kB). View file
|
|
|
pllava/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_subresultants_qq_zz.cpython-310.pyc
ADDED
|
Binary file (13.4 kB). View file
|
|
|
pllava/lib/python3.10/site-packages/sympy/polys/tests/test_appellseqs.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for efficient functions for generating Appell sequences."""
|
| 2 |
+
from sympy.core.numbers import Rational as Q
|
| 3 |
+
from sympy.polys.polytools import Poly
|
| 4 |
+
from sympy.testing.pytest import raises
|
| 5 |
+
from sympy.polys.appellseqs import (bernoulli_poly, bernoulli_c_poly,
|
| 6 |
+
euler_poly, genocchi_poly, andre_poly)
|
| 7 |
+
from sympy.abc import x
|
| 8 |
+
|
| 9 |
+
def test_bernoulli_poly():
|
| 10 |
+
raises(ValueError, lambda: bernoulli_poly(-1, x))
|
| 11 |
+
assert bernoulli_poly(1, x, polys=True) == Poly(x - Q(1,2))
|
| 12 |
+
|
| 13 |
+
assert bernoulli_poly(0, x) == 1
|
| 14 |
+
assert bernoulli_poly(1, x) == x - Q(1,2)
|
| 15 |
+
assert bernoulli_poly(2, x) == x**2 - x + Q(1,6)
|
| 16 |
+
assert bernoulli_poly(3, x) == x**3 - Q(3,2)*x**2 + Q(1,2)*x
|
| 17 |
+
assert bernoulli_poly(4, x) == x**4 - 2*x**3 + x**2 - Q(1,30)
|
| 18 |
+
assert bernoulli_poly(5, x) == x**5 - Q(5,2)*x**4 + Q(5,3)*x**3 - Q(1,6)*x
|
| 19 |
+
assert bernoulli_poly(6, x) == x**6 - 3*x**5 + Q(5,2)*x**4 - Q(1,2)*x**2 + Q(1,42)
|
| 20 |
+
|
| 21 |
+
assert bernoulli_poly(1).dummy_eq(x - Q(1,2))
|
| 22 |
+
assert bernoulli_poly(1, polys=True) == Poly(x - Q(1,2))
|
| 23 |
+
|
| 24 |
+
def test_bernoulli_c_poly():
|
| 25 |
+
raises(ValueError, lambda: bernoulli_c_poly(-1, x))
|
| 26 |
+
assert bernoulli_c_poly(1, x, polys=True) == Poly(x, domain='QQ')
|
| 27 |
+
|
| 28 |
+
assert bernoulli_c_poly(0, x) == 1
|
| 29 |
+
assert bernoulli_c_poly(1, x) == x
|
| 30 |
+
assert bernoulli_c_poly(2, x) == x**2 - Q(1,3)
|
| 31 |
+
assert bernoulli_c_poly(3, x) == x**3 - x
|
| 32 |
+
assert bernoulli_c_poly(4, x) == x**4 - 2*x**2 + Q(7,15)
|
| 33 |
+
assert bernoulli_c_poly(5, x) == x**5 - Q(10,3)*x**3 + Q(7,3)*x
|
| 34 |
+
assert bernoulli_c_poly(6, x) == x**6 - 5*x**4 + 7*x**2 - Q(31,21)
|
| 35 |
+
|
| 36 |
+
assert bernoulli_c_poly(1).dummy_eq(x)
|
| 37 |
+
assert bernoulli_c_poly(1, polys=True) == Poly(x, domain='QQ')
|
| 38 |
+
|
| 39 |
+
assert 2**8 * bernoulli_poly(8, (x+1)/2).expand() == bernoulli_c_poly(8, x)
|
| 40 |
+
assert 2**9 * bernoulli_poly(9, (x+1)/2).expand() == bernoulli_c_poly(9, x)
|
| 41 |
+
|
| 42 |
+
def test_genocchi_poly():
|
| 43 |
+
raises(ValueError, lambda: genocchi_poly(-1, x))
|
| 44 |
+
assert genocchi_poly(2, x, polys=True) == Poly(-2*x + 1)
|
| 45 |
+
|
| 46 |
+
assert genocchi_poly(0, x) == 0
|
| 47 |
+
assert genocchi_poly(1, x) == -1
|
| 48 |
+
assert genocchi_poly(2, x) == 1 - 2*x
|
| 49 |
+
assert genocchi_poly(3, x) == 3*x - 3*x**2
|
| 50 |
+
assert genocchi_poly(4, x) == -1 + 6*x**2 - 4*x**3
|
| 51 |
+
assert genocchi_poly(5, x) == -5*x + 10*x**3 - 5*x**4
|
| 52 |
+
assert genocchi_poly(6, x) == 3 - 15*x**2 + 15*x**4 - 6*x**5
|
| 53 |
+
|
| 54 |
+
assert genocchi_poly(2).dummy_eq(-2*x + 1)
|
| 55 |
+
assert genocchi_poly(2, polys=True) == Poly(-2*x + 1)
|
| 56 |
+
|
| 57 |
+
assert 2 * (bernoulli_poly(8, x) - bernoulli_c_poly(8, x)) == genocchi_poly(8, x)
|
| 58 |
+
assert 2 * (bernoulli_poly(9, x) - bernoulli_c_poly(9, x)) == genocchi_poly(9, x)
|
| 59 |
+
|
| 60 |
+
def test_euler_poly():
|
| 61 |
+
raises(ValueError, lambda: euler_poly(-1, x))
|
| 62 |
+
assert euler_poly(1, x, polys=True) == Poly(x - Q(1,2))
|
| 63 |
+
|
| 64 |
+
assert euler_poly(0, x) == 1
|
| 65 |
+
assert euler_poly(1, x) == x - Q(1,2)
|
| 66 |
+
assert euler_poly(2, x) == x**2 - x
|
| 67 |
+
assert euler_poly(3, x) == x**3 - Q(3,2)*x**2 + Q(1,4)
|
| 68 |
+
assert euler_poly(4, x) == x**4 - 2*x**3 + x
|
| 69 |
+
assert euler_poly(5, x) == x**5 - Q(5,2)*x**4 + Q(5,2)*x**2 - Q(1,2)
|
| 70 |
+
assert euler_poly(6, x) == x**6 - 3*x**5 + 5*x**3 - 3*x
|
| 71 |
+
|
| 72 |
+
assert euler_poly(1).dummy_eq(x - Q(1,2))
|
| 73 |
+
assert euler_poly(1, polys=True) == Poly(x - Q(1,2))
|
| 74 |
+
|
| 75 |
+
assert genocchi_poly(9, x) == euler_poly(8, x) * -9
|
| 76 |
+
assert genocchi_poly(10, x) == euler_poly(9, x) * -10
|
| 77 |
+
|
| 78 |
+
def test_andre_poly():
|
| 79 |
+
raises(ValueError, lambda: andre_poly(-1, x))
|
| 80 |
+
assert andre_poly(1, x, polys=True) == Poly(x)
|
| 81 |
+
|
| 82 |
+
assert andre_poly(0, x) == 1
|
| 83 |
+
assert andre_poly(1, x) == x
|
| 84 |
+
assert andre_poly(2, x) == x**2 - 1
|
| 85 |
+
assert andre_poly(3, x) == x**3 - 3*x
|
| 86 |
+
assert andre_poly(4, x) == x**4 - 6*x**2 + 5
|
| 87 |
+
assert andre_poly(5, x) == x**5 - 10*x**3 + 25*x
|
| 88 |
+
assert andre_poly(6, x) == x**6 - 15*x**4 + 75*x**2 - 61
|
| 89 |
+
|
| 90 |
+
assert andre_poly(1).dummy_eq(x)
|
| 91 |
+
assert andre_poly(1, polys=True) == Poly(x)
|
pllava/lib/python3.10/site-packages/sympy/polys/tests/test_constructor.py
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for tools for constructing domains for expressions. """
|
| 2 |
+
|
| 3 |
+
from sympy.polys.constructor import construct_domain
|
| 4 |
+
from sympy.polys.domains import ZZ, QQ, ZZ_I, QQ_I, RR, CC, EX
|
| 5 |
+
from sympy.polys.domains.realfield import RealField
|
| 6 |
+
from sympy.polys.domains.complexfield import ComplexField
|
| 7 |
+
|
| 8 |
+
from sympy.core import (Catalan, GoldenRatio)
|
| 9 |
+
from sympy.core.numbers import (E, Float, I, Rational, pi)
|
| 10 |
+
from sympy.core.singleton import S
|
| 11 |
+
from sympy.functions.elementary.exponential import exp
|
| 12 |
+
from sympy.functions.elementary.miscellaneous import sqrt
|
| 13 |
+
from sympy.functions.elementary.trigonometric import sin
|
| 14 |
+
from sympy.abc import x, y
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def test_construct_domain():
|
| 18 |
+
|
| 19 |
+
assert construct_domain([1, 2, 3]) == (ZZ, [ZZ(1), ZZ(2), ZZ(3)])
|
| 20 |
+
assert construct_domain([1, 2, 3], field=True) == (QQ, [QQ(1), QQ(2), QQ(3)])
|
| 21 |
+
|
| 22 |
+
assert construct_domain([S.One, S(2), S(3)]) == (ZZ, [ZZ(1), ZZ(2), ZZ(3)])
|
| 23 |
+
assert construct_domain([S.One, S(2), S(3)], field=True) == (QQ, [QQ(1), QQ(2), QQ(3)])
|
| 24 |
+
|
| 25 |
+
assert construct_domain([S.Half, S(2)]) == (QQ, [QQ(1, 2), QQ(2)])
|
| 26 |
+
result = construct_domain([3.14, 1, S.Half])
|
| 27 |
+
assert isinstance(result[0], RealField)
|
| 28 |
+
assert result[1] == [RR(3.14), RR(1.0), RR(0.5)]
|
| 29 |
+
|
| 30 |
+
result = construct_domain([3.14, I, S.Half])
|
| 31 |
+
assert isinstance(result[0], ComplexField)
|
| 32 |
+
assert result[1] == [CC(3.14), CC(1.0j), CC(0.5)]
|
| 33 |
+
|
| 34 |
+
assert construct_domain([1.0+I]) == (CC, [CC(1.0, 1.0)])
|
| 35 |
+
assert construct_domain([2.0+3.0*I]) == (CC, [CC(2.0, 3.0)])
|
| 36 |
+
|
| 37 |
+
assert construct_domain([1, I]) == (ZZ_I, [ZZ_I(1, 0), ZZ_I(0, 1)])
|
| 38 |
+
assert construct_domain([1, I/2]) == (QQ_I, [QQ_I(1, 0), QQ_I(0, S.Half)])
|
| 39 |
+
|
| 40 |
+
assert construct_domain([3.14, sqrt(2)], extension=None) == (EX, [EX(3.14), EX(sqrt(2))])
|
| 41 |
+
assert construct_domain([3.14, sqrt(2)], extension=True) == (EX, [EX(3.14), EX(sqrt(2))])
|
| 42 |
+
|
| 43 |
+
assert construct_domain([1, sqrt(2)], extension=None) == (EX, [EX(1), EX(sqrt(2))])
|
| 44 |
+
|
| 45 |
+
assert construct_domain([x, sqrt(x)]) == (EX, [EX(x), EX(sqrt(x))])
|
| 46 |
+
assert construct_domain([x, sqrt(x), sqrt(y)]) == (EX, [EX(x), EX(sqrt(x)), EX(sqrt(y))])
|
| 47 |
+
|
| 48 |
+
alg = QQ.algebraic_field(sqrt(2))
|
| 49 |
+
|
| 50 |
+
assert construct_domain([7, S.Half, sqrt(2)], extension=True) == \
|
| 51 |
+
(alg, [alg.convert(7), alg.convert(S.Half), alg.convert(sqrt(2))])
|
| 52 |
+
|
| 53 |
+
alg = QQ.algebraic_field(sqrt(2) + sqrt(3))
|
| 54 |
+
|
| 55 |
+
assert construct_domain([7, sqrt(2), sqrt(3)], extension=True) == \
|
| 56 |
+
(alg, [alg.convert(7), alg.convert(sqrt(2)), alg.convert(sqrt(3))])
|
| 57 |
+
|
| 58 |
+
dom = ZZ[x]
|
| 59 |
+
|
| 60 |
+
assert construct_domain([2*x, 3]) == \
|
| 61 |
+
(dom, [dom.convert(2*x), dom.convert(3)])
|
| 62 |
+
|
| 63 |
+
dom = ZZ[x, y]
|
| 64 |
+
|
| 65 |
+
assert construct_domain([2*x, 3*y]) == \
|
| 66 |
+
(dom, [dom.convert(2*x), dom.convert(3*y)])
|
| 67 |
+
|
| 68 |
+
dom = QQ[x]
|
| 69 |
+
|
| 70 |
+
assert construct_domain([x/2, 3]) == \
|
| 71 |
+
(dom, [dom.convert(x/2), dom.convert(3)])
|
| 72 |
+
|
| 73 |
+
dom = QQ[x, y]
|
| 74 |
+
|
| 75 |
+
assert construct_domain([x/2, 3*y]) == \
|
| 76 |
+
(dom, [dom.convert(x/2), dom.convert(3*y)])
|
| 77 |
+
|
| 78 |
+
dom = ZZ_I[x]
|
| 79 |
+
|
| 80 |
+
assert construct_domain([2*x, I]) == \
|
| 81 |
+
(dom, [dom.convert(2*x), dom.convert(I)])
|
| 82 |
+
|
| 83 |
+
dom = ZZ_I[x, y]
|
| 84 |
+
|
| 85 |
+
assert construct_domain([2*x, I*y]) == \
|
| 86 |
+
(dom, [dom.convert(2*x), dom.convert(I*y)])
|
| 87 |
+
|
| 88 |
+
dom = QQ_I[x]
|
| 89 |
+
|
| 90 |
+
assert construct_domain([x/2, I]) == \
|
| 91 |
+
(dom, [dom.convert(x/2), dom.convert(I)])
|
| 92 |
+
|
| 93 |
+
dom = QQ_I[x, y]
|
| 94 |
+
|
| 95 |
+
assert construct_domain([x/2, I*y]) == \
|
| 96 |
+
(dom, [dom.convert(x/2), dom.convert(I*y)])
|
| 97 |
+
|
| 98 |
+
dom = RR[x]
|
| 99 |
+
|
| 100 |
+
assert construct_domain([x/2, 3.5]) == \
|
| 101 |
+
(dom, [dom.convert(x/2), dom.convert(3.5)])
|
| 102 |
+
|
| 103 |
+
dom = RR[x, y]
|
| 104 |
+
|
| 105 |
+
assert construct_domain([x/2, 3.5*y]) == \
|
| 106 |
+
(dom, [dom.convert(x/2), dom.convert(3.5*y)])
|
| 107 |
+
|
| 108 |
+
dom = CC[x]
|
| 109 |
+
|
| 110 |
+
assert construct_domain([I*x/2, 3.5]) == \
|
| 111 |
+
(dom, [dom.convert(I*x/2), dom.convert(3.5)])
|
| 112 |
+
|
| 113 |
+
dom = CC[x, y]
|
| 114 |
+
|
| 115 |
+
assert construct_domain([I*x/2, 3.5*y]) == \
|
| 116 |
+
(dom, [dom.convert(I*x/2), dom.convert(3.5*y)])
|
| 117 |
+
|
| 118 |
+
dom = CC[x]
|
| 119 |
+
|
| 120 |
+
assert construct_domain([x/2, I*3.5]) == \
|
| 121 |
+
(dom, [dom.convert(x/2), dom.convert(I*3.5)])
|
| 122 |
+
|
| 123 |
+
dom = CC[x, y]
|
| 124 |
+
|
| 125 |
+
assert construct_domain([x/2, I*3.5*y]) == \
|
| 126 |
+
(dom, [dom.convert(x/2), dom.convert(I*3.5*y)])
|
| 127 |
+
|
| 128 |
+
dom = ZZ.frac_field(x)
|
| 129 |
+
|
| 130 |
+
assert construct_domain([2/x, 3]) == \
|
| 131 |
+
(dom, [dom.convert(2/x), dom.convert(3)])
|
| 132 |
+
|
| 133 |
+
dom = ZZ.frac_field(x, y)
|
| 134 |
+
|
| 135 |
+
assert construct_domain([2/x, 3*y]) == \
|
| 136 |
+
(dom, [dom.convert(2/x), dom.convert(3*y)])
|
| 137 |
+
|
| 138 |
+
dom = RR.frac_field(x)
|
| 139 |
+
|
| 140 |
+
assert construct_domain([2/x, 3.5]) == \
|
| 141 |
+
(dom, [dom.convert(2/x), dom.convert(3.5)])
|
| 142 |
+
|
| 143 |
+
dom = RR.frac_field(x, y)
|
| 144 |
+
|
| 145 |
+
assert construct_domain([2/x, 3.5*y]) == \
|
| 146 |
+
(dom, [dom.convert(2/x), dom.convert(3.5*y)])
|
| 147 |
+
|
| 148 |
+
dom = RealField(prec=336)[x]
|
| 149 |
+
|
| 150 |
+
assert construct_domain([pi.evalf(100)*x]) == \
|
| 151 |
+
(dom, [dom.convert(pi.evalf(100)*x)])
|
| 152 |
+
|
| 153 |
+
assert construct_domain(2) == (ZZ, ZZ(2))
|
| 154 |
+
assert construct_domain(S(2)/3) == (QQ, QQ(2, 3))
|
| 155 |
+
assert construct_domain(Rational(2, 3)) == (QQ, QQ(2, 3))
|
| 156 |
+
|
| 157 |
+
assert construct_domain({}) == (ZZ, {})
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
def test_complex_exponential():
|
| 161 |
+
w = exp(-I*2*pi/3, evaluate=False)
|
| 162 |
+
alg = QQ.algebraic_field(w)
|
| 163 |
+
assert construct_domain([w**2, w, 1], extension=True) == (
|
| 164 |
+
alg,
|
| 165 |
+
[alg.convert(w**2),
|
| 166 |
+
alg.convert(w),
|
| 167 |
+
alg.convert(1)]
|
| 168 |
+
)
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
def test_composite_option():
|
| 172 |
+
assert construct_domain({(1,): sin(y)}, composite=False) == \
|
| 173 |
+
(EX, {(1,): EX(sin(y))})
|
| 174 |
+
|
| 175 |
+
assert construct_domain({(1,): y}, composite=False) == \
|
| 176 |
+
(EX, {(1,): EX(y)})
|
| 177 |
+
|
| 178 |
+
assert construct_domain({(1, 1): 1}, composite=False) == \
|
| 179 |
+
(ZZ, {(1, 1): 1})
|
| 180 |
+
|
| 181 |
+
assert construct_domain({(1, 0): y}, composite=False) == \
|
| 182 |
+
(EX, {(1, 0): EX(y)})
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
def test_precision():
|
| 186 |
+
f1 = Float("1.01")
|
| 187 |
+
f2 = Float("1.0000000000000000000001")
|
| 188 |
+
for u in [1, 1e-2, 1e-6, 1e-13, 1e-14, 1e-16, 1e-20, 1e-100, 1e-300,
|
| 189 |
+
f1, f2]:
|
| 190 |
+
result = construct_domain([u])
|
| 191 |
+
v = float(result[1][0])
|
| 192 |
+
assert abs(u - v) / u < 1e-14 # Test relative accuracy
|
| 193 |
+
|
| 194 |
+
result = construct_domain([f1])
|
| 195 |
+
y = result[1][0]
|
| 196 |
+
assert y-1 > 1e-50
|
| 197 |
+
|
| 198 |
+
result = construct_domain([f2])
|
| 199 |
+
y = result[1][0]
|
| 200 |
+
assert y-1 > 1e-50
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
def test_issue_11538():
|
| 204 |
+
for n in [E, pi, Catalan]:
|
| 205 |
+
assert construct_domain(n)[0] == ZZ[n]
|
| 206 |
+
assert construct_domain(x + n)[0] == ZZ[x, n]
|
| 207 |
+
assert construct_domain(GoldenRatio)[0] == EX
|
| 208 |
+
assert construct_domain(x + GoldenRatio)[0] == EX
|
pllava/lib/python3.10/site-packages/sympy/polys/tests/test_densearith.py
ADDED
|
@@ -0,0 +1,997 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for dense recursive polynomials' arithmetics. """
|
| 2 |
+
|
| 3 |
+
from sympy.external.gmpy import GROUND_TYPES
|
| 4 |
+
|
| 5 |
+
from sympy.polys.densebasic import (
|
| 6 |
+
dup_normal, dmp_normal,
|
| 7 |
+
)
|
| 8 |
+
|
| 9 |
+
from sympy.polys.densearith import (
|
| 10 |
+
dup_add_term, dmp_add_term,
|
| 11 |
+
dup_sub_term, dmp_sub_term,
|
| 12 |
+
dup_mul_term, dmp_mul_term,
|
| 13 |
+
dup_add_ground, dmp_add_ground,
|
| 14 |
+
dup_sub_ground, dmp_sub_ground,
|
| 15 |
+
dup_mul_ground, dmp_mul_ground,
|
| 16 |
+
dup_quo_ground, dmp_quo_ground,
|
| 17 |
+
dup_exquo_ground, dmp_exquo_ground,
|
| 18 |
+
dup_lshift, dup_rshift,
|
| 19 |
+
dup_abs, dmp_abs,
|
| 20 |
+
dup_neg, dmp_neg,
|
| 21 |
+
dup_add, dmp_add,
|
| 22 |
+
dup_sub, dmp_sub,
|
| 23 |
+
dup_mul, dmp_mul,
|
| 24 |
+
dup_sqr, dmp_sqr,
|
| 25 |
+
dup_pow, dmp_pow,
|
| 26 |
+
dup_add_mul, dmp_add_mul,
|
| 27 |
+
dup_sub_mul, dmp_sub_mul,
|
| 28 |
+
dup_pdiv, dup_prem, dup_pquo, dup_pexquo,
|
| 29 |
+
dmp_pdiv, dmp_prem, dmp_pquo, dmp_pexquo,
|
| 30 |
+
dup_rr_div, dmp_rr_div,
|
| 31 |
+
dup_ff_div, dmp_ff_div,
|
| 32 |
+
dup_div, dup_rem, dup_quo, dup_exquo,
|
| 33 |
+
dmp_div, dmp_rem, dmp_quo, dmp_exquo,
|
| 34 |
+
dup_max_norm, dmp_max_norm,
|
| 35 |
+
dup_l1_norm, dmp_l1_norm,
|
| 36 |
+
dup_l2_norm_squared, dmp_l2_norm_squared,
|
| 37 |
+
dup_expand, dmp_expand,
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
from sympy.polys.polyerrors import (
|
| 41 |
+
ExactQuotientFailed,
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
from sympy.polys.specialpolys import f_polys
|
| 45 |
+
from sympy.polys.domains import FF, ZZ, QQ
|
| 46 |
+
|
| 47 |
+
from sympy.testing.pytest import raises
|
| 48 |
+
|
| 49 |
+
f_0, f_1, f_2, f_3, f_4, f_5, f_6 = [ f.to_dense() for f in f_polys() ]
|
| 50 |
+
F_0 = dmp_mul_ground(dmp_normal(f_0, 2, QQ), QQ(1, 7), 2, QQ)
|
| 51 |
+
|
| 52 |
+
def test_dup_add_term():
|
| 53 |
+
f = dup_normal([], ZZ)
|
| 54 |
+
|
| 55 |
+
assert dup_add_term(f, ZZ(0), 0, ZZ) == dup_normal([], ZZ)
|
| 56 |
+
|
| 57 |
+
assert dup_add_term(f, ZZ(1), 0, ZZ) == dup_normal([1], ZZ)
|
| 58 |
+
assert dup_add_term(f, ZZ(1), 1, ZZ) == dup_normal([1, 0], ZZ)
|
| 59 |
+
assert dup_add_term(f, ZZ(1), 2, ZZ) == dup_normal([1, 0, 0], ZZ)
|
| 60 |
+
|
| 61 |
+
f = dup_normal([1, 1, 1], ZZ)
|
| 62 |
+
|
| 63 |
+
assert dup_add_term(f, ZZ(1), 0, ZZ) == dup_normal([1, 1, 2], ZZ)
|
| 64 |
+
assert dup_add_term(f, ZZ(1), 1, ZZ) == dup_normal([1, 2, 1], ZZ)
|
| 65 |
+
assert dup_add_term(f, ZZ(1), 2, ZZ) == dup_normal([2, 1, 1], ZZ)
|
| 66 |
+
|
| 67 |
+
assert dup_add_term(f, ZZ(1), 3, ZZ) == dup_normal([1, 1, 1, 1], ZZ)
|
| 68 |
+
assert dup_add_term(f, ZZ(1), 4, ZZ) == dup_normal([1, 0, 1, 1, 1], ZZ)
|
| 69 |
+
assert dup_add_term(f, ZZ(1), 5, ZZ) == dup_normal([1, 0, 0, 1, 1, 1], ZZ)
|
| 70 |
+
assert dup_add_term(
|
| 71 |
+
f, ZZ(1), 6, ZZ) == dup_normal([1, 0, 0, 0, 1, 1, 1], ZZ)
|
| 72 |
+
|
| 73 |
+
assert dup_add_term(f, ZZ(-1), 2, ZZ) == dup_normal([1, 1], ZZ)
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def test_dmp_add_term():
|
| 77 |
+
assert dmp_add_term([ZZ(1), ZZ(1), ZZ(1)], ZZ(1), 2, 0, ZZ) == \
|
| 78 |
+
dup_add_term([ZZ(1), ZZ(1), ZZ(1)], ZZ(1), 2, ZZ)
|
| 79 |
+
assert dmp_add_term(f_0, [[]], 3, 2, ZZ) == f_0
|
| 80 |
+
assert dmp_add_term(F_0, [[]], 3, 2, QQ) == F_0
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def test_dup_sub_term():
|
| 84 |
+
f = dup_normal([], ZZ)
|
| 85 |
+
|
| 86 |
+
assert dup_sub_term(f, ZZ(0), 0, ZZ) == dup_normal([], ZZ)
|
| 87 |
+
|
| 88 |
+
assert dup_sub_term(f, ZZ(1), 0, ZZ) == dup_normal([-1], ZZ)
|
| 89 |
+
assert dup_sub_term(f, ZZ(1), 1, ZZ) == dup_normal([-1, 0], ZZ)
|
| 90 |
+
assert dup_sub_term(f, ZZ(1), 2, ZZ) == dup_normal([-1, 0, 0], ZZ)
|
| 91 |
+
|
| 92 |
+
f = dup_normal([1, 1, 1], ZZ)
|
| 93 |
+
|
| 94 |
+
assert dup_sub_term(f, ZZ(2), 0, ZZ) == dup_normal([ 1, 1, -1], ZZ)
|
| 95 |
+
assert dup_sub_term(f, ZZ(2), 1, ZZ) == dup_normal([ 1, -1, 1], ZZ)
|
| 96 |
+
assert dup_sub_term(f, ZZ(2), 2, ZZ) == dup_normal([-1, 1, 1], ZZ)
|
| 97 |
+
|
| 98 |
+
assert dup_sub_term(f, ZZ(1), 3, ZZ) == dup_normal([-1, 1, 1, 1], ZZ)
|
| 99 |
+
assert dup_sub_term(f, ZZ(1), 4, ZZ) == dup_normal([-1, 0, 1, 1, 1], ZZ)
|
| 100 |
+
assert dup_sub_term(f, ZZ(1), 5, ZZ) == dup_normal([-1, 0, 0, 1, 1, 1], ZZ)
|
| 101 |
+
assert dup_sub_term(
|
| 102 |
+
f, ZZ(1), 6, ZZ) == dup_normal([-1, 0, 0, 0, 1, 1, 1], ZZ)
|
| 103 |
+
|
| 104 |
+
assert dup_sub_term(f, ZZ(1), 2, ZZ) == dup_normal([1, 1], ZZ)
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
def test_dmp_sub_term():
|
| 108 |
+
assert dmp_sub_term([ZZ(1), ZZ(1), ZZ(1)], ZZ(1), 2, 0, ZZ) == \
|
| 109 |
+
dup_sub_term([ZZ(1), ZZ(1), ZZ(1)], ZZ(1), 2, ZZ)
|
| 110 |
+
assert dmp_sub_term(f_0, [[]], 3, 2, ZZ) == f_0
|
| 111 |
+
assert dmp_sub_term(F_0, [[]], 3, 2, QQ) == F_0
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
def test_dup_mul_term():
|
| 115 |
+
f = dup_normal([], ZZ)
|
| 116 |
+
|
| 117 |
+
assert dup_mul_term(f, ZZ(2), 3, ZZ) == dup_normal([], ZZ)
|
| 118 |
+
|
| 119 |
+
f = dup_normal([1, 1], ZZ)
|
| 120 |
+
|
| 121 |
+
assert dup_mul_term(f, ZZ(0), 3, ZZ) == dup_normal([], ZZ)
|
| 122 |
+
|
| 123 |
+
f = dup_normal([1, 2, 3], ZZ)
|
| 124 |
+
|
| 125 |
+
assert dup_mul_term(f, ZZ(2), 0, ZZ) == dup_normal([2, 4, 6], ZZ)
|
| 126 |
+
assert dup_mul_term(f, ZZ(2), 1, ZZ) == dup_normal([2, 4, 6, 0], ZZ)
|
| 127 |
+
assert dup_mul_term(f, ZZ(2), 2, ZZ) == dup_normal([2, 4, 6, 0, 0], ZZ)
|
| 128 |
+
assert dup_mul_term(f, ZZ(2), 3, ZZ) == dup_normal([2, 4, 6, 0, 0, 0], ZZ)
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
def test_dmp_mul_term():
|
| 132 |
+
assert dmp_mul_term([ZZ(1), ZZ(2), ZZ(3)], ZZ(2), 1, 0, ZZ) == \
|
| 133 |
+
dup_mul_term([ZZ(1), ZZ(2), ZZ(3)], ZZ(2), 1, ZZ)
|
| 134 |
+
|
| 135 |
+
assert dmp_mul_term([[]], [ZZ(2)], 3, 1, ZZ) == [[]]
|
| 136 |
+
assert dmp_mul_term([[ZZ(1)]], [], 3, 1, ZZ) == [[]]
|
| 137 |
+
|
| 138 |
+
assert dmp_mul_term([[ZZ(1), ZZ(2)], [ZZ(3)]], [ZZ(2)], 2, 1, ZZ) == \
|
| 139 |
+
[[ZZ(2), ZZ(4)], [ZZ(6)], [], []]
|
| 140 |
+
|
| 141 |
+
assert dmp_mul_term([[]], [QQ(2, 3)], 3, 1, QQ) == [[]]
|
| 142 |
+
assert dmp_mul_term([[QQ(1, 2)]], [], 3, 1, QQ) == [[]]
|
| 143 |
+
|
| 144 |
+
assert dmp_mul_term([[QQ(1, 5), QQ(2, 5)], [QQ(3, 5)]], [QQ(2, 3)], 2, 1, QQ) == \
|
| 145 |
+
[[QQ(2, 15), QQ(4, 15)], [QQ(6, 15)], [], []]
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
def test_dup_add_ground():
|
| 149 |
+
f = ZZ.map([1, 2, 3, 4])
|
| 150 |
+
g = ZZ.map([1, 2, 3, 8])
|
| 151 |
+
|
| 152 |
+
assert dup_add_ground(f, ZZ(4), ZZ) == g
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
def test_dmp_add_ground():
|
| 156 |
+
f = ZZ.map([[1], [2], [3], [4]])
|
| 157 |
+
g = ZZ.map([[1], [2], [3], [8]])
|
| 158 |
+
|
| 159 |
+
assert dmp_add_ground(f, ZZ(4), 1, ZZ) == g
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
def test_dup_sub_ground():
|
| 163 |
+
f = ZZ.map([1, 2, 3, 4])
|
| 164 |
+
g = ZZ.map([1, 2, 3, 0])
|
| 165 |
+
|
| 166 |
+
assert dup_sub_ground(f, ZZ(4), ZZ) == g
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
def test_dmp_sub_ground():
|
| 170 |
+
f = ZZ.map([[1], [2], [3], [4]])
|
| 171 |
+
g = ZZ.map([[1], [2], [3], []])
|
| 172 |
+
|
| 173 |
+
assert dmp_sub_ground(f, ZZ(4), 1, ZZ) == g
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
def test_dup_mul_ground():
|
| 177 |
+
f = dup_normal([], ZZ)
|
| 178 |
+
|
| 179 |
+
assert dup_mul_ground(f, ZZ(2), ZZ) == dup_normal([], ZZ)
|
| 180 |
+
|
| 181 |
+
f = dup_normal([1, 2, 3], ZZ)
|
| 182 |
+
|
| 183 |
+
assert dup_mul_ground(f, ZZ(0), ZZ) == dup_normal([], ZZ)
|
| 184 |
+
assert dup_mul_ground(f, ZZ(2), ZZ) == dup_normal([2, 4, 6], ZZ)
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
def test_dmp_mul_ground():
|
| 188 |
+
assert dmp_mul_ground(f_0, ZZ(2), 2, ZZ) == [
|
| 189 |
+
[[ZZ(2), ZZ(4), ZZ(6)], [ZZ(4)]],
|
| 190 |
+
[[ZZ(6)]],
|
| 191 |
+
[[ZZ(8), ZZ(10), ZZ(12)], [ZZ(2), ZZ(4), ZZ(2)], [ZZ(2)]]
|
| 192 |
+
]
|
| 193 |
+
|
| 194 |
+
assert dmp_mul_ground(F_0, QQ(1, 2), 2, QQ) == [
|
| 195 |
+
[[QQ(1, 14), QQ(2, 14), QQ(3, 14)], [QQ(2, 14)]],
|
| 196 |
+
[[QQ(3, 14)]],
|
| 197 |
+
[[QQ(4, 14), QQ(5, 14), QQ(6, 14)], [QQ(1, 14), QQ(2, 14),
|
| 198 |
+
QQ(1, 14)], [QQ(1, 14)]]
|
| 199 |
+
]
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
def test_dup_quo_ground():
|
| 203 |
+
raises(ZeroDivisionError, lambda: dup_quo_ground(dup_normal([1, 2,
|
| 204 |
+
3], ZZ), ZZ(0), ZZ))
|
| 205 |
+
|
| 206 |
+
f = dup_normal([], ZZ)
|
| 207 |
+
|
| 208 |
+
assert dup_quo_ground(f, ZZ(3), ZZ) == dup_normal([], ZZ)
|
| 209 |
+
|
| 210 |
+
f = dup_normal([6, 2, 8], ZZ)
|
| 211 |
+
|
| 212 |
+
assert dup_quo_ground(f, ZZ(1), ZZ) == f
|
| 213 |
+
assert dup_quo_ground(f, ZZ(2), ZZ) == dup_normal([3, 1, 4], ZZ)
|
| 214 |
+
|
| 215 |
+
assert dup_quo_ground(f, ZZ(3), ZZ) == dup_normal([2, 0, 2], ZZ)
|
| 216 |
+
|
| 217 |
+
f = dup_normal([6, 2, 8], QQ)
|
| 218 |
+
|
| 219 |
+
assert dup_quo_ground(f, QQ(1), QQ) == f
|
| 220 |
+
assert dup_quo_ground(f, QQ(2), QQ) == [QQ(3), QQ(1), QQ(4)]
|
| 221 |
+
assert dup_quo_ground(f, QQ(7), QQ) == [QQ(6, 7), QQ(2, 7), QQ(8, 7)]
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
def test_dup_exquo_ground():
|
| 225 |
+
raises(ZeroDivisionError, lambda: dup_exquo_ground(dup_normal([1,
|
| 226 |
+
2, 3], ZZ), ZZ(0), ZZ))
|
| 227 |
+
raises(ExactQuotientFailed, lambda: dup_exquo_ground(dup_normal([1,
|
| 228 |
+
2, 3], ZZ), ZZ(3), ZZ))
|
| 229 |
+
|
| 230 |
+
f = dup_normal([], ZZ)
|
| 231 |
+
|
| 232 |
+
assert dup_exquo_ground(f, ZZ(3), ZZ) == dup_normal([], ZZ)
|
| 233 |
+
|
| 234 |
+
f = dup_normal([6, 2, 8], ZZ)
|
| 235 |
+
|
| 236 |
+
assert dup_exquo_ground(f, ZZ(1), ZZ) == f
|
| 237 |
+
assert dup_exquo_ground(f, ZZ(2), ZZ) == dup_normal([3, 1, 4], ZZ)
|
| 238 |
+
|
| 239 |
+
f = dup_normal([6, 2, 8], QQ)
|
| 240 |
+
|
| 241 |
+
assert dup_exquo_ground(f, QQ(1), QQ) == f
|
| 242 |
+
assert dup_exquo_ground(f, QQ(2), QQ) == [QQ(3), QQ(1), QQ(4)]
|
| 243 |
+
assert dup_exquo_ground(f, QQ(7), QQ) == [QQ(6, 7), QQ(2, 7), QQ(8, 7)]
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
def test_dmp_quo_ground():
|
| 247 |
+
f = dmp_normal([[6], [2], [8]], 1, ZZ)
|
| 248 |
+
|
| 249 |
+
assert dmp_quo_ground(f, ZZ(1), 1, ZZ) == f
|
| 250 |
+
assert dmp_quo_ground(
|
| 251 |
+
f, ZZ(2), 1, ZZ) == dmp_normal([[3], [1], [4]], 1, ZZ)
|
| 252 |
+
|
| 253 |
+
assert dmp_normal(dmp_quo_ground(
|
| 254 |
+
f, ZZ(3), 1, ZZ), 1, ZZ) == dmp_normal([[2], [], [2]], 1, ZZ)
|
| 255 |
+
|
| 256 |
+
|
| 257 |
+
def test_dmp_exquo_ground():
|
| 258 |
+
f = dmp_normal([[6], [2], [8]], 1, ZZ)
|
| 259 |
+
|
| 260 |
+
assert dmp_exquo_ground(f, ZZ(1), 1, ZZ) == f
|
| 261 |
+
assert dmp_exquo_ground(
|
| 262 |
+
f, ZZ(2), 1, ZZ) == dmp_normal([[3], [1], [4]], 1, ZZ)
|
| 263 |
+
|
| 264 |
+
|
| 265 |
+
def test_dup_lshift():
|
| 266 |
+
assert dup_lshift([], 3, ZZ) == []
|
| 267 |
+
assert dup_lshift([1], 3, ZZ) == [1, 0, 0, 0]
|
| 268 |
+
|
| 269 |
+
|
| 270 |
+
def test_dup_rshift():
|
| 271 |
+
assert dup_rshift([], 3, ZZ) == []
|
| 272 |
+
assert dup_rshift([1, 0, 0, 0], 3, ZZ) == [1]
|
| 273 |
+
|
| 274 |
+
|
| 275 |
+
def test_dup_abs():
|
| 276 |
+
assert dup_abs([], ZZ) == []
|
| 277 |
+
assert dup_abs([ZZ( 1)], ZZ) == [ZZ(1)]
|
| 278 |
+
assert dup_abs([ZZ(-7)], ZZ) == [ZZ(7)]
|
| 279 |
+
assert dup_abs([ZZ(-1), ZZ(2), ZZ(3)], ZZ) == [ZZ(1), ZZ(2), ZZ(3)]
|
| 280 |
+
|
| 281 |
+
assert dup_abs([], QQ) == []
|
| 282 |
+
assert dup_abs([QQ( 1, 2)], QQ) == [QQ(1, 2)]
|
| 283 |
+
assert dup_abs([QQ(-7, 3)], QQ) == [QQ(7, 3)]
|
| 284 |
+
assert dup_abs(
|
| 285 |
+
[QQ(-1, 7), QQ(2, 7), QQ(3, 7)], QQ) == [QQ(1, 7), QQ(2, 7), QQ(3, 7)]
|
| 286 |
+
|
| 287 |
+
|
| 288 |
+
def test_dmp_abs():
|
| 289 |
+
assert dmp_abs([ZZ(-1)], 0, ZZ) == [ZZ(1)]
|
| 290 |
+
assert dmp_abs([QQ(-1, 2)], 0, QQ) == [QQ(1, 2)]
|
| 291 |
+
|
| 292 |
+
assert dmp_abs([[[]]], 2, ZZ) == [[[]]]
|
| 293 |
+
assert dmp_abs([[[ZZ(1)]]], 2, ZZ) == [[[ZZ(1)]]]
|
| 294 |
+
assert dmp_abs([[[ZZ(-7)]]], 2, ZZ) == [[[ZZ(7)]]]
|
| 295 |
+
|
| 296 |
+
assert dmp_abs([[[]]], 2, QQ) == [[[]]]
|
| 297 |
+
assert dmp_abs([[[QQ(1, 2)]]], 2, QQ) == [[[QQ(1, 2)]]]
|
| 298 |
+
assert dmp_abs([[[QQ(-7, 9)]]], 2, QQ) == [[[QQ(7, 9)]]]
|
| 299 |
+
|
| 300 |
+
|
| 301 |
+
def test_dup_neg():
|
| 302 |
+
assert dup_neg([], ZZ) == []
|
| 303 |
+
assert dup_neg([ZZ(1)], ZZ) == [ZZ(-1)]
|
| 304 |
+
assert dup_neg([ZZ(-7)], ZZ) == [ZZ(7)]
|
| 305 |
+
assert dup_neg([ZZ(-1), ZZ(2), ZZ(3)], ZZ) == [ZZ(1), ZZ(-2), ZZ(-3)]
|
| 306 |
+
|
| 307 |
+
assert dup_neg([], QQ) == []
|
| 308 |
+
assert dup_neg([QQ(1, 2)], QQ) == [QQ(-1, 2)]
|
| 309 |
+
assert dup_neg([QQ(-7, 9)], QQ) == [QQ(7, 9)]
|
| 310 |
+
assert dup_neg([QQ(
|
| 311 |
+
-1, 7), QQ(2, 7), QQ(3, 7)], QQ) == [QQ(1, 7), QQ(-2, 7), QQ(-3, 7)]
|
| 312 |
+
|
| 313 |
+
|
| 314 |
+
def test_dmp_neg():
|
| 315 |
+
assert dmp_neg([ZZ(-1)], 0, ZZ) == [ZZ(1)]
|
| 316 |
+
assert dmp_neg([QQ(-1, 2)], 0, QQ) == [QQ(1, 2)]
|
| 317 |
+
|
| 318 |
+
assert dmp_neg([[[]]], 2, ZZ) == [[[]]]
|
| 319 |
+
assert dmp_neg([[[ZZ(1)]]], 2, ZZ) == [[[ZZ(-1)]]]
|
| 320 |
+
assert dmp_neg([[[ZZ(-7)]]], 2, ZZ) == [[[ZZ(7)]]]
|
| 321 |
+
|
| 322 |
+
assert dmp_neg([[[]]], 2, QQ) == [[[]]]
|
| 323 |
+
assert dmp_neg([[[QQ(1, 9)]]], 2, QQ) == [[[QQ(-1, 9)]]]
|
| 324 |
+
assert dmp_neg([[[QQ(-7, 9)]]], 2, QQ) == [[[QQ(7, 9)]]]
|
| 325 |
+
|
| 326 |
+
|
| 327 |
+
def test_dup_add():
|
| 328 |
+
assert dup_add([], [], ZZ) == []
|
| 329 |
+
assert dup_add([ZZ(1)], [], ZZ) == [ZZ(1)]
|
| 330 |
+
assert dup_add([], [ZZ(1)], ZZ) == [ZZ(1)]
|
| 331 |
+
assert dup_add([ZZ(1)], [ZZ(1)], ZZ) == [ZZ(2)]
|
| 332 |
+
assert dup_add([ZZ(1)], [ZZ(2)], ZZ) == [ZZ(3)]
|
| 333 |
+
|
| 334 |
+
assert dup_add([ZZ(1), ZZ(2)], [ZZ(1)], ZZ) == [ZZ(1), ZZ(3)]
|
| 335 |
+
assert dup_add([ZZ(1)], [ZZ(1), ZZ(2)], ZZ) == [ZZ(1), ZZ(3)]
|
| 336 |
+
|
| 337 |
+
assert dup_add([ZZ(1), ZZ(
|
| 338 |
+
2), ZZ(3)], [ZZ(8), ZZ(9), ZZ(10)], ZZ) == [ZZ(9), ZZ(11), ZZ(13)]
|
| 339 |
+
|
| 340 |
+
assert dup_add([], [], QQ) == []
|
| 341 |
+
assert dup_add([QQ(1, 2)], [], QQ) == [QQ(1, 2)]
|
| 342 |
+
assert dup_add([], [QQ(1, 2)], QQ) == [QQ(1, 2)]
|
| 343 |
+
assert dup_add([QQ(1, 4)], [QQ(1, 4)], QQ) == [QQ(1, 2)]
|
| 344 |
+
assert dup_add([QQ(1, 4)], [QQ(1, 2)], QQ) == [QQ(3, 4)]
|
| 345 |
+
|
| 346 |
+
assert dup_add([QQ(1, 2), QQ(2, 3)], [QQ(1)], QQ) == [QQ(1, 2), QQ(5, 3)]
|
| 347 |
+
assert dup_add([QQ(1)], [QQ(1, 2), QQ(2, 3)], QQ) == [QQ(1, 2), QQ(5, 3)]
|
| 348 |
+
|
| 349 |
+
assert dup_add([QQ(1, 7), QQ(2, 7), QQ(3, 7)], [QQ(
|
| 350 |
+
8, 7), QQ(9, 7), QQ(10, 7)], QQ) == [QQ(9, 7), QQ(11, 7), QQ(13, 7)]
|
| 351 |
+
|
| 352 |
+
|
| 353 |
+
def test_dmp_add():
|
| 354 |
+
assert dmp_add([ZZ(1), ZZ(2)], [ZZ(1)], 0, ZZ) == \
|
| 355 |
+
dup_add([ZZ(1), ZZ(2)], [ZZ(1)], ZZ)
|
| 356 |
+
assert dmp_add([QQ(1, 2), QQ(2, 3)], [QQ(1)], 0, QQ) == \
|
| 357 |
+
dup_add([QQ(1, 2), QQ(2, 3)], [QQ(1)], QQ)
|
| 358 |
+
|
| 359 |
+
assert dmp_add([[[]]], [[[]]], 2, ZZ) == [[[]]]
|
| 360 |
+
assert dmp_add([[[ZZ(1)]]], [[[]]], 2, ZZ) == [[[ZZ(1)]]]
|
| 361 |
+
assert dmp_add([[[]]], [[[ZZ(1)]]], 2, ZZ) == [[[ZZ(1)]]]
|
| 362 |
+
assert dmp_add([[[ZZ(2)]]], [[[ZZ(1)]]], 2, ZZ) == [[[ZZ(3)]]]
|
| 363 |
+
assert dmp_add([[[ZZ(1)]]], [[[ZZ(2)]]], 2, ZZ) == [[[ZZ(3)]]]
|
| 364 |
+
|
| 365 |
+
assert dmp_add([[[]]], [[[]]], 2, QQ) == [[[]]]
|
| 366 |
+
assert dmp_add([[[QQ(1, 2)]]], [[[]]], 2, QQ) == [[[QQ(1, 2)]]]
|
| 367 |
+
assert dmp_add([[[]]], [[[QQ(1, 2)]]], 2, QQ) == [[[QQ(1, 2)]]]
|
| 368 |
+
assert dmp_add([[[QQ(2, 7)]]], [[[QQ(1, 7)]]], 2, QQ) == [[[QQ(3, 7)]]]
|
| 369 |
+
assert dmp_add([[[QQ(1, 7)]]], [[[QQ(2, 7)]]], 2, QQ) == [[[QQ(3, 7)]]]
|
| 370 |
+
|
| 371 |
+
|
| 372 |
+
def test_dup_sub():
|
| 373 |
+
assert dup_sub([], [], ZZ) == []
|
| 374 |
+
assert dup_sub([ZZ(1)], [], ZZ) == [ZZ(1)]
|
| 375 |
+
assert dup_sub([], [ZZ(1)], ZZ) == [ZZ(-1)]
|
| 376 |
+
assert dup_sub([ZZ(1)], [ZZ(1)], ZZ) == []
|
| 377 |
+
assert dup_sub([ZZ(1)], [ZZ(2)], ZZ) == [ZZ(-1)]
|
| 378 |
+
|
| 379 |
+
assert dup_sub([ZZ(1), ZZ(2)], [ZZ(1)], ZZ) == [ZZ(1), ZZ(1)]
|
| 380 |
+
assert dup_sub([ZZ(1)], [ZZ(1), ZZ(2)], ZZ) == [ZZ(-1), ZZ(-1)]
|
| 381 |
+
|
| 382 |
+
assert dup_sub([ZZ(3), ZZ(
|
| 383 |
+
2), ZZ(1)], [ZZ(8), ZZ(9), ZZ(10)], ZZ) == [ZZ(-5), ZZ(-7), ZZ(-9)]
|
| 384 |
+
|
| 385 |
+
assert dup_sub([], [], QQ) == []
|
| 386 |
+
assert dup_sub([QQ(1, 2)], [], QQ) == [QQ(1, 2)]
|
| 387 |
+
assert dup_sub([], [QQ(1, 2)], QQ) == [QQ(-1, 2)]
|
| 388 |
+
assert dup_sub([QQ(1, 3)], [QQ(1, 3)], QQ) == []
|
| 389 |
+
assert dup_sub([QQ(1, 3)], [QQ(2, 3)], QQ) == [QQ(-1, 3)]
|
| 390 |
+
|
| 391 |
+
assert dup_sub([QQ(1, 7), QQ(2, 7)], [QQ(1)], QQ) == [QQ(1, 7), QQ(-5, 7)]
|
| 392 |
+
assert dup_sub([QQ(1)], [QQ(1, 7), QQ(2, 7)], QQ) == [QQ(-1, 7), QQ(5, 7)]
|
| 393 |
+
|
| 394 |
+
assert dup_sub([QQ(3, 7), QQ(2, 7), QQ(1, 7)], [QQ(
|
| 395 |
+
8, 7), QQ(9, 7), QQ(10, 7)], QQ) == [QQ(-5, 7), QQ(-7, 7), QQ(-9, 7)]
|
| 396 |
+
|
| 397 |
+
|
| 398 |
+
def test_dmp_sub():
|
| 399 |
+
assert dmp_sub([ZZ(1), ZZ(2)], [ZZ(1)], 0, ZZ) == \
|
| 400 |
+
dup_sub([ZZ(1), ZZ(2)], [ZZ(1)], ZZ)
|
| 401 |
+
assert dmp_sub([QQ(1, 2), QQ(2, 3)], [QQ(1)], 0, QQ) == \
|
| 402 |
+
dup_sub([QQ(1, 2), QQ(2, 3)], [QQ(1)], QQ)
|
| 403 |
+
|
| 404 |
+
assert dmp_sub([[[]]], [[[]]], 2, ZZ) == [[[]]]
|
| 405 |
+
assert dmp_sub([[[ZZ(1)]]], [[[]]], 2, ZZ) == [[[ZZ(1)]]]
|
| 406 |
+
assert dmp_sub([[[]]], [[[ZZ(1)]]], 2, ZZ) == [[[ZZ(-1)]]]
|
| 407 |
+
assert dmp_sub([[[ZZ(2)]]], [[[ZZ(1)]]], 2, ZZ) == [[[ZZ(1)]]]
|
| 408 |
+
assert dmp_sub([[[ZZ(1)]]], [[[ZZ(2)]]], 2, ZZ) == [[[ZZ(-1)]]]
|
| 409 |
+
|
| 410 |
+
assert dmp_sub([[[]]], [[[]]], 2, QQ) == [[[]]]
|
| 411 |
+
assert dmp_sub([[[QQ(1, 2)]]], [[[]]], 2, QQ) == [[[QQ(1, 2)]]]
|
| 412 |
+
assert dmp_sub([[[]]], [[[QQ(1, 2)]]], 2, QQ) == [[[QQ(-1, 2)]]]
|
| 413 |
+
assert dmp_sub([[[QQ(2, 7)]]], [[[QQ(1, 7)]]], 2, QQ) == [[[QQ(1, 7)]]]
|
| 414 |
+
assert dmp_sub([[[QQ(1, 7)]]], [[[QQ(2, 7)]]], 2, QQ) == [[[QQ(-1, 7)]]]
|
| 415 |
+
|
| 416 |
+
|
| 417 |
+
def test_dup_add_mul():
|
| 418 |
+
assert dup_add_mul([ZZ(1), ZZ(2), ZZ(3)], [ZZ(3), ZZ(2), ZZ(1)],
|
| 419 |
+
[ZZ(1), ZZ(2)], ZZ) == [ZZ(3), ZZ(9), ZZ(7), ZZ(5)]
|
| 420 |
+
assert dmp_add_mul([[ZZ(1), ZZ(2)], [ZZ(3)]], [[ZZ(3)], [ZZ(2), ZZ(1)]],
|
| 421 |
+
[[ZZ(1)], [ZZ(2)]], 1, ZZ) == [[ZZ(3)], [ZZ(3), ZZ(9)], [ZZ(4), ZZ(5)]]
|
| 422 |
+
|
| 423 |
+
|
| 424 |
+
def test_dup_sub_mul():
|
| 425 |
+
assert dup_sub_mul([ZZ(1), ZZ(2), ZZ(3)], [ZZ(3), ZZ(2), ZZ(1)],
|
| 426 |
+
[ZZ(1), ZZ(2)], ZZ) == [ZZ(-3), ZZ(-7), ZZ(-3), ZZ(1)]
|
| 427 |
+
assert dmp_sub_mul([[ZZ(1), ZZ(2)], [ZZ(3)]], [[ZZ(3)], [ZZ(2), ZZ(1)]],
|
| 428 |
+
[[ZZ(1)], [ZZ(2)]], 1, ZZ) == [[ZZ(-3)], [ZZ(-1), ZZ(-5)], [ZZ(-4), ZZ(1)]]
|
| 429 |
+
|
| 430 |
+
|
| 431 |
+
def test_dup_mul():
|
| 432 |
+
assert dup_mul([], [], ZZ) == []
|
| 433 |
+
assert dup_mul([], [ZZ(1)], ZZ) == []
|
| 434 |
+
assert dup_mul([ZZ(1)], [], ZZ) == []
|
| 435 |
+
assert dup_mul([ZZ(1)], [ZZ(1)], ZZ) == [ZZ(1)]
|
| 436 |
+
assert dup_mul([ZZ(5)], [ZZ(7)], ZZ) == [ZZ(35)]
|
| 437 |
+
|
| 438 |
+
assert dup_mul([], [], QQ) == []
|
| 439 |
+
assert dup_mul([], [QQ(1, 2)], QQ) == []
|
| 440 |
+
assert dup_mul([QQ(1, 2)], [], QQ) == []
|
| 441 |
+
assert dup_mul([QQ(1, 2)], [QQ(4, 7)], QQ) == [QQ(2, 7)]
|
| 442 |
+
assert dup_mul([QQ(5, 7)], [QQ(3, 7)], QQ) == [QQ(15, 49)]
|
| 443 |
+
|
| 444 |
+
f = dup_normal([3, 0, 0, 6, 1, 2], ZZ)
|
| 445 |
+
g = dup_normal([4, 0, 1, 0], ZZ)
|
| 446 |
+
h = dup_normal([12, 0, 3, 24, 4, 14, 1, 2, 0], ZZ)
|
| 447 |
+
|
| 448 |
+
assert dup_mul(f, g, ZZ) == h
|
| 449 |
+
assert dup_mul(g, f, ZZ) == h
|
| 450 |
+
|
| 451 |
+
f = dup_normal([2, 0, 0, 1, 7], ZZ)
|
| 452 |
+
h = dup_normal([4, 0, 0, 4, 28, 0, 1, 14, 49], ZZ)
|
| 453 |
+
|
| 454 |
+
assert dup_mul(f, f, ZZ) == h
|
| 455 |
+
|
| 456 |
+
K = FF(6)
|
| 457 |
+
|
| 458 |
+
assert dup_mul([K(2), K(1)], [K(3), K(4)], K) == [K(5), K(4)]
|
| 459 |
+
|
| 460 |
+
p1 = dup_normal([79, -1, 78, -94, -10, 11, 32, -19, 78, 2, -89, 30, 73, 42,
|
| 461 |
+
85, 77, 83, -30, -34, -2, 95, -81, 37, -49, -46, -58, -16, 37, 35, -11,
|
| 462 |
+
-57, -15, -31, 67, -20, 27, 76, 2, 70, 67, -65, 65, -26, -93, -44, -12,
|
| 463 |
+
-92, 57, -90, -57, -11, -67, -98, -69, 97, -41, 89, 33, 89, -50, 81,
|
| 464 |
+
-31, 60, -27, 43, 29, -77, 44, 21, -91, 32, -57, 33, 3, 53, -51, -38,
|
| 465 |
+
-99, -84, 23, -50, 66, -100, 1, -75, -25, 27, -60, 98, -51, -87, 6, 8,
|
| 466 |
+
78, -28, -95, -88, 12, -35, 26, -9, 16, -92, 55, -7, -86, 68, -39, -46,
|
| 467 |
+
84, 94, 45, 60, 92, 68, -75, -74, -19, 8, 75, 78, 91, 57, 34, 14, -3,
|
| 468 |
+
-49, 65, 78, -18, 6, -29, -80, -98, 17, 13, 58, 21, 20, 9, 37, 7, -30,
|
| 469 |
+
-53, -20, 34, 67, -42, 89, -22, 73, 43, -6, 5, 51, -8, -15, -52, -22,
|
| 470 |
+
-58, -72, -3, 43, -92, 82, 83, -2, -13, -23, -60, 16, -94, -8, -28,
|
| 471 |
+
-95, -72, 63, -90, 76, 6, -43, -100, -59, 76, 3, 3, 46, -85, 75, 62,
|
| 472 |
+
-71, -76, 88, 97, -72, -1, 30, -64, 72, -48, 14, -78, 58, 63, -91, 24,
|
| 473 |
+
-87, -27, -80, -100, -44, 98, 70, 100, -29, -38, 11, 77, 100, 52, 86,
|
| 474 |
+
65, -5, -42, -81, -38, -42, 43, -2, -70, -63, -52], ZZ)
|
| 475 |
+
p2 = dup_normal([65, -19, -47, 1, 90, 81, -15, -34, 25, -75, 9, -83, 50, -5,
|
| 476 |
+
-44, 31, 1, 70, -7, 78, 74, 80, 85, 65, 21, 41, 66, 19, -40, 63, -21,
|
| 477 |
+
-27, 32, 69, 83, 34, -35, 14, 81, 57, -75, 32, -67, -89, -100, -61, 46,
|
| 478 |
+
84, -78, -29, -50, -94, -24, -32, -68, -16, 100, -7, -72, -89, 35, 82,
|
| 479 |
+
58, 81, -92, 62, 5, -47, -39, -58, -72, -13, 84, 44, 55, -25, 48, -54,
|
| 480 |
+
-31, -56, -11, -50, -84, 10, 67, 17, 13, -14, 61, 76, -64, -44, -40,
|
| 481 |
+
-96, 11, -11, -94, 2, 6, 27, -6, 68, -54, 66, -74, -14, -1, -24, -73,
|
| 482 |
+
96, 89, -11, -89, 56, -53, 72, -43, 96, 25, 63, -31, 29, 68, 83, 91,
|
| 483 |
+
-93, -19, -38, -40, 40, -12, -19, -79, 44, 100, -66, -29, -77, 62, 39,
|
| 484 |
+
-8, 11, -97, 14, 87, 64, 21, -18, 13, 15, -59, -75, -99, -88, 57, 54,
|
| 485 |
+
56, -67, 6, -63, -59, -14, 28, 87, -20, -39, 84, -91, -2, 49, -75, 11,
|
| 486 |
+
-24, -95, 36, 66, 5, 25, -72, -40, 86, 90, 37, -33, 57, -35, 29, -18,
|
| 487 |
+
4, -79, 64, -17, -27, 21, 29, -5, -44, -87, -24, 52, 78, 11, -23, -53,
|
| 488 |
+
36, 42, 21, -68, 94, -91, -51, -21, 51, -76, 72, 31, 24, -48, -80, -9,
|
| 489 |
+
37, -47, -6, -8, -63, -91, 79, -79, -100, 38, -20, 38, 100, 83, -90,
|
| 490 |
+
87, 63, -36, 82, -19, 18, -98, -38, 26, 98, -70, 79, 92, 12, 12, 70,
|
| 491 |
+
74, 36, 48, -13, 31, 31, -47, -71, -12, -64, 36, -42, 32, -86, 60, 83,
|
| 492 |
+
70, 55, 0, 1, 29, -35, 8, -82, 8, -73, -46, -50, 43, 48, -5, -86, -72,
|
| 493 |
+
44, -90, 19, 19, 5, -20, 97, -13, -66, -5, 5, -69, 64, -30, 41, 51, 36,
|
| 494 |
+
13, -99, -61, 94, -12, 74, 98, 68, 24, 46, -97, -87, -6, -27, 82, 62,
|
| 495 |
+
-11, -77, 86, 66, -47, -49, -50, 13, 18, 89, -89, 46, -80, 13, 98, -35,
|
| 496 |
+
-36, -25, 12, 20, 26, -52, 79, 27, 79, 100, 8, 62, -58, -28, 37], ZZ)
|
| 497 |
+
res = dup_normal([5135, -1566, 1376, -7466, 4579, 11710, 8001, -7183,
|
| 498 |
+
-3737, -7439, 345, -10084, 24522, -1201, 1070, -10245, 9582, 9264,
|
| 499 |
+
1903, 23312, 18953, 10037, -15268, -5450, 6442, -6243, -3777, 5110,
|
| 500 |
+
10936, -16649, -6022, 16255, 31300, 24818, 31922, 32760, 7854, 27080,
|
| 501 |
+
15766, 29596, 7139, 31945, -19810, 465, -38026, -3971, 9641, 465,
|
| 502 |
+
-19375, 5524, -30112, -11960, -12813, 13535, 30670, 5925, -43725,
|
| 503 |
+
-14089, 11503, -22782, 6371, 43881, 37465, -33529, -33590, -39798,
|
| 504 |
+
-37854, -18466, -7908, -35825, -26020, -36923, -11332, -5699, 25166,
|
| 505 |
+
-3147, 19885, 12962, -20659, -1642, 27723, -56331, -24580, -11010,
|
| 506 |
+
-20206, 20087, -23772, -16038, 38580, 20901, -50731, 32037, -4299,
|
| 507 |
+
26508, 18038, -28357, 31846, -7405, -20172, -15894, 2096, 25110,
|
| 508 |
+
-45786, 45918, -55333, -31928, -49428, -29824, -58796, -24609, -15408,
|
| 509 |
+
69, -35415, -18439, 10123, -20360, -65949, 33356, -20333, 26476,
|
| 510 |
+
-32073, 33621, 930, 28803, -42791, 44716, 38164, 12302, -1739, 11421,
|
| 511 |
+
73385, -7613, 14297, 38155, -414, 77587, 24338, -21415, 29367, 42639,
|
| 512 |
+
13901, -288, 51027, -11827, 91260, 43407, 88521, -15186, 70572, -12049,
|
| 513 |
+
5090, -12208, -56374, 15520, -623, -7742, 50825, 11199, -14894, 40892,
|
| 514 |
+
59591, -31356, -28696, -57842, -87751, -33744, -28436, -28945, -40287,
|
| 515 |
+
37957, -35638, 33401, -61534, 14870, 40292, 70366, -10803, 102290,
|
| 516 |
+
-71719, -85251, 7902, -22409, 75009, 99927, 35298, -1175, -762, -34744,
|
| 517 |
+
-10587, -47574, -62629, -19581, -43659, -54369, -32250, -39545, 15225,
|
| 518 |
+
-24454, 11241, -67308, -30148, 39929, 37639, 14383, -73475, -77636,
|
| 519 |
+
-81048, -35992, 41601, -90143, 76937, -8112, 56588, 9124, -40094,
|
| 520 |
+
-32340, 13253, 10898, -51639, 36390, 12086, -1885, 100714, -28561,
|
| 521 |
+
-23784, -18735, 18916, 16286, 10742, -87360, -13697, 10689, -19477,
|
| 522 |
+
-29770, 5060, 20189, -8297, 112407, 47071, 47743, 45519, -4109, 17468,
|
| 523 |
+
-68831, 78325, -6481, -21641, -19459, 30919, 96115, 8607, 53341, 32105,
|
| 524 |
+
-16211, 23538, 57259, -76272, -40583, 62093, 38511, -34255, -40665,
|
| 525 |
+
-40604, -37606, -15274, 33156, -13885, 103636, 118678, -14101, -92682,
|
| 526 |
+
-100791, 2634, 63791, 98266, 19286, -34590, -21067, -71130, 25380,
|
| 527 |
+
-40839, -27614, -26060, 52358, -15537, 27138, -6749, 36269, -33306,
|
| 528 |
+
13207, -91084, -5540, -57116, 69548, 44169, -57742, -41234, -103327,
|
| 529 |
+
-62904, -8566, 41149, -12866, 71188, 23980, 1838, 58230, 73950, 5594,
|
| 530 |
+
43113, -8159, -15925, 6911, 85598, -75016, -16214, -62726, -39016,
|
| 531 |
+
8618, -63882, -4299, 23182, 49959, 49342, -3238, -24913, -37138, 78361,
|
| 532 |
+
32451, 6337, -11438, -36241, -37737, 8169, -3077, -24829, 57953, 53016,
|
| 533 |
+
-31511, -91168, 12599, -41849, 41576, 55275, -62539, 47814, -62319,
|
| 534 |
+
12300, -32076, -55137, -84881, -27546, 4312, -3433, -54382, 113288,
|
| 535 |
+
-30157, 74469, 18219, 79880, -2124, 98911, 17655, -33499, -32861,
|
| 536 |
+
47242, -37393, 99765, 14831, -44483, 10800, -31617, -52710, 37406,
|
| 537 |
+
22105, 29704, -20050, 13778, 43683, 36628, 8494, 60964, -22644, 31550,
|
| 538 |
+
-17693, 33805, -124879, -12302, 19343, 20400, -30937, -21574, -34037,
|
| 539 |
+
-33380, 56539, -24993, -75513, -1527, 53563, 65407, -101, 53577, 37991,
|
| 540 |
+
18717, -23795, -8090, -47987, -94717, 41967, 5170, -14815, -94311,
|
| 541 |
+
17896, -17734, -57718, -774, -38410, 24830, 29682, 76480, 58802,
|
| 542 |
+
-46416, -20348, -61353, -68225, -68306, 23822, -31598, 42972, 36327,
|
| 543 |
+
28968, -65638, -21638, 24354, -8356, 26777, 52982, -11783, -44051,
|
| 544 |
+
-26467, -44721, -28435, -53265, -25574, -2669, 44155, 22946, -18454,
|
| 545 |
+
-30718, -11252, 58420, 8711, 67447, 4425, 41749, 67543, 43162, 11793,
|
| 546 |
+
-41907, 20477, -13080, 6559, -6104, -13244, 42853, 42935, 29793, 36730,
|
| 547 |
+
-28087, 28657, 17946, 7503, 7204, 21491, -27450, -24241, -98156,
|
| 548 |
+
-18082, -42613, -24928, 10775, -14842, -44127, 55910, 14777, 31151, -2194,
|
| 549 |
+
39206, -2100, -4211, 11827, -8918, -19471, 72567, 36447, -65590, -34861,
|
| 550 |
+
-17147, -45303, 9025, -7333, -35473, 11101, 11638, 3441, 6626, -41800,
|
| 551 |
+
9416, 13679, 33508, 40502, -60542, 16358, 8392, -43242, -35864, -34127,
|
| 552 |
+
-48721, 35878, 30598, 28630, 20279, -19983, -14638, -24455, -1851, -11344,
|
| 553 |
+
45150, 42051, 26034, -28889, -32382, -3527, -14532, 22564, -22346, 477,
|
| 554 |
+
11706, 28338, -25972, -9185, -22867, -12522, 32120, -4424, 11339, -33913,
|
| 555 |
+
-7184, 5101, -23552, -17115, -31401, -6104, 21906, 25708, 8406, 6317,
|
| 556 |
+
-7525, 5014, 20750, 20179, 22724, 11692, 13297, 2493, -253, -16841, -17339,
|
| 557 |
+
-6753, -4808, 2976, -10881, -10228, -13816, -12686, 1385, 2316, 2190, -875,
|
| 558 |
+
-1924], ZZ)
|
| 559 |
+
|
| 560 |
+
assert dup_mul(p1, p2, ZZ) == res
|
| 561 |
+
|
| 562 |
+
p1 = dup_normal([83, -61, -86, -24, 12, 43, -88, -9, 42, 55, -66, 74, 95,
|
| 563 |
+
-25, -12, 68, -99, 4, 45, 6, -15, -19, 78, 65, -55, 47, -13, 17, 86,
|
| 564 |
+
81, -58, -27, 50, -40, -24, 39, -41, -92, 75, 90, -1, 40, -15, -27,
|
| 565 |
+
-35, 68, 70, -64, -40, 78, -88, -58, -39, 69, 46, 12, 28, -94, -37,
|
| 566 |
+
-50, -80, -96, -61, 25, 1, 71, 4, 12, 48, 4, 34, -47, -75, 5, 48, 82,
|
| 567 |
+
88, 23, 98, 35, 17, -10, 48, -61, -95, 47, 65, -19, -66, -57, -6, -51,
|
| 568 |
+
-42, -89, 66, -13, 18, 37, 90, -23, 72, 96, -53, 0, 40, -73, -52, -68,
|
| 569 |
+
32, -25, -53, 79, -52, 18, 44, 73, -81, 31, -90, 70, 3, 36, 48, 76,
|
| 570 |
+
-24, -44, 23, 98, -4, 73, 69, 88, -70, 14, -68, 94, -78, -15, -64, -97,
|
| 571 |
+
-70, -35, 65, 88, 49, -53, -7, 12, -45, -7, 59, -94, 99, -2, 67, -60,
|
| 572 |
+
-71, 29, -62, -77, 1, 51, 17, 80, -20, -47, -19, 24, -9, 39, -23, 21,
|
| 573 |
+
-84, 10, 84, 56, -17, -21, -66, 85, 70, 46, -51, -22, -95, 78, -60,
|
| 574 |
+
-96, -97, -45, 72, 35, 30, -61, -92, -93, -60, -61, 4, -4, -81, -73,
|
| 575 |
+
46, 53, -11, 26, 94, 45, 14, -78, 55, 84, -68, 98, 60, 23, 100, -63,
|
| 576 |
+
68, 96, -16, 3, 56, 21, -58, 62, -67, 66, 85, 41, -79, -22, 97, -67,
|
| 577 |
+
82, 82, -96, -20, -7, 48, -67, 48, -9, -39, 78], ZZ)
|
| 578 |
+
p2 = dup_normal([52, 88, 76, 66, 9, -64, 46, -20, -28, 69, 60, 96, -36,
|
| 579 |
+
-92, -30, -11, -35, 35, 55, 63, -92, -7, 25, -58, 74, 55, -6, 4, 47,
|
| 580 |
+
-92, -65, 67, -45, 74, -76, 59, -6, 69, 39, 24, -71, -7, 39, -45, 60,
|
| 581 |
+
-68, 98, 97, -79, 17, 4, 94, -64, 68, -100, -96, -2, 3, 22, 96, 54,
|
| 582 |
+
-77, -86, 67, 6, 57, 37, 40, 89, -78, 64, -94, -45, -92, 57, 87, -26,
|
| 583 |
+
36, 19, 97, 25, 77, -87, 24, 43, -5, 35, 57, 83, 71, 35, 63, 61, 96,
|
| 584 |
+
-22, 8, -1, 96, 43, 45, 94, -93, 36, 71, -41, -99, 85, -48, 59, 52,
|
| 585 |
+
-17, 5, 87, -16, -68, -54, 76, -18, 100, 91, -42, -70, -66, -88, -12,
|
| 586 |
+
1, 95, -82, 52, 43, -29, 3, 12, 72, -99, -43, -32, -93, -51, 16, -20,
|
| 587 |
+
-12, -11, 5, 33, -38, 93, -5, -74, 25, 74, -58, 93, 59, -63, -86, 63,
|
| 588 |
+
-20, -4, -74, -73, -95, 29, -28, 93, -91, -2, -38, -62, 77, -58, -85,
|
| 589 |
+
-28, 95, 38, 19, -69, 86, 94, 25, -2, -4, 47, 34, -59, 35, -48, 29,
|
| 590 |
+
-63, -53, 34, 29, 66, 73, 6, 92, -84, 89, 15, 81, 93, 97, 51, -72, -78,
|
| 591 |
+
25, 60, 90, -45, 39, 67, -84, -62, 57, 26, -32, -56, -14, -83, 76, 5,
|
| 592 |
+
-2, 99, -100, 28, 46, 94, -7, 53, -25, 16, -23, -36, 89, -78, -63, 31,
|
| 593 |
+
1, 84, -99, -52, 76, 48, 90, -76, 44, -19, 54, -36, -9, -73, -100, -69,
|
| 594 |
+
31, 42, 25, -39, 76, -26, -8, -14, 51, 3, 37, 45, 2, -54, 13, -34, -92,
|
| 595 |
+
17, -25, -65, 53, -63, 30, 4, -70, -67, 90, 52, 51, 18, -3, 31, -45,
|
| 596 |
+
-9, 59, 63, -87, 22, -32, 29, -38, 21, 36, -82, 27, -11], ZZ)
|
| 597 |
+
res = dup_normal([4316, 4132, -3532, -7974, -11303, -10069, 5484, -3330,
|
| 598 |
+
-5874, 7734, 4673, 11327, -9884, -8031, 17343, 21035, -10570, -9285,
|
| 599 |
+
15893, 3780, -14083, 8819, 17592, 10159, 7174, -11587, 8598, -16479,
|
| 600 |
+
3602, 25596, 9781, 12163, 150, 18749, -21782, -12307, 27578, -2757,
|
| 601 |
+
-12573, 12565, 6345, -18956, 19503, -15617, 1443, -16778, 36851, 23588,
|
| 602 |
+
-28474, 5749, 40695, -7521, -53669, -2497, -18530, 6770, 57038, 3926,
|
| 603 |
+
-6927, -15399, 1848, -64649, -27728, 3644, 49608, 15187, -8902, -9480,
|
| 604 |
+
-7398, -40425, 4824, 23767, -7594, -6905, 33089, 18786, 12192, 24670,
|
| 605 |
+
31114, 35334, -4501, -14676, 7107, -59018, -21352, 20777, 19661, 20653,
|
| 606 |
+
33754, -885, -43758, 6269, 51897, -28719, -97488, -9527, 13746, 11644,
|
| 607 |
+
17644, -21720, 23782, -10481, 47867, 20752, 33810, -1875, 39918, -7710,
|
| 608 |
+
-40840, 19808, -47075, 23066, 46616, 25201, 9287, 35436, -1602, 9645,
|
| 609 |
+
-11978, 13273, 15544, 33465, 20063, 44539, 11687, 27314, -6538, -37467,
|
| 610 |
+
14031, 32970, -27086, 41323, 29551, 65910, -39027, -37800, -22232,
|
| 611 |
+
8212, 46316, -28981, -55282, 50417, -44929, -44062, 73879, 37573,
|
| 612 |
+
-2596, -10877, -21893, -133218, -33707, -25753, -9531, 17530, 61126,
|
| 613 |
+
2748, -56235, 43874, -10872, -90459, -30387, 115267, -7264, -44452,
|
| 614 |
+
122626, 14839, -599, 10337, 57166, -67467, -54957, 63669, 1202, 18488,
|
| 615 |
+
52594, 7205, -97822, 612, 78069, -5403, -63562, 47236, 36873, -154827,
|
| 616 |
+
-26188, 82427, -39521, 5628, 7416, 5276, -53095, 47050, 26121, -42207,
|
| 617 |
+
79021, -13035, 2499, -66943, 29040, -72355, -23480, 23416, -12885,
|
| 618 |
+
-44225, -42688, -4224, 19858, 55299, 15735, 11465, 101876, -39169,
|
| 619 |
+
51786, 14723, 43280, -68697, 16410, 92295, 56767, 7183, 111850, 4550,
|
| 620 |
+
115451, -38443, -19642, -35058, 10230, 93829, 8925, 63047, 3146, 29250,
|
| 621 |
+
8530, 5255, -98117, -115517, -76817, -8724, 41044, 1312, -35974, 79333,
|
| 622 |
+
-28567, 7547, -10580, -24559, -16238, 10794, -3867, 24848, 57770,
|
| 623 |
+
-51536, -35040, 71033, 29853, 62029, -7125, -125585, -32169, -47907,
|
| 624 |
+
156811, -65176, -58006, -15757, -57861, 11963, 30225, -41901, -41681,
|
| 625 |
+
31310, 27982, 18613, 61760, 60746, -59096, 33499, 30097, -17997, 24032,
|
| 626 |
+
56442, -83042, 23747, -20931, -21978, -158752, -9883, -73598, -7987,
|
| 627 |
+
-7333, -125403, -116329, 30585, 53281, 51018, -29193, 88575, 8264,
|
| 628 |
+
-40147, -16289, 113088, 12810, -6508, 101552, -13037, 34440, -41840,
|
| 629 |
+
101643, 24263, 80532, 61748, 65574, 6423, -20672, 6591, -10834, -71716,
|
| 630 |
+
86919, -92626, 39161, 28490, 81319, 46676, 106720, 43530, 26998, 57456,
|
| 631 |
+
-8862, 60989, 13982, 3119, -2224, 14743, 55415, -49093, -29303, 28999,
|
| 632 |
+
1789, 55953, -84043, -7780, -65013, 57129, -47251, 61484, 61994,
|
| 633 |
+
-78361, -82778, 22487, -26894, 9756, -74637, -15519, -4360, 30115,
|
| 634 |
+
42433, 35475, 15286, 69768, 21509, -20214, 78675, -21163, 13596, 11443,
|
| 635 |
+
-10698, -53621, -53867, -24155, 64500, -42784, -33077, -16500, 873,
|
| 636 |
+
-52788, 14546, -38011, 36974, -39849, -34029, -94311, 83068, -50437,
|
| 637 |
+
-26169, -46746, 59185, 42259, -101379, -12943, 30089, -59086, 36271,
|
| 638 |
+
22723, -30253, -52472, -70826, -23289, 3331, -31687, 14183, -857,
|
| 639 |
+
-28627, 35246, -51284, 5636, -6933, 66539, 36654, 50927, 24783, 3457,
|
| 640 |
+
33276, 45281, 45650, -4938, -9968, -22590, 47995, 69229, 5214, -58365,
|
| 641 |
+
-17907, -14651, 18668, 18009, 12649, -11851, -13387, 20339, 52472,
|
| 642 |
+
-1087, -21458, -68647, 52295, 15849, 40608, 15323, 25164, -29368,
|
| 643 |
+
10352, -7055, 7159, 21695, -5373, -54849, 101103, -24963, -10511,
|
| 644 |
+
33227, 7659, 41042, -69588, 26718, -20515, 6441, 38135, -63, 24088,
|
| 645 |
+
-35364, -12785, -18709, 47843, 48533, -48575, 17251, -19394, 32878,
|
| 646 |
+
-9010, -9050, 504, -12407, 28076, -3429, 25324, -4210, -26119, 752,
|
| 647 |
+
-29203, 28251, -11324, -32140, -3366, -25135, 18702, -31588, -7047,
|
| 648 |
+
-24267, 49987, -14975, -33169, 37744, -7720, -9035, 16964, -2807, -421,
|
| 649 |
+
14114, -17097, -13662, 40628, -12139, -9427, 5369, 17551, -13232, -16211,
|
| 650 |
+
9804, -7422, 2677, 28635, -8280, -4906, 2908, -22558, 5604, 12459, 8756,
|
| 651 |
+
-3980, -4745, -18525, 7913, 5970, -16457, 20230, -6247, -13812, 2505,
|
| 652 |
+
11899, 1409, -15094, 22540, -18863, 137, 11123, -4516, 2290, -8594, 12150,
|
| 653 |
+
-10380, 3005, 5235, -7350, 2535, -858], ZZ)
|
| 654 |
+
|
| 655 |
+
assert dup_mul(p1, p2, ZZ) == res
|
| 656 |
+
|
| 657 |
+
|
| 658 |
+
def test_dmp_mul():
|
| 659 |
+
assert dmp_mul([ZZ(5)], [ZZ(7)], 0, ZZ) == \
|
| 660 |
+
dup_mul([ZZ(5)], [ZZ(7)], ZZ)
|
| 661 |
+
assert dmp_mul([QQ(5, 7)], [QQ(3, 7)], 0, QQ) == \
|
| 662 |
+
dup_mul([QQ(5, 7)], [QQ(3, 7)], QQ)
|
| 663 |
+
|
| 664 |
+
assert dmp_mul([[[]]], [[[]]], 2, ZZ) == [[[]]]
|
| 665 |
+
assert dmp_mul([[[ZZ(1)]]], [[[]]], 2, ZZ) == [[[]]]
|
| 666 |
+
assert dmp_mul([[[]]], [[[ZZ(1)]]], 2, ZZ) == [[[]]]
|
| 667 |
+
assert dmp_mul([[[ZZ(2)]]], [[[ZZ(1)]]], 2, ZZ) == [[[ZZ(2)]]]
|
| 668 |
+
assert dmp_mul([[[ZZ(1)]]], [[[ZZ(2)]]], 2, ZZ) == [[[ZZ(2)]]]
|
| 669 |
+
|
| 670 |
+
assert dmp_mul([[[]]], [[[]]], 2, QQ) == [[[]]]
|
| 671 |
+
assert dmp_mul([[[QQ(1, 2)]]], [[[]]], 2, QQ) == [[[]]]
|
| 672 |
+
assert dmp_mul([[[]]], [[[QQ(1, 2)]]], 2, QQ) == [[[]]]
|
| 673 |
+
assert dmp_mul([[[QQ(2, 7)]]], [[[QQ(1, 3)]]], 2, QQ) == [[[QQ(2, 21)]]]
|
| 674 |
+
assert dmp_mul([[[QQ(1, 7)]]], [[[QQ(2, 3)]]], 2, QQ) == [[[QQ(2, 21)]]]
|
| 675 |
+
|
| 676 |
+
K = FF(6)
|
| 677 |
+
|
| 678 |
+
assert dmp_mul(
|
| 679 |
+
[[K(2)], [K(1)]], [[K(3)], [K(4)]], 1, K) == [[K(5)], [K(4)]]
|
| 680 |
+
|
| 681 |
+
|
| 682 |
+
def test_dup_sqr():
|
| 683 |
+
assert dup_sqr([], ZZ) == []
|
| 684 |
+
assert dup_sqr([ZZ(2)], ZZ) == [ZZ(4)]
|
| 685 |
+
assert dup_sqr([ZZ(1), ZZ(2)], ZZ) == [ZZ(1), ZZ(4), ZZ(4)]
|
| 686 |
+
|
| 687 |
+
assert dup_sqr([], QQ) == []
|
| 688 |
+
assert dup_sqr([QQ(2, 3)], QQ) == [QQ(4, 9)]
|
| 689 |
+
assert dup_sqr([QQ(1, 3), QQ(2, 3)], QQ) == [QQ(1, 9), QQ(4, 9), QQ(4, 9)]
|
| 690 |
+
|
| 691 |
+
f = dup_normal([2, 0, 0, 1, 7], ZZ)
|
| 692 |
+
|
| 693 |
+
assert dup_sqr(f, ZZ) == dup_normal([4, 0, 0, 4, 28, 0, 1, 14, 49], ZZ)
|
| 694 |
+
|
| 695 |
+
K = FF(9)
|
| 696 |
+
|
| 697 |
+
assert dup_sqr([K(3), K(4)], K) == [K(6), K(7)]
|
| 698 |
+
|
| 699 |
+
|
| 700 |
+
def test_dmp_sqr():
|
| 701 |
+
assert dmp_sqr([ZZ(1), ZZ(2)], 0, ZZ) == \
|
| 702 |
+
dup_sqr([ZZ(1), ZZ(2)], ZZ)
|
| 703 |
+
|
| 704 |
+
assert dmp_sqr([[[]]], 2, ZZ) == [[[]]]
|
| 705 |
+
assert dmp_sqr([[[ZZ(2)]]], 2, ZZ) == [[[ZZ(4)]]]
|
| 706 |
+
|
| 707 |
+
assert dmp_sqr([[[]]], 2, QQ) == [[[]]]
|
| 708 |
+
assert dmp_sqr([[[QQ(2, 3)]]], 2, QQ) == [[[QQ(4, 9)]]]
|
| 709 |
+
|
| 710 |
+
K = FF(9)
|
| 711 |
+
|
| 712 |
+
assert dmp_sqr([[K(3)], [K(4)]], 1, K) == [[K(6)], [K(7)]]
|
| 713 |
+
|
| 714 |
+
|
| 715 |
+
def test_dup_pow():
|
| 716 |
+
assert dup_pow([], 0, ZZ) == [ZZ(1)]
|
| 717 |
+
assert dup_pow([], 0, QQ) == [QQ(1)]
|
| 718 |
+
|
| 719 |
+
assert dup_pow([], 1, ZZ) == []
|
| 720 |
+
assert dup_pow([], 7, ZZ) == []
|
| 721 |
+
|
| 722 |
+
assert dup_pow([ZZ(1)], 0, ZZ) == [ZZ(1)]
|
| 723 |
+
assert dup_pow([ZZ(1)], 1, ZZ) == [ZZ(1)]
|
| 724 |
+
assert dup_pow([ZZ(1)], 7, ZZ) == [ZZ(1)]
|
| 725 |
+
|
| 726 |
+
assert dup_pow([ZZ(3)], 0, ZZ) == [ZZ(1)]
|
| 727 |
+
assert dup_pow([ZZ(3)], 1, ZZ) == [ZZ(3)]
|
| 728 |
+
assert dup_pow([ZZ(3)], 7, ZZ) == [ZZ(2187)]
|
| 729 |
+
|
| 730 |
+
assert dup_pow([QQ(1, 1)], 0, QQ) == [QQ(1, 1)]
|
| 731 |
+
assert dup_pow([QQ(1, 1)], 1, QQ) == [QQ(1, 1)]
|
| 732 |
+
assert dup_pow([QQ(1, 1)], 7, QQ) == [QQ(1, 1)]
|
| 733 |
+
|
| 734 |
+
assert dup_pow([QQ(3, 7)], 0, QQ) == [QQ(1, 1)]
|
| 735 |
+
assert dup_pow([QQ(3, 7)], 1, QQ) == [QQ(3, 7)]
|
| 736 |
+
assert dup_pow([QQ(3, 7)], 7, QQ) == [QQ(2187, 823543)]
|
| 737 |
+
|
| 738 |
+
f = dup_normal([2, 0, 0, 1, 7], ZZ)
|
| 739 |
+
|
| 740 |
+
assert dup_pow(f, 0, ZZ) == dup_normal([1], ZZ)
|
| 741 |
+
assert dup_pow(f, 1, ZZ) == dup_normal([2, 0, 0, 1, 7], ZZ)
|
| 742 |
+
assert dup_pow(f, 2, ZZ) == dup_normal([4, 0, 0, 4, 28, 0, 1, 14, 49], ZZ)
|
| 743 |
+
assert dup_pow(f, 3, ZZ) == dup_normal(
|
| 744 |
+
[8, 0, 0, 12, 84, 0, 6, 84, 294, 1, 21, 147, 343], ZZ)
|
| 745 |
+
|
| 746 |
+
|
| 747 |
+
def test_dmp_pow():
|
| 748 |
+
assert dmp_pow([[]], 0, 1, ZZ) == [[ZZ(1)]]
|
| 749 |
+
assert dmp_pow([[]], 0, 1, QQ) == [[QQ(1)]]
|
| 750 |
+
|
| 751 |
+
assert dmp_pow([[]], 1, 1, ZZ) == [[]]
|
| 752 |
+
assert dmp_pow([[]], 7, 1, ZZ) == [[]]
|
| 753 |
+
|
| 754 |
+
assert dmp_pow([[ZZ(1)]], 0, 1, ZZ) == [[ZZ(1)]]
|
| 755 |
+
assert dmp_pow([[ZZ(1)]], 1, 1, ZZ) == [[ZZ(1)]]
|
| 756 |
+
assert dmp_pow([[ZZ(1)]], 7, 1, ZZ) == [[ZZ(1)]]
|
| 757 |
+
|
| 758 |
+
assert dmp_pow([[QQ(3, 7)]], 0, 1, QQ) == [[QQ(1, 1)]]
|
| 759 |
+
assert dmp_pow([[QQ(3, 7)]], 1, 1, QQ) == [[QQ(3, 7)]]
|
| 760 |
+
assert dmp_pow([[QQ(3, 7)]], 7, 1, QQ) == [[QQ(2187, 823543)]]
|
| 761 |
+
|
| 762 |
+
f = dup_normal([2, 0, 0, 1, 7], ZZ)
|
| 763 |
+
|
| 764 |
+
assert dmp_pow(f, 2, 0, ZZ) == dup_pow(f, 2, ZZ)
|
| 765 |
+
|
| 766 |
+
|
| 767 |
+
def test_dup_pdiv():
|
| 768 |
+
f = dup_normal([3, 1, 1, 5], ZZ)
|
| 769 |
+
g = dup_normal([5, -3, 1], ZZ)
|
| 770 |
+
|
| 771 |
+
q = dup_normal([15, 14], ZZ)
|
| 772 |
+
r = dup_normal([52, 111], ZZ)
|
| 773 |
+
|
| 774 |
+
assert dup_pdiv(f, g, ZZ) == (q, r)
|
| 775 |
+
assert dup_pquo(f, g, ZZ) == q
|
| 776 |
+
assert dup_prem(f, g, ZZ) == r
|
| 777 |
+
|
| 778 |
+
raises(ExactQuotientFailed, lambda: dup_pexquo(f, g, ZZ))
|
| 779 |
+
|
| 780 |
+
f = dup_normal([3, 1, 1, 5], QQ)
|
| 781 |
+
g = dup_normal([5, -3, 1], QQ)
|
| 782 |
+
|
| 783 |
+
q = dup_normal([15, 14], QQ)
|
| 784 |
+
r = dup_normal([52, 111], QQ)
|
| 785 |
+
|
| 786 |
+
assert dup_pdiv(f, g, QQ) == (q, r)
|
| 787 |
+
assert dup_pquo(f, g, QQ) == q
|
| 788 |
+
assert dup_prem(f, g, QQ) == r
|
| 789 |
+
|
| 790 |
+
raises(ExactQuotientFailed, lambda: dup_pexquo(f, g, QQ))
|
| 791 |
+
|
| 792 |
+
|
| 793 |
+
def test_dmp_pdiv():
|
| 794 |
+
f = dmp_normal([[1], [], [1, 0, 0]], 1, ZZ)
|
| 795 |
+
g = dmp_normal([[1], [-1, 0]], 1, ZZ)
|
| 796 |
+
|
| 797 |
+
q = dmp_normal([[1], [1, 0]], 1, ZZ)
|
| 798 |
+
r = dmp_normal([[2, 0, 0]], 1, ZZ)
|
| 799 |
+
|
| 800 |
+
assert dmp_pdiv(f, g, 1, ZZ) == (q, r)
|
| 801 |
+
assert dmp_pquo(f, g, 1, ZZ) == q
|
| 802 |
+
assert dmp_prem(f, g, 1, ZZ) == r
|
| 803 |
+
|
| 804 |
+
raises(ExactQuotientFailed, lambda: dmp_pexquo(f, g, 1, ZZ))
|
| 805 |
+
|
| 806 |
+
f = dmp_normal([[1], [], [1, 0, 0]], 1, ZZ)
|
| 807 |
+
g = dmp_normal([[2], [-2, 0]], 1, ZZ)
|
| 808 |
+
|
| 809 |
+
q = dmp_normal([[2], [2, 0]], 1, ZZ)
|
| 810 |
+
r = dmp_normal([[8, 0, 0]], 1, ZZ)
|
| 811 |
+
|
| 812 |
+
assert dmp_pdiv(f, g, 1, ZZ) == (q, r)
|
| 813 |
+
assert dmp_pquo(f, g, 1, ZZ) == q
|
| 814 |
+
assert dmp_prem(f, g, 1, ZZ) == r
|
| 815 |
+
|
| 816 |
+
raises(ExactQuotientFailed, lambda: dmp_pexquo(f, g, 1, ZZ))
|
| 817 |
+
|
| 818 |
+
|
| 819 |
+
def test_dup_rr_div():
|
| 820 |
+
raises(ZeroDivisionError, lambda: dup_rr_div([1, 2, 3], [], ZZ))
|
| 821 |
+
|
| 822 |
+
f = dup_normal([3, 1, 1, 5], ZZ)
|
| 823 |
+
g = dup_normal([5, -3, 1], ZZ)
|
| 824 |
+
|
| 825 |
+
q, r = [], f
|
| 826 |
+
|
| 827 |
+
assert dup_rr_div(f, g, ZZ) == (q, r)
|
| 828 |
+
|
| 829 |
+
|
| 830 |
+
def test_dmp_rr_div():
|
| 831 |
+
raises(ZeroDivisionError, lambda: dmp_rr_div([[1, 2], [3]], [[]], 1, ZZ))
|
| 832 |
+
|
| 833 |
+
f = dmp_normal([[1], [], [1, 0, 0]], 1, ZZ)
|
| 834 |
+
g = dmp_normal([[1], [-1, 0]], 1, ZZ)
|
| 835 |
+
|
| 836 |
+
q = dmp_normal([[1], [1, 0]], 1, ZZ)
|
| 837 |
+
r = dmp_normal([[2, 0, 0]], 1, ZZ)
|
| 838 |
+
|
| 839 |
+
assert dmp_rr_div(f, g, 1, ZZ) == (q, r)
|
| 840 |
+
|
| 841 |
+
f = dmp_normal([[1], [], [1, 0, 0]], 1, ZZ)
|
| 842 |
+
g = dmp_normal([[-1], [1, 0]], 1, ZZ)
|
| 843 |
+
|
| 844 |
+
q = dmp_normal([[-1], [-1, 0]], 1, ZZ)
|
| 845 |
+
r = dmp_normal([[2, 0, 0]], 1, ZZ)
|
| 846 |
+
|
| 847 |
+
assert dmp_rr_div(f, g, 1, ZZ) == (q, r)
|
| 848 |
+
|
| 849 |
+
f = dmp_normal([[1], [], [1, 0, 0]], 1, ZZ)
|
| 850 |
+
g = dmp_normal([[2], [-2, 0]], 1, ZZ)
|
| 851 |
+
|
| 852 |
+
q, r = [[]], f
|
| 853 |
+
|
| 854 |
+
assert dmp_rr_div(f, g, 1, ZZ) == (q, r)
|
| 855 |
+
|
| 856 |
+
|
| 857 |
+
def test_dup_ff_div():
|
| 858 |
+
raises(ZeroDivisionError, lambda: dup_ff_div([1, 2, 3], [], QQ))
|
| 859 |
+
|
| 860 |
+
f = dup_normal([3, 1, 1, 5], QQ)
|
| 861 |
+
g = dup_normal([5, -3, 1], QQ)
|
| 862 |
+
|
| 863 |
+
q = [QQ(3, 5), QQ(14, 25)]
|
| 864 |
+
r = [QQ(52, 25), QQ(111, 25)]
|
| 865 |
+
|
| 866 |
+
assert dup_ff_div(f, g, QQ) == (q, r)
|
| 867 |
+
|
| 868 |
+
def test_dup_ff_div_gmpy2():
|
| 869 |
+
if GROUND_TYPES != 'gmpy2':
|
| 870 |
+
return
|
| 871 |
+
|
| 872 |
+
from gmpy2 import mpq
|
| 873 |
+
from sympy.polys.domains import GMPYRationalField
|
| 874 |
+
K = GMPYRationalField()
|
| 875 |
+
|
| 876 |
+
f = [mpq(1,3), mpq(3,2)]
|
| 877 |
+
g = [mpq(2,1)]
|
| 878 |
+
assert dmp_ff_div(f, g, 0, K) == ([mpq(1,6), mpq(3,4)], [])
|
| 879 |
+
|
| 880 |
+
f = [mpq(1,2), mpq(1,3), mpq(1,4), mpq(1,5)]
|
| 881 |
+
g = [mpq(-1,1), mpq(1,1), mpq(-1,1)]
|
| 882 |
+
assert dmp_ff_div(f, g, 0, K) == ([mpq(-1,2), mpq(-5,6)], [mpq(7,12), mpq(-19,30)])
|
| 883 |
+
|
| 884 |
+
def test_dmp_ff_div():
|
| 885 |
+
raises(ZeroDivisionError, lambda: dmp_ff_div([[1, 2], [3]], [[]], 1, QQ))
|
| 886 |
+
|
| 887 |
+
f = dmp_normal([[1], [], [1, 0, 0]], 1, QQ)
|
| 888 |
+
g = dmp_normal([[1], [-1, 0]], 1, QQ)
|
| 889 |
+
|
| 890 |
+
q = [[QQ(1, 1)], [QQ(1, 1), QQ(0, 1)]]
|
| 891 |
+
r = [[QQ(2, 1), QQ(0, 1), QQ(0, 1)]]
|
| 892 |
+
|
| 893 |
+
assert dmp_ff_div(f, g, 1, QQ) == (q, r)
|
| 894 |
+
|
| 895 |
+
f = dmp_normal([[1], [], [1, 0, 0]], 1, QQ)
|
| 896 |
+
g = dmp_normal([[-1], [1, 0]], 1, QQ)
|
| 897 |
+
|
| 898 |
+
q = [[QQ(-1, 1)], [QQ(-1, 1), QQ(0, 1)]]
|
| 899 |
+
r = [[QQ(2, 1), QQ(0, 1), QQ(0, 1)]]
|
| 900 |
+
|
| 901 |
+
assert dmp_ff_div(f, g, 1, QQ) == (q, r)
|
| 902 |
+
|
| 903 |
+
f = dmp_normal([[1], [], [1, 0, 0]], 1, QQ)
|
| 904 |
+
g = dmp_normal([[2], [-2, 0]], 1, QQ)
|
| 905 |
+
|
| 906 |
+
q = [[QQ(1, 2)], [QQ(1, 2), QQ(0, 1)]]
|
| 907 |
+
r = [[QQ(2, 1), QQ(0, 1), QQ(0, 1)]]
|
| 908 |
+
|
| 909 |
+
assert dmp_ff_div(f, g, 1, QQ) == (q, r)
|
| 910 |
+
|
| 911 |
+
|
| 912 |
+
def test_dup_div():
|
| 913 |
+
f, g, q, r = [5, 4, 3, 2, 1], [1, 2, 3], [5, -6, 0], [20, 1]
|
| 914 |
+
|
| 915 |
+
assert dup_div(f, g, ZZ) == (q, r)
|
| 916 |
+
assert dup_quo(f, g, ZZ) == q
|
| 917 |
+
assert dup_rem(f, g, ZZ) == r
|
| 918 |
+
|
| 919 |
+
raises(ExactQuotientFailed, lambda: dup_exquo(f, g, ZZ))
|
| 920 |
+
|
| 921 |
+
f, g, q, r = [5, 4, 3, 2, 1, 0], [1, 2, 0, 0, 9], [5, -6], [15, 2, -44, 54]
|
| 922 |
+
|
| 923 |
+
assert dup_div(f, g, ZZ) == (q, r)
|
| 924 |
+
assert dup_quo(f, g, ZZ) == q
|
| 925 |
+
assert dup_rem(f, g, ZZ) == r
|
| 926 |
+
|
| 927 |
+
raises(ExactQuotientFailed, lambda: dup_exquo(f, g, ZZ))
|
| 928 |
+
|
| 929 |
+
|
| 930 |
+
def test_dmp_div():
|
| 931 |
+
f, g, q, r = [5, 4, 3, 2, 1], [1, 2, 3], [5, -6, 0], [20, 1]
|
| 932 |
+
|
| 933 |
+
assert dmp_div(f, g, 0, ZZ) == (q, r)
|
| 934 |
+
assert dmp_quo(f, g, 0, ZZ) == q
|
| 935 |
+
assert dmp_rem(f, g, 0, ZZ) == r
|
| 936 |
+
|
| 937 |
+
raises(ExactQuotientFailed, lambda: dmp_exquo(f, g, 0, ZZ))
|
| 938 |
+
|
| 939 |
+
f, g, q, r = [[[1]]], [[[2]], [1]], [[[]]], [[[1]]]
|
| 940 |
+
|
| 941 |
+
assert dmp_div(f, g, 2, ZZ) == (q, r)
|
| 942 |
+
assert dmp_quo(f, g, 2, ZZ) == q
|
| 943 |
+
assert dmp_rem(f, g, 2, ZZ) == r
|
| 944 |
+
|
| 945 |
+
raises(ExactQuotientFailed, lambda: dmp_exquo(f, g, 2, ZZ))
|
| 946 |
+
|
| 947 |
+
|
| 948 |
+
def test_dup_max_norm():
|
| 949 |
+
assert dup_max_norm([], ZZ) == 0
|
| 950 |
+
assert dup_max_norm([1], ZZ) == 1
|
| 951 |
+
|
| 952 |
+
assert dup_max_norm([1, 4, 2, 3], ZZ) == 4
|
| 953 |
+
|
| 954 |
+
|
| 955 |
+
def test_dmp_max_norm():
|
| 956 |
+
assert dmp_max_norm([[[]]], 2, ZZ) == 0
|
| 957 |
+
assert dmp_max_norm([[[1]]], 2, ZZ) == 1
|
| 958 |
+
|
| 959 |
+
assert dmp_max_norm(f_0, 2, ZZ) == 6
|
| 960 |
+
|
| 961 |
+
|
| 962 |
+
def test_dup_l1_norm():
|
| 963 |
+
assert dup_l1_norm([], ZZ) == 0
|
| 964 |
+
assert dup_l1_norm([1], ZZ) == 1
|
| 965 |
+
assert dup_l1_norm([1, 4, 2, 3], ZZ) == 10
|
| 966 |
+
|
| 967 |
+
|
| 968 |
+
def test_dmp_l1_norm():
|
| 969 |
+
assert dmp_l1_norm([[[]]], 2, ZZ) == 0
|
| 970 |
+
assert dmp_l1_norm([[[1]]], 2, ZZ) == 1
|
| 971 |
+
|
| 972 |
+
assert dmp_l1_norm(f_0, 2, ZZ) == 31
|
| 973 |
+
|
| 974 |
+
|
| 975 |
+
def test_dup_l2_norm_squared():
|
| 976 |
+
assert dup_l2_norm_squared([], ZZ) == 0
|
| 977 |
+
assert dup_l2_norm_squared([1], ZZ) == 1
|
| 978 |
+
assert dup_l2_norm_squared([1, 4, 2, 3], ZZ) == 30
|
| 979 |
+
|
| 980 |
+
|
| 981 |
+
def test_dmp_l2_norm_squared():
|
| 982 |
+
assert dmp_l2_norm_squared([[[]]], 2, ZZ) == 0
|
| 983 |
+
assert dmp_l2_norm_squared([[[1]]], 2, ZZ) == 1
|
| 984 |
+
assert dmp_l2_norm_squared(f_0, 2, ZZ) == 111
|
| 985 |
+
|
| 986 |
+
|
| 987 |
+
def test_dup_expand():
|
| 988 |
+
assert dup_expand((), ZZ) == [1]
|
| 989 |
+
assert dup_expand(([1, 2, 3], [1, 2], [7, 5, 4, 3]), ZZ) == \
|
| 990 |
+
dup_mul([1, 2, 3], dup_mul([1, 2], [7, 5, 4, 3], ZZ), ZZ)
|
| 991 |
+
|
| 992 |
+
|
| 993 |
+
def test_dmp_expand():
|
| 994 |
+
assert dmp_expand((), 1, ZZ) == [[1]]
|
| 995 |
+
assert dmp_expand(([[1], [2], [3]], [[1], [2]], [[7], [5], [4], [3]]), 1, ZZ) == \
|
| 996 |
+
dmp_mul([[1], [2], [3]], dmp_mul([[1], [2]], [[7], [5], [
|
| 997 |
+
4], [3]], 1, ZZ), 1, ZZ)
|
pllava/lib/python3.10/site-packages/sympy/polys/tests/test_densebasic.py
ADDED
|
@@ -0,0 +1,730 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for dense recursive polynomials' basic tools. """
|
| 2 |
+
|
| 3 |
+
from sympy.polys.densebasic import (
|
| 4 |
+
ninf,
|
| 5 |
+
dup_LC, dmp_LC,
|
| 6 |
+
dup_TC, dmp_TC,
|
| 7 |
+
dmp_ground_LC, dmp_ground_TC,
|
| 8 |
+
dmp_true_LT,
|
| 9 |
+
dup_degree, dmp_degree,
|
| 10 |
+
dmp_degree_in, dmp_degree_list,
|
| 11 |
+
dup_strip, dmp_strip,
|
| 12 |
+
dmp_validate,
|
| 13 |
+
dup_reverse,
|
| 14 |
+
dup_copy, dmp_copy,
|
| 15 |
+
dup_normal, dmp_normal,
|
| 16 |
+
dup_convert, dmp_convert,
|
| 17 |
+
dup_from_sympy, dmp_from_sympy,
|
| 18 |
+
dup_nth, dmp_nth, dmp_ground_nth,
|
| 19 |
+
dmp_zero_p, dmp_zero,
|
| 20 |
+
dmp_one_p, dmp_one,
|
| 21 |
+
dmp_ground_p, dmp_ground,
|
| 22 |
+
dmp_negative_p, dmp_positive_p,
|
| 23 |
+
dmp_zeros, dmp_grounds,
|
| 24 |
+
dup_from_dict, dup_from_raw_dict,
|
| 25 |
+
dup_to_dict, dup_to_raw_dict,
|
| 26 |
+
dmp_from_dict, dmp_to_dict,
|
| 27 |
+
dmp_swap, dmp_permute,
|
| 28 |
+
dmp_nest, dmp_raise,
|
| 29 |
+
dup_deflate, dmp_deflate,
|
| 30 |
+
dup_multi_deflate, dmp_multi_deflate,
|
| 31 |
+
dup_inflate, dmp_inflate,
|
| 32 |
+
dmp_exclude, dmp_include,
|
| 33 |
+
dmp_inject, dmp_eject,
|
| 34 |
+
dup_terms_gcd, dmp_terms_gcd,
|
| 35 |
+
dmp_list_terms, dmp_apply_pairs,
|
| 36 |
+
dup_slice,
|
| 37 |
+
dup_random,
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
from sympy.polys.specialpolys import f_polys
|
| 41 |
+
from sympy.polys.domains import ZZ, QQ
|
| 42 |
+
from sympy.polys.rings import ring
|
| 43 |
+
|
| 44 |
+
from sympy.core.singleton import S
|
| 45 |
+
from sympy.testing.pytest import raises
|
| 46 |
+
|
| 47 |
+
from sympy.core.numbers import oo
|
| 48 |
+
|
| 49 |
+
f_0, f_1, f_2, f_3, f_4, f_5, f_6 = [ f.to_dense() for f in f_polys() ]
|
| 50 |
+
|
| 51 |
+
def test_dup_LC():
|
| 52 |
+
assert dup_LC([], ZZ) == 0
|
| 53 |
+
assert dup_LC([2, 3, 4, 5], ZZ) == 2
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def test_dup_TC():
|
| 57 |
+
assert dup_TC([], ZZ) == 0
|
| 58 |
+
assert dup_TC([2, 3, 4, 5], ZZ) == 5
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def test_dmp_LC():
|
| 62 |
+
assert dmp_LC([[]], ZZ) == []
|
| 63 |
+
assert dmp_LC([[2, 3, 4], [5]], ZZ) == [2, 3, 4]
|
| 64 |
+
assert dmp_LC([[[]]], ZZ) == [[]]
|
| 65 |
+
assert dmp_LC([[[2], [3, 4]], [[5]]], ZZ) == [[2], [3, 4]]
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def test_dmp_TC():
|
| 69 |
+
assert dmp_TC([[]], ZZ) == []
|
| 70 |
+
assert dmp_TC([[2, 3, 4], [5]], ZZ) == [5]
|
| 71 |
+
assert dmp_TC([[[]]], ZZ) == [[]]
|
| 72 |
+
assert dmp_TC([[[2], [3, 4]], [[5]]], ZZ) == [[5]]
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
def test_dmp_ground_LC():
|
| 76 |
+
assert dmp_ground_LC([[]], 1, ZZ) == 0
|
| 77 |
+
assert dmp_ground_LC([[2, 3, 4], [5]], 1, ZZ) == 2
|
| 78 |
+
assert dmp_ground_LC([[[]]], 2, ZZ) == 0
|
| 79 |
+
assert dmp_ground_LC([[[2], [3, 4]], [[5]]], 2, ZZ) == 2
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def test_dmp_ground_TC():
|
| 83 |
+
assert dmp_ground_TC([[]], 1, ZZ) == 0
|
| 84 |
+
assert dmp_ground_TC([[2, 3, 4], [5]], 1, ZZ) == 5
|
| 85 |
+
assert dmp_ground_TC([[[]]], 2, ZZ) == 0
|
| 86 |
+
assert dmp_ground_TC([[[2], [3, 4]], [[5]]], 2, ZZ) == 5
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
def test_dmp_true_LT():
|
| 90 |
+
assert dmp_true_LT([[]], 1, ZZ) == ((0, 0), 0)
|
| 91 |
+
assert dmp_true_LT([[7]], 1, ZZ) == ((0, 0), 7)
|
| 92 |
+
|
| 93 |
+
assert dmp_true_LT([[1, 0]], 1, ZZ) == ((0, 1), 1)
|
| 94 |
+
assert dmp_true_LT([[1], []], 1, ZZ) == ((1, 0), 1)
|
| 95 |
+
assert dmp_true_LT([[1, 0], []], 1, ZZ) == ((1, 1), 1)
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
def test_dup_degree():
|
| 99 |
+
assert ninf == float('-inf')
|
| 100 |
+
assert dup_degree([]) is ninf
|
| 101 |
+
assert dup_degree([1]) == 0
|
| 102 |
+
assert dup_degree([1, 0]) == 1
|
| 103 |
+
assert dup_degree([1, 0, 0, 0, 1]) == 4
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
def test_dmp_degree():
|
| 107 |
+
assert dmp_degree([[]], 1) is ninf
|
| 108 |
+
assert dmp_degree([[[]]], 2) is ninf
|
| 109 |
+
|
| 110 |
+
assert dmp_degree([[1]], 1) == 0
|
| 111 |
+
assert dmp_degree([[2], [1]], 1) == 1
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
def test_dmp_degree_in():
|
| 115 |
+
assert dmp_degree_in([[[]]], 0, 2) is ninf
|
| 116 |
+
assert dmp_degree_in([[[]]], 1, 2) is ninf
|
| 117 |
+
assert dmp_degree_in([[[]]], 2, 2) is ninf
|
| 118 |
+
|
| 119 |
+
assert dmp_degree_in([[[1]]], 0, 2) == 0
|
| 120 |
+
assert dmp_degree_in([[[1]]], 1, 2) == 0
|
| 121 |
+
assert dmp_degree_in([[[1]]], 2, 2) == 0
|
| 122 |
+
|
| 123 |
+
assert dmp_degree_in(f_4, 0, 2) == 9
|
| 124 |
+
assert dmp_degree_in(f_4, 1, 2) == 12
|
| 125 |
+
assert dmp_degree_in(f_4, 2, 2) == 8
|
| 126 |
+
|
| 127 |
+
assert dmp_degree_in(f_6, 0, 2) == 4
|
| 128 |
+
assert dmp_degree_in(f_6, 1, 2) == 4
|
| 129 |
+
assert dmp_degree_in(f_6, 2, 2) == 6
|
| 130 |
+
assert dmp_degree_in(f_6, 3, 3) == 3
|
| 131 |
+
|
| 132 |
+
raises(IndexError, lambda: dmp_degree_in([[1]], -5, 1))
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
def test_dmp_degree_list():
|
| 136 |
+
assert dmp_degree_list([[[[ ]]]], 3) == (-oo, -oo, -oo, -oo)
|
| 137 |
+
assert dmp_degree_list([[[[1]]]], 3) == ( 0, 0, 0, 0)
|
| 138 |
+
|
| 139 |
+
assert dmp_degree_list(f_0, 2) == (2, 2, 2)
|
| 140 |
+
assert dmp_degree_list(f_1, 2) == (3, 3, 3)
|
| 141 |
+
assert dmp_degree_list(f_2, 2) == (5, 3, 3)
|
| 142 |
+
assert dmp_degree_list(f_3, 2) == (5, 4, 7)
|
| 143 |
+
assert dmp_degree_list(f_4, 2) == (9, 12, 8)
|
| 144 |
+
assert dmp_degree_list(f_5, 2) == (3, 3, 3)
|
| 145 |
+
assert dmp_degree_list(f_6, 3) == (4, 4, 6, 3)
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
def test_dup_strip():
|
| 149 |
+
assert dup_strip([]) == []
|
| 150 |
+
assert dup_strip([0]) == []
|
| 151 |
+
assert dup_strip([0, 0, 0]) == []
|
| 152 |
+
|
| 153 |
+
assert dup_strip([1]) == [1]
|
| 154 |
+
assert dup_strip([0, 1]) == [1]
|
| 155 |
+
assert dup_strip([0, 0, 0, 1]) == [1]
|
| 156 |
+
|
| 157 |
+
assert dup_strip([1, 2, 0]) == [1, 2, 0]
|
| 158 |
+
assert dup_strip([0, 1, 2, 0]) == [1, 2, 0]
|
| 159 |
+
assert dup_strip([0, 0, 0, 1, 2, 0]) == [1, 2, 0]
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
def test_dmp_strip():
|
| 163 |
+
assert dmp_strip([0, 1, 0], 0) == [1, 0]
|
| 164 |
+
|
| 165 |
+
assert dmp_strip([[]], 1) == [[]]
|
| 166 |
+
assert dmp_strip([[], []], 1) == [[]]
|
| 167 |
+
assert dmp_strip([[], [], []], 1) == [[]]
|
| 168 |
+
|
| 169 |
+
assert dmp_strip([[[]]], 2) == [[[]]]
|
| 170 |
+
assert dmp_strip([[[]], [[]]], 2) == [[[]]]
|
| 171 |
+
assert dmp_strip([[[]], [[]], [[]]], 2) == [[[]]]
|
| 172 |
+
|
| 173 |
+
assert dmp_strip([[[1]]], 2) == [[[1]]]
|
| 174 |
+
assert dmp_strip([[[]], [[1]]], 2) == [[[1]]]
|
| 175 |
+
assert dmp_strip([[[]], [[1]], [[]]], 2) == [[[1]], [[]]]
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
def test_dmp_validate():
|
| 179 |
+
assert dmp_validate([]) == ([], 0)
|
| 180 |
+
assert dmp_validate([0, 0, 0, 1, 0]) == ([1, 0], 0)
|
| 181 |
+
|
| 182 |
+
assert dmp_validate([[[]]]) == ([[[]]], 2)
|
| 183 |
+
assert dmp_validate([[0], [], [0], [1], [0]]) == ([[1], []], 1)
|
| 184 |
+
|
| 185 |
+
raises(ValueError, lambda: dmp_validate([[0], 0, [0], [1], [0]]))
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
def test_dup_reverse():
|
| 189 |
+
assert dup_reverse([1, 2, 0, 3]) == [3, 0, 2, 1]
|
| 190 |
+
assert dup_reverse([1, 2, 3, 0]) == [3, 2, 1]
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
def test_dup_copy():
|
| 194 |
+
f = [ZZ(1), ZZ(0), ZZ(2)]
|
| 195 |
+
g = dup_copy(f)
|
| 196 |
+
|
| 197 |
+
g[0], g[2] = ZZ(7), ZZ(0)
|
| 198 |
+
|
| 199 |
+
assert f != g
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
def test_dmp_copy():
|
| 203 |
+
f = [[ZZ(1)], [ZZ(2), ZZ(0)]]
|
| 204 |
+
g = dmp_copy(f, 1)
|
| 205 |
+
|
| 206 |
+
g[0][0], g[1][1] = ZZ(7), ZZ(1)
|
| 207 |
+
|
| 208 |
+
assert f != g
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
def test_dup_normal():
|
| 212 |
+
assert dup_normal([0, 0, 2, 1, 0, 11, 0], ZZ) == \
|
| 213 |
+
[ZZ(2), ZZ(1), ZZ(0), ZZ(11), ZZ(0)]
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
def test_dmp_normal():
|
| 217 |
+
assert dmp_normal([[0], [], [0, 2, 1], [0], [11], []], 1, ZZ) == \
|
| 218 |
+
[[ZZ(2), ZZ(1)], [], [ZZ(11)], []]
|
| 219 |
+
|
| 220 |
+
|
| 221 |
+
def test_dup_convert():
|
| 222 |
+
K0, K1 = ZZ['x'], ZZ
|
| 223 |
+
|
| 224 |
+
f = [K0(1), K0(2), K0(0), K0(3)]
|
| 225 |
+
|
| 226 |
+
assert dup_convert(f, K0, K1) == \
|
| 227 |
+
[ZZ(1), ZZ(2), ZZ(0), ZZ(3)]
|
| 228 |
+
|
| 229 |
+
|
| 230 |
+
def test_dmp_convert():
|
| 231 |
+
K0, K1 = ZZ['x'], ZZ
|
| 232 |
+
|
| 233 |
+
f = [[K0(1)], [K0(2)], [], [K0(3)]]
|
| 234 |
+
|
| 235 |
+
assert dmp_convert(f, 1, K0, K1) == \
|
| 236 |
+
[[ZZ(1)], [ZZ(2)], [], [ZZ(3)]]
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
def test_dup_from_sympy():
|
| 240 |
+
assert dup_from_sympy([S.One, S(2)], ZZ) == \
|
| 241 |
+
[ZZ(1), ZZ(2)]
|
| 242 |
+
assert dup_from_sympy([S.Half, S(3)], QQ) == \
|
| 243 |
+
[QQ(1, 2), QQ(3, 1)]
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
def test_dmp_from_sympy():
|
| 247 |
+
assert dmp_from_sympy([[S.One, S(2)], [S.Zero]], 1, ZZ) == \
|
| 248 |
+
[[ZZ(1), ZZ(2)], []]
|
| 249 |
+
assert dmp_from_sympy([[S.Half, S(2)]], 1, QQ) == \
|
| 250 |
+
[[QQ(1, 2), QQ(2, 1)]]
|
| 251 |
+
|
| 252 |
+
|
| 253 |
+
def test_dup_nth():
|
| 254 |
+
assert dup_nth([1, 2, 3], 0, ZZ) == 3
|
| 255 |
+
assert dup_nth([1, 2, 3], 1, ZZ) == 2
|
| 256 |
+
assert dup_nth([1, 2, 3], 2, ZZ) == 1
|
| 257 |
+
|
| 258 |
+
assert dup_nth([1, 2, 3], 9, ZZ) == 0
|
| 259 |
+
|
| 260 |
+
raises(IndexError, lambda: dup_nth([3, 4, 5], -1, ZZ))
|
| 261 |
+
|
| 262 |
+
|
| 263 |
+
def test_dmp_nth():
|
| 264 |
+
assert dmp_nth([[1], [2], [3]], 0, 1, ZZ) == [3]
|
| 265 |
+
assert dmp_nth([[1], [2], [3]], 1, 1, ZZ) == [2]
|
| 266 |
+
assert dmp_nth([[1], [2], [3]], 2, 1, ZZ) == [1]
|
| 267 |
+
|
| 268 |
+
assert dmp_nth([[1], [2], [3]], 9, 1, ZZ) == []
|
| 269 |
+
|
| 270 |
+
raises(IndexError, lambda: dmp_nth([[3], [4], [5]], -1, 1, ZZ))
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
def test_dmp_ground_nth():
|
| 274 |
+
assert dmp_ground_nth([[]], (0, 0), 1, ZZ) == 0
|
| 275 |
+
assert dmp_ground_nth([[1], [2], [3]], (0, 0), 1, ZZ) == 3
|
| 276 |
+
assert dmp_ground_nth([[1], [2], [3]], (1, 0), 1, ZZ) == 2
|
| 277 |
+
assert dmp_ground_nth([[1], [2], [3]], (2, 0), 1, ZZ) == 1
|
| 278 |
+
|
| 279 |
+
assert dmp_ground_nth([[1], [2], [3]], (2, 1), 1, ZZ) == 0
|
| 280 |
+
assert dmp_ground_nth([[1], [2], [3]], (3, 0), 1, ZZ) == 0
|
| 281 |
+
|
| 282 |
+
raises(IndexError, lambda: dmp_ground_nth([[3], [4], [5]], (2, -1), 1, ZZ))
|
| 283 |
+
|
| 284 |
+
|
| 285 |
+
def test_dmp_zero_p():
|
| 286 |
+
assert dmp_zero_p([], 0) is True
|
| 287 |
+
assert dmp_zero_p([[]], 1) is True
|
| 288 |
+
|
| 289 |
+
assert dmp_zero_p([[[]]], 2) is True
|
| 290 |
+
assert dmp_zero_p([[[1]]], 2) is False
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
def test_dmp_zero():
|
| 294 |
+
assert dmp_zero(0) == []
|
| 295 |
+
assert dmp_zero(2) == [[[]]]
|
| 296 |
+
|
| 297 |
+
|
| 298 |
+
def test_dmp_one_p():
|
| 299 |
+
assert dmp_one_p([1], 0, ZZ) is True
|
| 300 |
+
assert dmp_one_p([[1]], 1, ZZ) is True
|
| 301 |
+
assert dmp_one_p([[[1]]], 2, ZZ) is True
|
| 302 |
+
assert dmp_one_p([[[12]]], 2, ZZ) is False
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
def test_dmp_one():
|
| 306 |
+
assert dmp_one(0, ZZ) == [ZZ(1)]
|
| 307 |
+
assert dmp_one(2, ZZ) == [[[ZZ(1)]]]
|
| 308 |
+
|
| 309 |
+
|
| 310 |
+
def test_dmp_ground_p():
|
| 311 |
+
assert dmp_ground_p([], 0, 0) is True
|
| 312 |
+
assert dmp_ground_p([[]], 0, 1) is True
|
| 313 |
+
assert dmp_ground_p([[]], 1, 1) is False
|
| 314 |
+
|
| 315 |
+
assert dmp_ground_p([[ZZ(1)]], 1, 1) is True
|
| 316 |
+
assert dmp_ground_p([[[ZZ(2)]]], 2, 2) is True
|
| 317 |
+
|
| 318 |
+
assert dmp_ground_p([[[ZZ(2)]]], 3, 2) is False
|
| 319 |
+
assert dmp_ground_p([[[ZZ(3)], []]], 3, 2) is False
|
| 320 |
+
|
| 321 |
+
assert dmp_ground_p([], None, 0) is True
|
| 322 |
+
assert dmp_ground_p([[]], None, 1) is True
|
| 323 |
+
|
| 324 |
+
assert dmp_ground_p([ZZ(1)], None, 0) is True
|
| 325 |
+
assert dmp_ground_p([[[ZZ(1)]]], None, 2) is True
|
| 326 |
+
|
| 327 |
+
assert dmp_ground_p([[[ZZ(3)], []]], None, 2) is False
|
| 328 |
+
|
| 329 |
+
|
| 330 |
+
def test_dmp_ground():
|
| 331 |
+
assert dmp_ground(ZZ(0), 2) == [[[]]]
|
| 332 |
+
|
| 333 |
+
assert dmp_ground(ZZ(7), -1) == ZZ(7)
|
| 334 |
+
assert dmp_ground(ZZ(7), 0) == [ZZ(7)]
|
| 335 |
+
assert dmp_ground(ZZ(7), 2) == [[[ZZ(7)]]]
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
def test_dmp_zeros():
|
| 339 |
+
assert dmp_zeros(4, 0, ZZ) == [[], [], [], []]
|
| 340 |
+
|
| 341 |
+
assert dmp_zeros(0, 2, ZZ) == []
|
| 342 |
+
assert dmp_zeros(1, 2, ZZ) == [[[[]]]]
|
| 343 |
+
assert dmp_zeros(2, 2, ZZ) == [[[[]]], [[[]]]]
|
| 344 |
+
assert dmp_zeros(3, 2, ZZ) == [[[[]]], [[[]]], [[[]]]]
|
| 345 |
+
|
| 346 |
+
assert dmp_zeros(3, -1, ZZ) == [0, 0, 0]
|
| 347 |
+
|
| 348 |
+
|
| 349 |
+
def test_dmp_grounds():
|
| 350 |
+
assert dmp_grounds(ZZ(7), 0, 2) == []
|
| 351 |
+
|
| 352 |
+
assert dmp_grounds(ZZ(7), 1, 2) == [[[[7]]]]
|
| 353 |
+
assert dmp_grounds(ZZ(7), 2, 2) == [[[[7]]], [[[7]]]]
|
| 354 |
+
assert dmp_grounds(ZZ(7), 3, 2) == [[[[7]]], [[[7]]], [[[7]]]]
|
| 355 |
+
|
| 356 |
+
assert dmp_grounds(ZZ(7), 3, -1) == [7, 7, 7]
|
| 357 |
+
|
| 358 |
+
|
| 359 |
+
def test_dmp_negative_p():
|
| 360 |
+
assert dmp_negative_p([[[]]], 2, ZZ) is False
|
| 361 |
+
assert dmp_negative_p([[[1], [2]]], 2, ZZ) is False
|
| 362 |
+
assert dmp_negative_p([[[-1], [2]]], 2, ZZ) is True
|
| 363 |
+
|
| 364 |
+
|
| 365 |
+
def test_dmp_positive_p():
|
| 366 |
+
assert dmp_positive_p([[[]]], 2, ZZ) is False
|
| 367 |
+
assert dmp_positive_p([[[1], [2]]], 2, ZZ) is True
|
| 368 |
+
assert dmp_positive_p([[[-1], [2]]], 2, ZZ) is False
|
| 369 |
+
|
| 370 |
+
|
| 371 |
+
def test_dup_from_to_dict():
|
| 372 |
+
assert dup_from_raw_dict({}, ZZ) == []
|
| 373 |
+
assert dup_from_dict({}, ZZ) == []
|
| 374 |
+
|
| 375 |
+
assert dup_to_raw_dict([]) == {}
|
| 376 |
+
assert dup_to_dict([]) == {}
|
| 377 |
+
|
| 378 |
+
assert dup_to_raw_dict([], ZZ, zero=True) == {0: ZZ(0)}
|
| 379 |
+
assert dup_to_dict([], ZZ, zero=True) == {(0,): ZZ(0)}
|
| 380 |
+
|
| 381 |
+
f = [3, 0, 0, 2, 0, 0, 0, 0, 8]
|
| 382 |
+
g = {8: 3, 5: 2, 0: 8}
|
| 383 |
+
h = {(8,): 3, (5,): 2, (0,): 8}
|
| 384 |
+
|
| 385 |
+
assert dup_from_raw_dict(g, ZZ) == f
|
| 386 |
+
assert dup_from_dict(h, ZZ) == f
|
| 387 |
+
|
| 388 |
+
assert dup_to_raw_dict(f) == g
|
| 389 |
+
assert dup_to_dict(f) == h
|
| 390 |
+
|
| 391 |
+
R, x,y = ring("x,y", ZZ)
|
| 392 |
+
K = R.to_domain()
|
| 393 |
+
|
| 394 |
+
f = [R(3), R(0), R(2), R(0), R(0), R(8)]
|
| 395 |
+
g = {5: R(3), 3: R(2), 0: R(8)}
|
| 396 |
+
h = {(5,): R(3), (3,): R(2), (0,): R(8)}
|
| 397 |
+
|
| 398 |
+
assert dup_from_raw_dict(g, K) == f
|
| 399 |
+
assert dup_from_dict(h, K) == f
|
| 400 |
+
|
| 401 |
+
assert dup_to_raw_dict(f) == g
|
| 402 |
+
assert dup_to_dict(f) == h
|
| 403 |
+
|
| 404 |
+
|
| 405 |
+
def test_dmp_from_to_dict():
|
| 406 |
+
assert dmp_from_dict({}, 1, ZZ) == [[]]
|
| 407 |
+
assert dmp_to_dict([[]], 1) == {}
|
| 408 |
+
|
| 409 |
+
assert dmp_to_dict([], 0, ZZ, zero=True) == {(0,): ZZ(0)}
|
| 410 |
+
assert dmp_to_dict([[]], 1, ZZ, zero=True) == {(0, 0): ZZ(0)}
|
| 411 |
+
|
| 412 |
+
f = [[3], [], [], [2], [], [], [], [], [8]]
|
| 413 |
+
g = {(8, 0): 3, (5, 0): 2, (0, 0): 8}
|
| 414 |
+
|
| 415 |
+
assert dmp_from_dict(g, 1, ZZ) == f
|
| 416 |
+
assert dmp_to_dict(f, 1) == g
|
| 417 |
+
|
| 418 |
+
|
| 419 |
+
def test_dmp_swap():
|
| 420 |
+
f = dmp_normal([[1, 0, 0], [], [1, 0], [], [1]], 1, ZZ)
|
| 421 |
+
g = dmp_normal([[1, 0, 0, 0, 0], [1, 0, 0], [1]], 1, ZZ)
|
| 422 |
+
|
| 423 |
+
assert dmp_swap(f, 1, 1, 1, ZZ) == f
|
| 424 |
+
|
| 425 |
+
assert dmp_swap(f, 0, 1, 1, ZZ) == g
|
| 426 |
+
assert dmp_swap(g, 0, 1, 1, ZZ) == f
|
| 427 |
+
|
| 428 |
+
raises(IndexError, lambda: dmp_swap(f, -1, -7, 1, ZZ))
|
| 429 |
+
|
| 430 |
+
|
| 431 |
+
def test_dmp_permute():
|
| 432 |
+
f = dmp_normal([[1, 0, 0], [], [1, 0], [], [1]], 1, ZZ)
|
| 433 |
+
g = dmp_normal([[1, 0, 0, 0, 0], [1, 0, 0], [1]], 1, ZZ)
|
| 434 |
+
|
| 435 |
+
assert dmp_permute(f, [0, 1], 1, ZZ) == f
|
| 436 |
+
assert dmp_permute(g, [0, 1], 1, ZZ) == g
|
| 437 |
+
|
| 438 |
+
assert dmp_permute(f, [1, 0], 1, ZZ) == g
|
| 439 |
+
assert dmp_permute(g, [1, 0], 1, ZZ) == f
|
| 440 |
+
|
| 441 |
+
|
| 442 |
+
def test_dmp_nest():
|
| 443 |
+
assert dmp_nest(ZZ(1), 2, ZZ) == [[[1]]]
|
| 444 |
+
|
| 445 |
+
assert dmp_nest([[1]], 0, ZZ) == [[1]]
|
| 446 |
+
assert dmp_nest([[1]], 1, ZZ) == [[[1]]]
|
| 447 |
+
assert dmp_nest([[1]], 2, ZZ) == [[[[1]]]]
|
| 448 |
+
|
| 449 |
+
|
| 450 |
+
def test_dmp_raise():
|
| 451 |
+
assert dmp_raise([], 2, 0, ZZ) == [[[]]]
|
| 452 |
+
assert dmp_raise([[1]], 0, 1, ZZ) == [[1]]
|
| 453 |
+
|
| 454 |
+
assert dmp_raise([[1, 2, 3], [], [2, 3]], 2, 1, ZZ) == \
|
| 455 |
+
[[[[1]], [[2]], [[3]]], [[[]]], [[[2]], [[3]]]]
|
| 456 |
+
|
| 457 |
+
|
| 458 |
+
def test_dup_deflate():
|
| 459 |
+
assert dup_deflate([], ZZ) == (1, [])
|
| 460 |
+
assert dup_deflate([2], ZZ) == (1, [2])
|
| 461 |
+
assert dup_deflate([1, 2, 3], ZZ) == (1, [1, 2, 3])
|
| 462 |
+
assert dup_deflate([1, 0, 2, 0, 3], ZZ) == (2, [1, 2, 3])
|
| 463 |
+
|
| 464 |
+
assert dup_deflate(dup_from_raw_dict({7: 1, 1: 1}, ZZ), ZZ) == \
|
| 465 |
+
(1, [1, 0, 0, 0, 0, 0, 1, 0])
|
| 466 |
+
assert dup_deflate(dup_from_raw_dict({7: 1, 0: 1}, ZZ), ZZ) == \
|
| 467 |
+
(7, [1, 1])
|
| 468 |
+
assert dup_deflate(dup_from_raw_dict({7: 1, 3: 1}, ZZ), ZZ) == \
|
| 469 |
+
(1, [1, 0, 0, 0, 1, 0, 0, 0])
|
| 470 |
+
|
| 471 |
+
assert dup_deflate(dup_from_raw_dict({7: 1, 4: 1}, ZZ), ZZ) == \
|
| 472 |
+
(1, [1, 0, 0, 1, 0, 0, 0, 0])
|
| 473 |
+
assert dup_deflate(dup_from_raw_dict({8: 1, 4: 1}, ZZ), ZZ) == \
|
| 474 |
+
(4, [1, 1, 0])
|
| 475 |
+
|
| 476 |
+
assert dup_deflate(dup_from_raw_dict({8: 1}, ZZ), ZZ) == \
|
| 477 |
+
(8, [1, 0])
|
| 478 |
+
assert dup_deflate(dup_from_raw_dict({7: 1}, ZZ), ZZ) == \
|
| 479 |
+
(7, [1, 0])
|
| 480 |
+
assert dup_deflate(dup_from_raw_dict({1: 1}, ZZ), ZZ) == \
|
| 481 |
+
(1, [1, 0])
|
| 482 |
+
|
| 483 |
+
|
| 484 |
+
def test_dmp_deflate():
|
| 485 |
+
assert dmp_deflate([[]], 1, ZZ) == ((1, 1), [[]])
|
| 486 |
+
assert dmp_deflate([[2]], 1, ZZ) == ((1, 1), [[2]])
|
| 487 |
+
|
| 488 |
+
f = [[1, 0, 0], [], [1, 0], [], [1]]
|
| 489 |
+
|
| 490 |
+
assert dmp_deflate(f, 1, ZZ) == ((2, 1), [[1, 0, 0], [1, 0], [1]])
|
| 491 |
+
|
| 492 |
+
|
| 493 |
+
def test_dup_multi_deflate():
|
| 494 |
+
assert dup_multi_deflate(([2],), ZZ) == (1, ([2],))
|
| 495 |
+
assert dup_multi_deflate(([], []), ZZ) == (1, ([], []))
|
| 496 |
+
|
| 497 |
+
assert dup_multi_deflate(([1, 2, 3],), ZZ) == (1, ([1, 2, 3],))
|
| 498 |
+
assert dup_multi_deflate(([1, 0, 2, 0, 3],), ZZ) == (2, ([1, 2, 3],))
|
| 499 |
+
|
| 500 |
+
assert dup_multi_deflate(([1, 0, 2, 0, 3], [2, 0, 0]), ZZ) == \
|
| 501 |
+
(2, ([1, 2, 3], [2, 0]))
|
| 502 |
+
assert dup_multi_deflate(([1, 0, 2, 0, 3], [2, 1, 0]), ZZ) == \
|
| 503 |
+
(1, ([1, 0, 2, 0, 3], [2, 1, 0]))
|
| 504 |
+
|
| 505 |
+
|
| 506 |
+
def test_dmp_multi_deflate():
|
| 507 |
+
assert dmp_multi_deflate(([[]],), 1, ZZ) == \
|
| 508 |
+
((1, 1), ([[]],))
|
| 509 |
+
assert dmp_multi_deflate(([[]], [[]]), 1, ZZ) == \
|
| 510 |
+
((1, 1), ([[]], [[]]))
|
| 511 |
+
|
| 512 |
+
assert dmp_multi_deflate(([[1]], [[]]), 1, ZZ) == \
|
| 513 |
+
((1, 1), ([[1]], [[]]))
|
| 514 |
+
assert dmp_multi_deflate(([[1]], [[2]]), 1, ZZ) == \
|
| 515 |
+
((1, 1), ([[1]], [[2]]))
|
| 516 |
+
assert dmp_multi_deflate(([[1]], [[2, 0]]), 1, ZZ) == \
|
| 517 |
+
((1, 1), ([[1]], [[2, 0]]))
|
| 518 |
+
|
| 519 |
+
assert dmp_multi_deflate(([[2, 0]], [[2, 0]]), 1, ZZ) == \
|
| 520 |
+
((1, 1), ([[2, 0]], [[2, 0]]))
|
| 521 |
+
|
| 522 |
+
assert dmp_multi_deflate(
|
| 523 |
+
([[2]], [[2, 0, 0]]), 1, ZZ) == ((1, 2), ([[2]], [[2, 0]]))
|
| 524 |
+
assert dmp_multi_deflate(
|
| 525 |
+
([[2, 0, 0]], [[2, 0, 0]]), 1, ZZ) == ((1, 2), ([[2, 0]], [[2, 0]]))
|
| 526 |
+
|
| 527 |
+
assert dmp_multi_deflate(([2, 0, 0], [1, 0, 4, 0, 1]), 0, ZZ) == \
|
| 528 |
+
((2,), ([2, 0], [1, 4, 1]))
|
| 529 |
+
|
| 530 |
+
f = [[1, 0, 0], [], [1, 0], [], [1]]
|
| 531 |
+
g = [[1, 0, 1, 0], [], [1]]
|
| 532 |
+
|
| 533 |
+
assert dmp_multi_deflate((f,), 1, ZZ) == \
|
| 534 |
+
((2, 1), ([[1, 0, 0], [1, 0], [1]],))
|
| 535 |
+
|
| 536 |
+
assert dmp_multi_deflate((f, g), 1, ZZ) == \
|
| 537 |
+
((2, 1), ([[1, 0, 0], [1, 0], [1]],
|
| 538 |
+
[[1, 0, 1, 0], [1]]))
|
| 539 |
+
|
| 540 |
+
|
| 541 |
+
def test_dup_inflate():
|
| 542 |
+
assert dup_inflate([], 17, ZZ) == []
|
| 543 |
+
|
| 544 |
+
assert dup_inflate([1, 2, 3], 1, ZZ) == [1, 2, 3]
|
| 545 |
+
assert dup_inflate([1, 2, 3], 2, ZZ) == [1, 0, 2, 0, 3]
|
| 546 |
+
assert dup_inflate([1, 2, 3], 3, ZZ) == [1, 0, 0, 2, 0, 0, 3]
|
| 547 |
+
assert dup_inflate([1, 2, 3], 4, ZZ) == [1, 0, 0, 0, 2, 0, 0, 0, 3]
|
| 548 |
+
|
| 549 |
+
raises(IndexError, lambda: dup_inflate([1, 2, 3], 0, ZZ))
|
| 550 |
+
|
| 551 |
+
|
| 552 |
+
def test_dmp_inflate():
|
| 553 |
+
assert dmp_inflate([1], (3,), 0, ZZ) == [1]
|
| 554 |
+
|
| 555 |
+
assert dmp_inflate([[]], (3, 7), 1, ZZ) == [[]]
|
| 556 |
+
assert dmp_inflate([[2]], (1, 2), 1, ZZ) == [[2]]
|
| 557 |
+
|
| 558 |
+
assert dmp_inflate([[2, 0]], (1, 1), 1, ZZ) == [[2, 0]]
|
| 559 |
+
assert dmp_inflate([[2, 0]], (1, 2), 1, ZZ) == [[2, 0, 0]]
|
| 560 |
+
assert dmp_inflate([[2, 0]], (1, 3), 1, ZZ) == [[2, 0, 0, 0]]
|
| 561 |
+
|
| 562 |
+
assert dmp_inflate([[1, 0, 0], [1], [1, 0]], (2, 1), 1, ZZ) == \
|
| 563 |
+
[[1, 0, 0], [], [1], [], [1, 0]]
|
| 564 |
+
|
| 565 |
+
raises(IndexError, lambda: dmp_inflate([[]], (-3, 7), 1, ZZ))
|
| 566 |
+
|
| 567 |
+
|
| 568 |
+
def test_dmp_exclude():
|
| 569 |
+
assert dmp_exclude([[[]]], 2, ZZ) == ([], [[[]]], 2)
|
| 570 |
+
assert dmp_exclude([[[7]]], 2, ZZ) == ([], [[[7]]], 2)
|
| 571 |
+
|
| 572 |
+
assert dmp_exclude([1, 2, 3], 0, ZZ) == ([], [1, 2, 3], 0)
|
| 573 |
+
assert dmp_exclude([[1], [2, 3]], 1, ZZ) == ([], [[1], [2, 3]], 1)
|
| 574 |
+
|
| 575 |
+
assert dmp_exclude([[1, 2, 3]], 1, ZZ) == ([0], [1, 2, 3], 0)
|
| 576 |
+
assert dmp_exclude([[1], [2], [3]], 1, ZZ) == ([1], [1, 2, 3], 0)
|
| 577 |
+
|
| 578 |
+
assert dmp_exclude([[[1, 2, 3]]], 2, ZZ) == ([0, 1], [1, 2, 3], 0)
|
| 579 |
+
assert dmp_exclude([[[1]], [[2]], [[3]]], 2, ZZ) == ([1, 2], [1, 2, 3], 0)
|
| 580 |
+
|
| 581 |
+
|
| 582 |
+
def test_dmp_include():
|
| 583 |
+
assert dmp_include([1, 2, 3], [], 0, ZZ) == [1, 2, 3]
|
| 584 |
+
|
| 585 |
+
assert dmp_include([1, 2, 3], [0], 0, ZZ) == [[1, 2, 3]]
|
| 586 |
+
assert dmp_include([1, 2, 3], [1], 0, ZZ) == [[1], [2], [3]]
|
| 587 |
+
|
| 588 |
+
assert dmp_include([1, 2, 3], [0, 1], 0, ZZ) == [[[1, 2, 3]]]
|
| 589 |
+
assert dmp_include([1, 2, 3], [1, 2], 0, ZZ) == [[[1]], [[2]], [[3]]]
|
| 590 |
+
|
| 591 |
+
|
| 592 |
+
def test_dmp_inject():
|
| 593 |
+
R, x,y = ring("x,y", ZZ)
|
| 594 |
+
K = R.to_domain()
|
| 595 |
+
|
| 596 |
+
assert dmp_inject([], 0, K) == ([[[]]], 2)
|
| 597 |
+
assert dmp_inject([[]], 1, K) == ([[[[]]]], 3)
|
| 598 |
+
|
| 599 |
+
assert dmp_inject([R(1)], 0, K) == ([[[1]]], 2)
|
| 600 |
+
assert dmp_inject([[R(1)]], 1, K) == ([[[[1]]]], 3)
|
| 601 |
+
|
| 602 |
+
assert dmp_inject([R(1), 2*x + 3*y + 4], 0, K) == ([[[1]], [[2], [3, 4]]], 2)
|
| 603 |
+
|
| 604 |
+
f = [3*x**2 + 7*x*y + 5*y**2, 2*x, R(0), x*y**2 + 11]
|
| 605 |
+
g = [[[3], [7, 0], [5, 0, 0]], [[2], []], [[]], [[1, 0, 0], [11]]]
|
| 606 |
+
|
| 607 |
+
assert dmp_inject(f, 0, K) == (g, 2)
|
| 608 |
+
|
| 609 |
+
|
| 610 |
+
def test_dmp_eject():
|
| 611 |
+
R, x,y = ring("x,y", ZZ)
|
| 612 |
+
K = R.to_domain()
|
| 613 |
+
|
| 614 |
+
assert dmp_eject([[[]]], 2, K) == []
|
| 615 |
+
assert dmp_eject([[[[]]]], 3, K) == [[]]
|
| 616 |
+
|
| 617 |
+
assert dmp_eject([[[1]]], 2, K) == [R(1)]
|
| 618 |
+
assert dmp_eject([[[[1]]]], 3, K) == [[R(1)]]
|
| 619 |
+
|
| 620 |
+
assert dmp_eject([[[1]], [[2], [3, 4]]], 2, K) == [R(1), 2*x + 3*y + 4]
|
| 621 |
+
|
| 622 |
+
f = [3*x**2 + 7*x*y + 5*y**2, 2*x, R(0), x*y**2 + 11]
|
| 623 |
+
g = [[[3], [7, 0], [5, 0, 0]], [[2], []], [[]], [[1, 0, 0], [11]]]
|
| 624 |
+
|
| 625 |
+
assert dmp_eject(g, 2, K) == f
|
| 626 |
+
|
| 627 |
+
|
| 628 |
+
def test_dup_terms_gcd():
|
| 629 |
+
assert dup_terms_gcd([], ZZ) == (0, [])
|
| 630 |
+
assert dup_terms_gcd([1, 0, 1], ZZ) == (0, [1, 0, 1])
|
| 631 |
+
assert dup_terms_gcd([1, 0, 1, 0], ZZ) == (1, [1, 0, 1])
|
| 632 |
+
|
| 633 |
+
|
| 634 |
+
def test_dmp_terms_gcd():
|
| 635 |
+
assert dmp_terms_gcd([[]], 1, ZZ) == ((0, 0), [[]])
|
| 636 |
+
|
| 637 |
+
assert dmp_terms_gcd([1, 0, 1, 0], 0, ZZ) == ((1,), [1, 0, 1])
|
| 638 |
+
assert dmp_terms_gcd([[1], [], [1], []], 1, ZZ) == ((1, 0), [[1], [], [1]])
|
| 639 |
+
|
| 640 |
+
assert dmp_terms_gcd(
|
| 641 |
+
[[1, 0], [], [1]], 1, ZZ) == ((0, 0), [[1, 0], [], [1]])
|
| 642 |
+
assert dmp_terms_gcd(
|
| 643 |
+
[[1, 0], [1, 0, 0], [], []], 1, ZZ) == ((2, 1), [[1], [1, 0]])
|
| 644 |
+
|
| 645 |
+
|
| 646 |
+
def test_dmp_list_terms():
|
| 647 |
+
assert dmp_list_terms([[[]]], 2, ZZ) == [((0, 0, 0), 0)]
|
| 648 |
+
assert dmp_list_terms([[[1]]], 2, ZZ) == [((0, 0, 0), 1)]
|
| 649 |
+
|
| 650 |
+
assert dmp_list_terms([1, 2, 4, 3, 5], 0, ZZ) == \
|
| 651 |
+
[((4,), 1), ((3,), 2), ((2,), 4), ((1,), 3), ((0,), 5)]
|
| 652 |
+
|
| 653 |
+
assert dmp_list_terms([[1], [2, 4], [3, 5, 0]], 1, ZZ) == \
|
| 654 |
+
[((2, 0), 1), ((1, 1), 2), ((1, 0), 4), ((0, 2), 3), ((0, 1), 5)]
|
| 655 |
+
|
| 656 |
+
f = [[2, 0, 0, 0], [1, 0, 0], []]
|
| 657 |
+
|
| 658 |
+
assert dmp_list_terms(f, 1, ZZ, order='lex') == [((2, 3), 2), ((1, 2), 1)]
|
| 659 |
+
assert dmp_list_terms(
|
| 660 |
+
f, 1, ZZ, order='grlex') == [((2, 3), 2), ((1, 2), 1)]
|
| 661 |
+
|
| 662 |
+
f = [[2, 0, 0, 0], [1, 0, 0, 0, 0, 0], []]
|
| 663 |
+
|
| 664 |
+
assert dmp_list_terms(f, 1, ZZ, order='lex') == [((2, 3), 2), ((1, 5), 1)]
|
| 665 |
+
assert dmp_list_terms(
|
| 666 |
+
f, 1, ZZ, order='grlex') == [((1, 5), 1), ((2, 3), 2)]
|
| 667 |
+
|
| 668 |
+
|
| 669 |
+
def test_dmp_apply_pairs():
|
| 670 |
+
h = lambda a, b: a*b
|
| 671 |
+
|
| 672 |
+
assert dmp_apply_pairs([1, 2, 3], [4, 5, 6], h, [], 0, ZZ) == [4, 10, 18]
|
| 673 |
+
|
| 674 |
+
assert dmp_apply_pairs([2, 3], [4, 5, 6], h, [], 0, ZZ) == [10, 18]
|
| 675 |
+
assert dmp_apply_pairs([1, 2, 3], [5, 6], h, [], 0, ZZ) == [10, 18]
|
| 676 |
+
|
| 677 |
+
assert dmp_apply_pairs(
|
| 678 |
+
[[1, 2], [3]], [[4, 5], [6]], h, [], 1, ZZ) == [[4, 10], [18]]
|
| 679 |
+
|
| 680 |
+
assert dmp_apply_pairs(
|
| 681 |
+
[[1, 2], [3]], [[4], [5, 6]], h, [], 1, ZZ) == [[8], [18]]
|
| 682 |
+
assert dmp_apply_pairs(
|
| 683 |
+
[[1], [2, 3]], [[4, 5], [6]], h, [], 1, ZZ) == [[5], [18]]
|
| 684 |
+
|
| 685 |
+
|
| 686 |
+
def test_dup_slice():
|
| 687 |
+
f = [1, 2, 3, 4]
|
| 688 |
+
|
| 689 |
+
assert dup_slice(f, 0, 0, ZZ) == []
|
| 690 |
+
assert dup_slice(f, 0, 1, ZZ) == [4]
|
| 691 |
+
assert dup_slice(f, 0, 2, ZZ) == [3, 4]
|
| 692 |
+
assert dup_slice(f, 0, 3, ZZ) == [2, 3, 4]
|
| 693 |
+
assert dup_slice(f, 0, 4, ZZ) == [1, 2, 3, 4]
|
| 694 |
+
|
| 695 |
+
assert dup_slice(f, 0, 4, ZZ) == f
|
| 696 |
+
assert dup_slice(f, 0, 9, ZZ) == f
|
| 697 |
+
|
| 698 |
+
assert dup_slice(f, 1, 0, ZZ) == []
|
| 699 |
+
assert dup_slice(f, 1, 1, ZZ) == []
|
| 700 |
+
assert dup_slice(f, 1, 2, ZZ) == [3, 0]
|
| 701 |
+
assert dup_slice(f, 1, 3, ZZ) == [2, 3, 0]
|
| 702 |
+
assert dup_slice(f, 1, 4, ZZ) == [1, 2, 3, 0]
|
| 703 |
+
|
| 704 |
+
assert dup_slice([1, 2], 0, 3, ZZ) == [1, 2]
|
| 705 |
+
|
| 706 |
+
g = [1, 0, 0, 2]
|
| 707 |
+
|
| 708 |
+
assert dup_slice(g, 0, 3, ZZ) == [2]
|
| 709 |
+
|
| 710 |
+
|
| 711 |
+
def test_dup_random():
|
| 712 |
+
f = dup_random(0, -10, 10, ZZ)
|
| 713 |
+
|
| 714 |
+
assert dup_degree(f) == 0
|
| 715 |
+
assert all(-10 <= c <= 10 for c in f)
|
| 716 |
+
|
| 717 |
+
f = dup_random(1, -20, 20, ZZ)
|
| 718 |
+
|
| 719 |
+
assert dup_degree(f) == 1
|
| 720 |
+
assert all(-20 <= c <= 20 for c in f)
|
| 721 |
+
|
| 722 |
+
f = dup_random(2, -30, 30, ZZ)
|
| 723 |
+
|
| 724 |
+
assert dup_degree(f) == 2
|
| 725 |
+
assert all(-30 <= c <= 30 for c in f)
|
| 726 |
+
|
| 727 |
+
f = dup_random(3, -40, 40, ZZ)
|
| 728 |
+
|
| 729 |
+
assert dup_degree(f) == 3
|
| 730 |
+
assert all(-40 <= c <= 40 for c in f)
|
pllava/lib/python3.10/site-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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for dense recursive polynomials' tools. """
|
| 2 |
+
|
| 3 |
+
from sympy.polys.densebasic import (
|
| 4 |
+
dup_normal, dmp_normal,
|
| 5 |
+
dup_from_raw_dict,
|
| 6 |
+
dmp_convert, dmp_swap,
|
| 7 |
+
)
|
| 8 |
+
|
| 9 |
+
from sympy.polys.densearith import dmp_mul_ground
|
| 10 |
+
|
| 11 |
+
from sympy.polys.densetools import (
|
| 12 |
+
dup_clear_denoms, dmp_clear_denoms,
|
| 13 |
+
dup_integrate, dmp_integrate, dmp_integrate_in,
|
| 14 |
+
dup_diff, dmp_diff, dmp_diff_in,
|
| 15 |
+
dup_eval, dmp_eval, dmp_eval_in,
|
| 16 |
+
dmp_eval_tail, dmp_diff_eval_in,
|
| 17 |
+
dup_trunc, dmp_trunc, dmp_ground_trunc,
|
| 18 |
+
dup_monic, dmp_ground_monic,
|
| 19 |
+
dup_content, dmp_ground_content,
|
| 20 |
+
dup_primitive, dmp_ground_primitive,
|
| 21 |
+
dup_extract, dmp_ground_extract,
|
| 22 |
+
dup_real_imag,
|
| 23 |
+
dup_mirror, dup_scale, dup_shift, dmp_shift,
|
| 24 |
+
dup_transform,
|
| 25 |
+
dup_compose, dmp_compose,
|
| 26 |
+
dup_decompose,
|
| 27 |
+
dmp_lift,
|
| 28 |
+
dup_sign_variations,
|
| 29 |
+
dup_revert, dmp_revert,
|
| 30 |
+
)
|
| 31 |
+
from sympy.polys.polyclasses import ANP
|
| 32 |
+
|
| 33 |
+
from sympy.polys.polyerrors import (
|
| 34 |
+
MultivariatePolynomialError,
|
| 35 |
+
ExactQuotientFailed,
|
| 36 |
+
NotReversible,
|
| 37 |
+
DomainError,
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
from sympy.polys.specialpolys import f_polys
|
| 41 |
+
|
| 42 |
+
from sympy.polys.domains import FF, ZZ, QQ, ZZ_I, QQ_I, EX, RR
|
| 43 |
+
from sympy.polys.rings import ring
|
| 44 |
+
|
| 45 |
+
from sympy.core.numbers import I
|
| 46 |
+
from sympy.core.singleton import S
|
| 47 |
+
from sympy.functions.elementary.trigonometric import sin
|
| 48 |
+
|
| 49 |
+
from sympy.abc import x
|
| 50 |
+
from sympy.testing.pytest import raises
|
| 51 |
+
|
| 52 |
+
f_0, f_1, f_2, f_3, f_4, f_5, f_6 = [ f.to_dense() for f in f_polys() ]
|
| 53 |
+
|
| 54 |
+
def test_dup_integrate():
|
| 55 |
+
assert dup_integrate([], 1, QQ) == []
|
| 56 |
+
assert dup_integrate([], 2, QQ) == []
|
| 57 |
+
|
| 58 |
+
assert dup_integrate([QQ(1)], 1, QQ) == [QQ(1), QQ(0)]
|
| 59 |
+
assert dup_integrate([QQ(1)], 2, QQ) == [QQ(1, 2), QQ(0), QQ(0)]
|
| 60 |
+
|
| 61 |
+
assert dup_integrate([QQ(1), QQ(2), QQ(3)], 0, QQ) == \
|
| 62 |
+
[QQ(1), QQ(2), QQ(3)]
|
| 63 |
+
assert dup_integrate([QQ(1), QQ(2), QQ(3)], 1, QQ) == \
|
| 64 |
+
[QQ(1, 3), QQ(1), QQ(3), QQ(0)]
|
| 65 |
+
assert dup_integrate([QQ(1), QQ(2), QQ(3)], 2, QQ) == \
|
| 66 |
+
[QQ(1, 12), QQ(1, 3), QQ(3, 2), QQ(0), QQ(0)]
|
| 67 |
+
assert dup_integrate([QQ(1), QQ(2), QQ(3)], 3, QQ) == \
|
| 68 |
+
[QQ(1, 60), QQ(1, 12), QQ(1, 2), QQ(0), QQ(0), QQ(0)]
|
| 69 |
+
|
| 70 |
+
assert dup_integrate(dup_from_raw_dict({29: QQ(17)}, QQ), 3, QQ) == \
|
| 71 |
+
dup_from_raw_dict({32: QQ(17, 29760)}, QQ)
|
| 72 |
+
|
| 73 |
+
assert dup_integrate(dup_from_raw_dict({29: QQ(17), 5: QQ(1, 2)}, QQ), 3, QQ) == \
|
| 74 |
+
dup_from_raw_dict({32: QQ(17, 29760), 8: QQ(1, 672)}, QQ)
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def test_dmp_integrate():
|
| 78 |
+
assert dmp_integrate([QQ(1)], 2, 0, QQ) == [QQ(1, 2), QQ(0), QQ(0)]
|
| 79 |
+
|
| 80 |
+
assert dmp_integrate([[[]]], 1, 2, QQ) == [[[]]]
|
| 81 |
+
assert dmp_integrate([[[]]], 2, 2, QQ) == [[[]]]
|
| 82 |
+
|
| 83 |
+
assert dmp_integrate([[[QQ(1)]]], 1, 2, QQ) == [[[QQ(1)]], [[]]]
|
| 84 |
+
assert dmp_integrate([[[QQ(1)]]], 2, 2, QQ) == [[[QQ(1, 2)]], [[]], [[]]]
|
| 85 |
+
|
| 86 |
+
assert dmp_integrate([[QQ(1)], [QQ(2)], [QQ(3)]], 0, 1, QQ) == \
|
| 87 |
+
[[QQ(1)], [QQ(2)], [QQ(3)]]
|
| 88 |
+
assert dmp_integrate([[QQ(1)], [QQ(2)], [QQ(3)]], 1, 1, QQ) == \
|
| 89 |
+
[[QQ(1, 3)], [QQ(1)], [QQ(3)], []]
|
| 90 |
+
assert dmp_integrate([[QQ(1)], [QQ(2)], [QQ(3)]], 2, 1, QQ) == \
|
| 91 |
+
[[QQ(1, 12)], [QQ(1, 3)], [QQ(3, 2)], [], []]
|
| 92 |
+
assert dmp_integrate([[QQ(1)], [QQ(2)], [QQ(3)]], 3, 1, QQ) == \
|
| 93 |
+
[[QQ(1, 60)], [QQ(1, 12)], [QQ(1, 2)], [], [], []]
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
def test_dmp_integrate_in():
|
| 97 |
+
f = dmp_convert(f_6, 3, ZZ, QQ)
|
| 98 |
+
|
| 99 |
+
assert dmp_integrate_in(f, 2, 1, 3, QQ) == \
|
| 100 |
+
dmp_swap(
|
| 101 |
+
dmp_integrate(dmp_swap(f, 0, 1, 3, QQ), 2, 3, QQ), 0, 1, 3, QQ)
|
| 102 |
+
assert dmp_integrate_in(f, 3, 1, 3, QQ) == \
|
| 103 |
+
dmp_swap(
|
| 104 |
+
dmp_integrate(dmp_swap(f, 0, 1, 3, QQ), 3, 3, QQ), 0, 1, 3, QQ)
|
| 105 |
+
assert dmp_integrate_in(f, 2, 2, 3, QQ) == \
|
| 106 |
+
dmp_swap(
|
| 107 |
+
dmp_integrate(dmp_swap(f, 0, 2, 3, QQ), 2, 3, QQ), 0, 2, 3, QQ)
|
| 108 |
+
assert dmp_integrate_in(f, 3, 2, 3, QQ) == \
|
| 109 |
+
dmp_swap(
|
| 110 |
+
dmp_integrate(dmp_swap(f, 0, 2, 3, QQ), 3, 3, QQ), 0, 2, 3, QQ)
|
| 111 |
+
|
| 112 |
+
raises(IndexError, lambda: dmp_integrate_in(f, 1, -1, 3, QQ))
|
| 113 |
+
raises(IndexError, lambda: dmp_integrate_in(f, 1, 4, 3, QQ))
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
def test_dup_diff():
|
| 117 |
+
assert dup_diff([], 1, ZZ) == []
|
| 118 |
+
assert dup_diff([7], 1, ZZ) == []
|
| 119 |
+
assert dup_diff([2, 7], 1, ZZ) == [2]
|
| 120 |
+
assert dup_diff([1, 2, 1], 1, ZZ) == [2, 2]
|
| 121 |
+
assert dup_diff([1, 2, 3, 4], 1, ZZ) == [3, 4, 3]
|
| 122 |
+
assert dup_diff([1, -1, 0, 0, 2], 1, ZZ) == [4, -3, 0, 0]
|
| 123 |
+
|
| 124 |
+
f = dup_normal([17, 34, 56, -345, 23, 76, 0, 0, 12, 3, 7], ZZ)
|
| 125 |
+
|
| 126 |
+
assert dup_diff(f, 0, ZZ) == f
|
| 127 |
+
assert dup_diff(f, 1, ZZ) == [170, 306, 448, -2415, 138, 380, 0, 0, 24, 3]
|
| 128 |
+
assert dup_diff(f, 2, ZZ) == dup_diff(dup_diff(f, 1, ZZ), 1, ZZ)
|
| 129 |
+
assert dup_diff(
|
| 130 |
+
f, 3, ZZ) == dup_diff(dup_diff(dup_diff(f, 1, ZZ), 1, ZZ), 1, ZZ)
|
| 131 |
+
|
| 132 |
+
K = FF(3)
|
| 133 |
+
f = dup_normal([17, 34, 56, -345, 23, 76, 0, 0, 12, 3, 7], K)
|
| 134 |
+
|
| 135 |
+
assert dup_diff(f, 1, K) == dup_normal([2, 0, 1, 0, 0, 2, 0, 0, 0, 0], K)
|
| 136 |
+
assert dup_diff(f, 2, K) == dup_normal([1, 0, 0, 2, 0, 0, 0], K)
|
| 137 |
+
assert dup_diff(f, 3, K) == dup_normal([], K)
|
| 138 |
+
|
| 139 |
+
assert dup_diff(f, 0, K) == f
|
| 140 |
+
assert dup_diff(f, 2, K) == dup_diff(dup_diff(f, 1, K), 1, K)
|
| 141 |
+
assert dup_diff(
|
| 142 |
+
f, 3, K) == dup_diff(dup_diff(dup_diff(f, 1, K), 1, K), 1, K)
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
def test_dmp_diff():
|
| 146 |
+
assert dmp_diff([], 1, 0, ZZ) == []
|
| 147 |
+
assert dmp_diff([[]], 1, 1, ZZ) == [[]]
|
| 148 |
+
assert dmp_diff([[[]]], 1, 2, ZZ) == [[[]]]
|
| 149 |
+
|
| 150 |
+
assert dmp_diff([[[1], [2]]], 1, 2, ZZ) == [[[]]]
|
| 151 |
+
|
| 152 |
+
assert dmp_diff([[[1]], [[]]], 1, 2, ZZ) == [[[1]]]
|
| 153 |
+
assert dmp_diff([[[3]], [[1]], [[]]], 1, 2, ZZ) == [[[6]], [[1]]]
|
| 154 |
+
|
| 155 |
+
assert dmp_diff([1, -1, 0, 0, 2], 1, 0, ZZ) == \
|
| 156 |
+
dup_diff([1, -1, 0, 0, 2], 1, ZZ)
|
| 157 |
+
|
| 158 |
+
assert dmp_diff(f_6, 0, 3, ZZ) == f_6
|
| 159 |
+
assert dmp_diff(f_6, 1, 3, ZZ) == [[[[8460]], [[]]],
|
| 160 |
+
[[[135, 0, 0], [], [], [-135, 0, 0]]],
|
| 161 |
+
[[[]]],
|
| 162 |
+
[[[-423]], [[-47]], [[]], [[141], [], [94, 0], []], [[]]]]
|
| 163 |
+
assert dmp_diff(
|
| 164 |
+
f_6, 2, 3, ZZ) == dmp_diff(dmp_diff(f_6, 1, 3, ZZ), 1, 3, ZZ)
|
| 165 |
+
assert dmp_diff(f_6, 3, 3, ZZ) == dmp_diff(
|
| 166 |
+
dmp_diff(dmp_diff(f_6, 1, 3, ZZ), 1, 3, ZZ), 1, 3, ZZ)
|
| 167 |
+
|
| 168 |
+
K = FF(23)
|
| 169 |
+
F_6 = dmp_normal(f_6, 3, K)
|
| 170 |
+
|
| 171 |
+
assert dmp_diff(F_6, 0, 3, K) == F_6
|
| 172 |
+
assert dmp_diff(F_6, 1, 3, K) == dmp_diff(F_6, 1, 3, K)
|
| 173 |
+
assert dmp_diff(F_6, 2, 3, K) == dmp_diff(dmp_diff(F_6, 1, 3, K), 1, 3, K)
|
| 174 |
+
assert dmp_diff(F_6, 3, 3, K) == dmp_diff(
|
| 175 |
+
dmp_diff(dmp_diff(F_6, 1, 3, K), 1, 3, K), 1, 3, K)
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
def test_dmp_diff_in():
|
| 179 |
+
assert dmp_diff_in(f_6, 2, 1, 3, ZZ) == \
|
| 180 |
+
dmp_swap(dmp_diff(dmp_swap(f_6, 0, 1, 3, ZZ), 2, 3, ZZ), 0, 1, 3, ZZ)
|
| 181 |
+
assert dmp_diff_in(f_6, 3, 1, 3, ZZ) == \
|
| 182 |
+
dmp_swap(dmp_diff(dmp_swap(f_6, 0, 1, 3, ZZ), 3, 3, ZZ), 0, 1, 3, ZZ)
|
| 183 |
+
assert dmp_diff_in(f_6, 2, 2, 3, ZZ) == \
|
| 184 |
+
dmp_swap(dmp_diff(dmp_swap(f_6, 0, 2, 3, ZZ), 2, 3, ZZ), 0, 2, 3, ZZ)
|
| 185 |
+
assert dmp_diff_in(f_6, 3, 2, 3, ZZ) == \
|
| 186 |
+
dmp_swap(dmp_diff(dmp_swap(f_6, 0, 2, 3, ZZ), 3, 3, ZZ), 0, 2, 3, ZZ)
|
| 187 |
+
|
| 188 |
+
raises(IndexError, lambda: dmp_diff_in(f_6, 1, -1, 3, ZZ))
|
| 189 |
+
raises(IndexError, lambda: dmp_diff_in(f_6, 1, 4, 3, ZZ))
|
| 190 |
+
|
| 191 |
+
def test_dup_eval():
|
| 192 |
+
assert dup_eval([], 7, ZZ) == 0
|
| 193 |
+
assert dup_eval([1, 2], 0, ZZ) == 2
|
| 194 |
+
assert dup_eval([1, 2, 3], 7, ZZ) == 66
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
def test_dmp_eval():
|
| 198 |
+
assert dmp_eval([], 3, 0, ZZ) == 0
|
| 199 |
+
|
| 200 |
+
assert dmp_eval([[]], 3, 1, ZZ) == []
|
| 201 |
+
assert dmp_eval([[[]]], 3, 2, ZZ) == [[]]
|
| 202 |
+
|
| 203 |
+
assert dmp_eval([[1, 2]], 0, 1, ZZ) == [1, 2]
|
| 204 |
+
|
| 205 |
+
assert dmp_eval([[[1]]], 3, 2, ZZ) == [[1]]
|
| 206 |
+
assert dmp_eval([[[1, 2]]], 3, 2, ZZ) == [[1, 2]]
|
| 207 |
+
|
| 208 |
+
assert dmp_eval([[3, 2], [1, 2]], 3, 1, ZZ) == [10, 8]
|
| 209 |
+
assert dmp_eval([[[3, 2]], [[1, 2]]], 3, 2, ZZ) == [[10, 8]]
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
def test_dmp_eval_in():
|
| 213 |
+
assert dmp_eval_in(
|
| 214 |
+
f_6, -2, 1, 3, ZZ) == dmp_eval(dmp_swap(f_6, 0, 1, 3, ZZ), -2, 3, ZZ)
|
| 215 |
+
assert dmp_eval_in(
|
| 216 |
+
f_6, 7, 1, 3, ZZ) == dmp_eval(dmp_swap(f_6, 0, 1, 3, ZZ), 7, 3, ZZ)
|
| 217 |
+
assert dmp_eval_in(f_6, -2, 2, 3, ZZ) == dmp_swap(
|
| 218 |
+
dmp_eval(dmp_swap(f_6, 0, 2, 3, ZZ), -2, 3, ZZ), 0, 1, 2, ZZ)
|
| 219 |
+
assert dmp_eval_in(f_6, 7, 2, 3, ZZ) == dmp_swap(
|
| 220 |
+
dmp_eval(dmp_swap(f_6, 0, 2, 3, ZZ), 7, 3, ZZ), 0, 1, 2, ZZ)
|
| 221 |
+
|
| 222 |
+
f = [[[int(45)]], [[]], [[]], [[int(-9)], [-1], [], [int(3), int(0), int(10), int(0)]]]
|
| 223 |
+
|
| 224 |
+
assert dmp_eval_in(f, -2, 2, 2, ZZ) == \
|
| 225 |
+
[[45], [], [], [-9, -1, 0, -44]]
|
| 226 |
+
|
| 227 |
+
raises(IndexError, lambda: dmp_eval_in(f_6, ZZ(1), -1, 3, ZZ))
|
| 228 |
+
raises(IndexError, lambda: dmp_eval_in(f_6, ZZ(1), 4, 3, ZZ))
|
| 229 |
+
|
| 230 |
+
|
| 231 |
+
def test_dmp_eval_tail():
|
| 232 |
+
assert dmp_eval_tail([[]], [1], 1, ZZ) == []
|
| 233 |
+
assert dmp_eval_tail([[[]]], [1], 2, ZZ) == [[]]
|
| 234 |
+
assert dmp_eval_tail([[[]]], [1, 2], 2, ZZ) == []
|
| 235 |
+
|
| 236 |
+
assert dmp_eval_tail(f_0, [], 2, ZZ) == f_0
|
| 237 |
+
|
| 238 |
+
assert dmp_eval_tail(f_0, [1, -17, 8], 2, ZZ) == 84496
|
| 239 |
+
assert dmp_eval_tail(f_0, [-17, 8], 2, ZZ) == [-1409, 3, 85902]
|
| 240 |
+
assert dmp_eval_tail(f_0, [8], 2, ZZ) == [[83, 2], [3], [302, 81, 1]]
|
| 241 |
+
|
| 242 |
+
assert dmp_eval_tail(f_1, [-17, 8], 2, ZZ) == [-136, 15699, 9166, -27144]
|
| 243 |
+
|
| 244 |
+
assert dmp_eval_tail(
|
| 245 |
+
f_2, [-12, 3], 2, ZZ) == [-1377, 0, -702, -1224, 0, -624]
|
| 246 |
+
assert dmp_eval_tail(
|
| 247 |
+
f_3, [-12, 3], 2, ZZ) == [144, 82, -5181, -28872, -14868, -540]
|
| 248 |
+
|
| 249 |
+
assert dmp_eval_tail(
|
| 250 |
+
f_4, [25, -1], 2, ZZ) == [152587890625, 9765625, -59605407714843750,
|
| 251 |
+
-3839159765625, -1562475, 9536712644531250, 610349546750, -4, 24414375000, 1562520]
|
| 252 |
+
assert dmp_eval_tail(f_5, [25, -1], 2, ZZ) == [-1, -78, -2028, -17576]
|
| 253 |
+
|
| 254 |
+
assert dmp_eval_tail(f_6, [0, 2, 4], 3, ZZ) == [5040, 0, 0, 4480]
|
| 255 |
+
|
| 256 |
+
|
| 257 |
+
def test_dmp_diff_eval_in():
|
| 258 |
+
assert dmp_diff_eval_in(f_6, 2, 7, 1, 3, ZZ) == \
|
| 259 |
+
dmp_eval(dmp_diff(dmp_swap(f_6, 0, 1, 3, ZZ), 2, 3, ZZ), 7, 3, ZZ)
|
| 260 |
+
|
| 261 |
+
assert dmp_diff_eval_in(f_6, 2, 7, 0, 3, ZZ) == \
|
| 262 |
+
dmp_eval(dmp_diff(f_6, 2, 3, ZZ), 7, 3, ZZ)
|
| 263 |
+
|
| 264 |
+
raises(IndexError, lambda: dmp_diff_eval_in(f_6, 1, ZZ(1), 4, 3, ZZ))
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
def test_dup_revert():
|
| 268 |
+
f = [-QQ(1, 720), QQ(0), QQ(1, 24), QQ(0), -QQ(1, 2), QQ(0), QQ(1)]
|
| 269 |
+
g = [QQ(61, 720), QQ(0), QQ(5, 24), QQ(0), QQ(1, 2), QQ(0), QQ(1)]
|
| 270 |
+
|
| 271 |
+
assert dup_revert(f, 8, QQ) == g
|
| 272 |
+
|
| 273 |
+
raises(NotReversible, lambda: dup_revert([QQ(1), QQ(0)], 3, QQ))
|
| 274 |
+
|
| 275 |
+
|
| 276 |
+
def test_dmp_revert():
|
| 277 |
+
f = [-QQ(1, 720), QQ(0), QQ(1, 24), QQ(0), -QQ(1, 2), QQ(0), QQ(1)]
|
| 278 |
+
g = [QQ(61, 720), QQ(0), QQ(5, 24), QQ(0), QQ(1, 2), QQ(0), QQ(1)]
|
| 279 |
+
|
| 280 |
+
assert dmp_revert(f, 8, 0, QQ) == g
|
| 281 |
+
|
| 282 |
+
raises(MultivariatePolynomialError, lambda: dmp_revert([[1]], 2, 1, QQ))
|
| 283 |
+
|
| 284 |
+
|
| 285 |
+
def test_dup_trunc():
|
| 286 |
+
assert dup_trunc([1, 2, 3, 4, 5, 6], ZZ(3), ZZ) == [1, -1, 0, 1, -1, 0]
|
| 287 |
+
assert dup_trunc([6, 5, 4, 3, 2, 1], ZZ(3), ZZ) == [-1, 1, 0, -1, 1]
|
| 288 |
+
|
| 289 |
+
R = ZZ_I
|
| 290 |
+
assert dup_trunc([R(3), R(4), R(5)], R(3), R) == [R(1), R(-1)]
|
| 291 |
+
|
| 292 |
+
K = FF(5)
|
| 293 |
+
assert dup_trunc([K(3), K(4), K(5)], K(3), K) == [K(1), K(0)]
|
| 294 |
+
|
| 295 |
+
|
| 296 |
+
def test_dmp_trunc():
|
| 297 |
+
assert dmp_trunc([[]], [1, 2], 2, ZZ) == [[]]
|
| 298 |
+
assert dmp_trunc([[1, 2], [1, 4, 1], [1]], [1, 2], 1, ZZ) == [[-3], [1]]
|
| 299 |
+
|
| 300 |
+
|
| 301 |
+
def test_dmp_ground_trunc():
|
| 302 |
+
assert dmp_ground_trunc(f_0, ZZ(3), 2, ZZ) == \
|
| 303 |
+
dmp_normal(
|
| 304 |
+
[[[1, -1, 0], [-1]], [[]], [[1, -1, 0], [1, -1, 1], [1]]], 2, ZZ)
|
| 305 |
+
|
| 306 |
+
|
| 307 |
+
def test_dup_monic():
|
| 308 |
+
assert dup_monic([3, 6, 9], ZZ) == [1, 2, 3]
|
| 309 |
+
|
| 310 |
+
raises(ExactQuotientFailed, lambda: dup_monic([3, 4, 5], ZZ))
|
| 311 |
+
|
| 312 |
+
assert dup_monic([], QQ) == []
|
| 313 |
+
assert dup_monic([QQ(1)], QQ) == [QQ(1)]
|
| 314 |
+
assert dup_monic([QQ(7), QQ(1), QQ(21)], QQ) == [QQ(1), QQ(1, 7), QQ(3)]
|
| 315 |
+
|
| 316 |
+
|
| 317 |
+
def test_dmp_ground_monic():
|
| 318 |
+
assert dmp_ground_monic([3, 6, 9], 0, ZZ) == [1, 2, 3]
|
| 319 |
+
|
| 320 |
+
assert dmp_ground_monic([[3], [6], [9]], 1, ZZ) == [[1], [2], [3]]
|
| 321 |
+
|
| 322 |
+
raises(
|
| 323 |
+
ExactQuotientFailed, lambda: dmp_ground_monic([[3], [4], [5]], 1, ZZ))
|
| 324 |
+
|
| 325 |
+
assert dmp_ground_monic([[]], 1, QQ) == [[]]
|
| 326 |
+
assert dmp_ground_monic([[QQ(1)]], 1, QQ) == [[QQ(1)]]
|
| 327 |
+
assert dmp_ground_monic(
|
| 328 |
+
[[QQ(7)], [QQ(1)], [QQ(21)]], 1, QQ) == [[QQ(1)], [QQ(1, 7)], [QQ(3)]]
|
| 329 |
+
|
| 330 |
+
|
| 331 |
+
def test_dup_content():
|
| 332 |
+
assert dup_content([], ZZ) == ZZ(0)
|
| 333 |
+
assert dup_content([1], ZZ) == ZZ(1)
|
| 334 |
+
assert dup_content([-1], ZZ) == ZZ(1)
|
| 335 |
+
assert dup_content([1, 1], ZZ) == ZZ(1)
|
| 336 |
+
assert dup_content([2, 2], ZZ) == ZZ(2)
|
| 337 |
+
assert dup_content([1, 2, 1], ZZ) == ZZ(1)
|
| 338 |
+
assert dup_content([2, 4, 2], ZZ) == ZZ(2)
|
| 339 |
+
|
| 340 |
+
assert dup_content([QQ(2, 3), QQ(4, 9)], QQ) == QQ(2, 9)
|
| 341 |
+
assert dup_content([QQ(2, 3), QQ(4, 5)], QQ) == QQ(2, 15)
|
| 342 |
+
|
| 343 |
+
|
| 344 |
+
def test_dmp_ground_content():
|
| 345 |
+
assert dmp_ground_content([[]], 1, ZZ) == ZZ(0)
|
| 346 |
+
assert dmp_ground_content([[]], 1, QQ) == QQ(0)
|
| 347 |
+
assert dmp_ground_content([[1]], 1, ZZ) == ZZ(1)
|
| 348 |
+
assert dmp_ground_content([[-1]], 1, ZZ) == ZZ(1)
|
| 349 |
+
assert dmp_ground_content([[1], [1]], 1, ZZ) == ZZ(1)
|
| 350 |
+
assert dmp_ground_content([[2], [2]], 1, ZZ) == ZZ(2)
|
| 351 |
+
assert dmp_ground_content([[1], [2], [1]], 1, ZZ) == ZZ(1)
|
| 352 |
+
assert dmp_ground_content([[2], [4], [2]], 1, ZZ) == ZZ(2)
|
| 353 |
+
|
| 354 |
+
assert dmp_ground_content([[QQ(2, 3)], [QQ(4, 9)]], 1, QQ) == QQ(2, 9)
|
| 355 |
+
assert dmp_ground_content([[QQ(2, 3)], [QQ(4, 5)]], 1, QQ) == QQ(2, 15)
|
| 356 |
+
|
| 357 |
+
assert dmp_ground_content(f_0, 2, ZZ) == ZZ(1)
|
| 358 |
+
assert dmp_ground_content(
|
| 359 |
+
dmp_mul_ground(f_0, ZZ(2), 2, ZZ), 2, ZZ) == ZZ(2)
|
| 360 |
+
|
| 361 |
+
assert dmp_ground_content(f_1, 2, ZZ) == ZZ(1)
|
| 362 |
+
assert dmp_ground_content(
|
| 363 |
+
dmp_mul_ground(f_1, ZZ(3), 2, ZZ), 2, ZZ) == ZZ(3)
|
| 364 |
+
|
| 365 |
+
assert dmp_ground_content(f_2, 2, ZZ) == ZZ(1)
|
| 366 |
+
assert dmp_ground_content(
|
| 367 |
+
dmp_mul_ground(f_2, ZZ(4), 2, ZZ), 2, ZZ) == ZZ(4)
|
| 368 |
+
|
| 369 |
+
assert dmp_ground_content(f_3, 2, ZZ) == ZZ(1)
|
| 370 |
+
assert dmp_ground_content(
|
| 371 |
+
dmp_mul_ground(f_3, ZZ(5), 2, ZZ), 2, ZZ) == ZZ(5)
|
| 372 |
+
|
| 373 |
+
assert dmp_ground_content(f_4, 2, ZZ) == ZZ(1)
|
| 374 |
+
assert dmp_ground_content(
|
| 375 |
+
dmp_mul_ground(f_4, ZZ(6), 2, ZZ), 2, ZZ) == ZZ(6)
|
| 376 |
+
|
| 377 |
+
assert dmp_ground_content(f_5, 2, ZZ) == ZZ(1)
|
| 378 |
+
assert dmp_ground_content(
|
| 379 |
+
dmp_mul_ground(f_5, ZZ(7), 2, ZZ), 2, ZZ) == ZZ(7)
|
| 380 |
+
|
| 381 |
+
assert dmp_ground_content(f_6, 3, ZZ) == ZZ(1)
|
| 382 |
+
assert dmp_ground_content(
|
| 383 |
+
dmp_mul_ground(f_6, ZZ(8), 3, ZZ), 3, ZZ) == ZZ(8)
|
| 384 |
+
|
| 385 |
+
|
| 386 |
+
def test_dup_primitive():
|
| 387 |
+
assert dup_primitive([], ZZ) == (ZZ(0), [])
|
| 388 |
+
assert dup_primitive([ZZ(1)], ZZ) == (ZZ(1), [ZZ(1)])
|
| 389 |
+
assert dup_primitive([ZZ(1), ZZ(1)], ZZ) == (ZZ(1), [ZZ(1), ZZ(1)])
|
| 390 |
+
assert dup_primitive([ZZ(2), ZZ(2)], ZZ) == (ZZ(2), [ZZ(1), ZZ(1)])
|
| 391 |
+
assert dup_primitive(
|
| 392 |
+
[ZZ(1), ZZ(2), ZZ(1)], ZZ) == (ZZ(1), [ZZ(1), ZZ(2), ZZ(1)])
|
| 393 |
+
assert dup_primitive(
|
| 394 |
+
[ZZ(2), ZZ(4), ZZ(2)], ZZ) == (ZZ(2), [ZZ(1), ZZ(2), ZZ(1)])
|
| 395 |
+
|
| 396 |
+
assert dup_primitive([], QQ) == (QQ(0), [])
|
| 397 |
+
assert dup_primitive([QQ(1)], QQ) == (QQ(1), [QQ(1)])
|
| 398 |
+
assert dup_primitive([QQ(1), QQ(1)], QQ) == (QQ(1), [QQ(1), QQ(1)])
|
| 399 |
+
assert dup_primitive([QQ(2), QQ(2)], QQ) == (QQ(2), [QQ(1), QQ(1)])
|
| 400 |
+
assert dup_primitive(
|
| 401 |
+
[QQ(1), QQ(2), QQ(1)], QQ) == (QQ(1), [QQ(1), QQ(2), QQ(1)])
|
| 402 |
+
assert dup_primitive(
|
| 403 |
+
[QQ(2), QQ(4), QQ(2)], QQ) == (QQ(2), [QQ(1), QQ(2), QQ(1)])
|
| 404 |
+
|
| 405 |
+
assert dup_primitive(
|
| 406 |
+
[QQ(2, 3), QQ(4, 9)], QQ) == (QQ(2, 9), [QQ(3), QQ(2)])
|
| 407 |
+
assert dup_primitive(
|
| 408 |
+
[QQ(2, 3), QQ(4, 5)], QQ) == (QQ(2, 15), [QQ(5), QQ(6)])
|
| 409 |
+
|
| 410 |
+
|
| 411 |
+
def test_dmp_ground_primitive():
|
| 412 |
+
assert dmp_ground_primitive([ZZ(1)], 0, ZZ) == (ZZ(1), [ZZ(1)])
|
| 413 |
+
|
| 414 |
+
assert dmp_ground_primitive([[]], 1, ZZ) == (ZZ(0), [[]])
|
| 415 |
+
|
| 416 |
+
assert dmp_ground_primitive(f_0, 2, ZZ) == (ZZ(1), f_0)
|
| 417 |
+
assert dmp_ground_primitive(
|
| 418 |
+
dmp_mul_ground(f_0, ZZ(2), 2, ZZ), 2, ZZ) == (ZZ(2), f_0)
|
| 419 |
+
|
| 420 |
+
assert dmp_ground_primitive(f_1, 2, ZZ) == (ZZ(1), f_1)
|
| 421 |
+
assert dmp_ground_primitive(
|
| 422 |
+
dmp_mul_ground(f_1, ZZ(3), 2, ZZ), 2, ZZ) == (ZZ(3), f_1)
|
| 423 |
+
|
| 424 |
+
assert dmp_ground_primitive(f_2, 2, ZZ) == (ZZ(1), f_2)
|
| 425 |
+
assert dmp_ground_primitive(
|
| 426 |
+
dmp_mul_ground(f_2, ZZ(4), 2, ZZ), 2, ZZ) == (ZZ(4), f_2)
|
| 427 |
+
|
| 428 |
+
assert dmp_ground_primitive(f_3, 2, ZZ) == (ZZ(1), f_3)
|
| 429 |
+
assert dmp_ground_primitive(
|
| 430 |
+
dmp_mul_ground(f_3, ZZ(5), 2, ZZ), 2, ZZ) == (ZZ(5), f_3)
|
| 431 |
+
|
| 432 |
+
assert dmp_ground_primitive(f_4, 2, ZZ) == (ZZ(1), f_4)
|
| 433 |
+
assert dmp_ground_primitive(
|
| 434 |
+
dmp_mul_ground(f_4, ZZ(6), 2, ZZ), 2, ZZ) == (ZZ(6), f_4)
|
| 435 |
+
|
| 436 |
+
assert dmp_ground_primitive(f_5, 2, ZZ) == (ZZ(1), f_5)
|
| 437 |
+
assert dmp_ground_primitive(
|
| 438 |
+
dmp_mul_ground(f_5, ZZ(7), 2, ZZ), 2, ZZ) == (ZZ(7), f_5)
|
| 439 |
+
|
| 440 |
+
assert dmp_ground_primitive(f_6, 3, ZZ) == (ZZ(1), f_6)
|
| 441 |
+
assert dmp_ground_primitive(
|
| 442 |
+
dmp_mul_ground(f_6, ZZ(8), 3, ZZ), 3, ZZ) == (ZZ(8), f_6)
|
| 443 |
+
|
| 444 |
+
assert dmp_ground_primitive([[ZZ(2)]], 1, ZZ) == (ZZ(2), [[ZZ(1)]])
|
| 445 |
+
assert dmp_ground_primitive([[QQ(2)]], 1, QQ) == (QQ(2), [[QQ(1)]])
|
| 446 |
+
|
| 447 |
+
assert dmp_ground_primitive(
|
| 448 |
+
[[QQ(2, 3)], [QQ(4, 9)]], 1, QQ) == (QQ(2, 9), [[QQ(3)], [QQ(2)]])
|
| 449 |
+
assert dmp_ground_primitive(
|
| 450 |
+
[[QQ(2, 3)], [QQ(4, 5)]], 1, QQ) == (QQ(2, 15), [[QQ(5)], [QQ(6)]])
|
| 451 |
+
|
| 452 |
+
|
| 453 |
+
def test_dup_extract():
|
| 454 |
+
f = dup_normal([2930944, 0, 2198208, 0, 549552, 0, 45796], ZZ)
|
| 455 |
+
g = dup_normal([17585664, 0, 8792832, 0, 1099104, 0], ZZ)
|
| 456 |
+
|
| 457 |
+
F = dup_normal([64, 0, 48, 0, 12, 0, 1], ZZ)
|
| 458 |
+
G = dup_normal([384, 0, 192, 0, 24, 0], ZZ)
|
| 459 |
+
|
| 460 |
+
assert dup_extract(f, g, ZZ) == (45796, F, G)
|
| 461 |
+
|
| 462 |
+
|
| 463 |
+
def test_dmp_ground_extract():
|
| 464 |
+
f = dmp_normal(
|
| 465 |
+
[[2930944], [], [2198208], [], [549552], [], [45796]], 1, ZZ)
|
| 466 |
+
g = dmp_normal([[17585664], [], [8792832], [], [1099104], []], 1, ZZ)
|
| 467 |
+
|
| 468 |
+
F = dmp_normal([[64], [], [48], [], [12], [], [1]], 1, ZZ)
|
| 469 |
+
G = dmp_normal([[384], [], [192], [], [24], []], 1, ZZ)
|
| 470 |
+
|
| 471 |
+
assert dmp_ground_extract(f, g, 1, ZZ) == (45796, F, G)
|
| 472 |
+
|
| 473 |
+
|
| 474 |
+
def test_dup_real_imag():
|
| 475 |
+
assert dup_real_imag([], ZZ) == ([[]], [[]])
|
| 476 |
+
assert dup_real_imag([1], ZZ) == ([[1]], [[]])
|
| 477 |
+
|
| 478 |
+
assert dup_real_imag([1, 1], ZZ) == ([[1], [1]], [[1, 0]])
|
| 479 |
+
assert dup_real_imag([1, 2], ZZ) == ([[1], [2]], [[1, 0]])
|
| 480 |
+
|
| 481 |
+
assert dup_real_imag(
|
| 482 |
+
[1, 2, 3], ZZ) == ([[1], [2], [-1, 0, 3]], [[2, 0], [2, 0]])
|
| 483 |
+
|
| 484 |
+
assert dup_real_imag([ZZ(1), ZZ(0), ZZ(1), ZZ(3)], ZZ) == (
|
| 485 |
+
[[ZZ(1)], [], [ZZ(-3), ZZ(0), ZZ(1)], [ZZ(3)]],
|
| 486 |
+
[[ZZ(3), ZZ(0)], [], [ZZ(-1), ZZ(0), ZZ(1), ZZ(0)]]
|
| 487 |
+
)
|
| 488 |
+
|
| 489 |
+
raises(DomainError, lambda: dup_real_imag([EX(1), EX(2)], EX))
|
| 490 |
+
|
| 491 |
+
|
| 492 |
+
|
| 493 |
+
def test_dup_mirror():
|
| 494 |
+
assert dup_mirror([], ZZ) == []
|
| 495 |
+
assert dup_mirror([1], ZZ) == [1]
|
| 496 |
+
|
| 497 |
+
assert dup_mirror([1, 2, 3, 4, 5], ZZ) == [1, -2, 3, -4, 5]
|
| 498 |
+
assert dup_mirror([1, 2, 3, 4, 5, 6], ZZ) == [-1, 2, -3, 4, -5, 6]
|
| 499 |
+
|
| 500 |
+
|
| 501 |
+
def test_dup_scale():
|
| 502 |
+
assert dup_scale([], -1, ZZ) == []
|
| 503 |
+
assert dup_scale([1], -1, ZZ) == [1]
|
| 504 |
+
|
| 505 |
+
assert dup_scale([1, 2, 3, 4, 5], -1, ZZ) == [1, -2, 3, -4, 5]
|
| 506 |
+
assert dup_scale([1, 2, 3, 4, 5], -7, ZZ) == [2401, -686, 147, -28, 5]
|
| 507 |
+
|
| 508 |
+
|
| 509 |
+
def test_dup_shift():
|
| 510 |
+
assert dup_shift([], 1, ZZ) == []
|
| 511 |
+
assert dup_shift([1], 1, ZZ) == [1]
|
| 512 |
+
|
| 513 |
+
assert dup_shift([1, 2, 3, 4, 5], 1, ZZ) == [1, 6, 15, 20, 15]
|
| 514 |
+
assert dup_shift([1, 2, 3, 4, 5], 7, ZZ) == [1, 30, 339, 1712, 3267]
|
| 515 |
+
|
| 516 |
+
|
| 517 |
+
def test_dmp_shift():
|
| 518 |
+
assert dmp_shift([ZZ(1), ZZ(2)], [ZZ(1)], 0, ZZ) == [ZZ(1), ZZ(3)]
|
| 519 |
+
|
| 520 |
+
assert dmp_shift([[]], [ZZ(1), ZZ(2)], 1, ZZ) == [[]]
|
| 521 |
+
|
| 522 |
+
xy = [[ZZ(1), ZZ(0)], []] # x*y
|
| 523 |
+
x1y2 = [[ZZ(1), ZZ(2)], [ZZ(1), ZZ(2)]] # (x+1)*(y+2)
|
| 524 |
+
assert dmp_shift(xy, [ZZ(1), ZZ(2)], 1, ZZ) == x1y2
|
| 525 |
+
|
| 526 |
+
|
| 527 |
+
def test_dup_transform():
|
| 528 |
+
assert dup_transform([], [], [1, 1], ZZ) == []
|
| 529 |
+
assert dup_transform([], [1], [1, 1], ZZ) == []
|
| 530 |
+
assert dup_transform([], [1, 2], [1, 1], ZZ) == []
|
| 531 |
+
|
| 532 |
+
assert dup_transform([6, -5, 4, -3, 17], [1, -3, 4], [2, -3], ZZ) == \
|
| 533 |
+
[6, -82, 541, -2205, 6277, -12723, 17191, -13603, 4773]
|
| 534 |
+
|
| 535 |
+
|
| 536 |
+
def test_dup_compose():
|
| 537 |
+
assert dup_compose([], [], ZZ) == []
|
| 538 |
+
assert dup_compose([], [1], ZZ) == []
|
| 539 |
+
assert dup_compose([], [1, 2], ZZ) == []
|
| 540 |
+
|
| 541 |
+
assert dup_compose([1], [], ZZ) == [1]
|
| 542 |
+
|
| 543 |
+
assert dup_compose([1, 2, 0], [], ZZ) == []
|
| 544 |
+
assert dup_compose([1, 2, 1], [], ZZ) == [1]
|
| 545 |
+
|
| 546 |
+
assert dup_compose([1, 2, 1], [1], ZZ) == [4]
|
| 547 |
+
assert dup_compose([1, 2, 1], [7], ZZ) == [64]
|
| 548 |
+
|
| 549 |
+
assert dup_compose([1, 2, 1], [1, -1], ZZ) == [1, 0, 0]
|
| 550 |
+
assert dup_compose([1, 2, 1], [1, 1], ZZ) == [1, 4, 4]
|
| 551 |
+
assert dup_compose([1, 2, 1], [1, 2, 1], ZZ) == [1, 4, 8, 8, 4]
|
| 552 |
+
|
| 553 |
+
|
| 554 |
+
def test_dmp_compose():
|
| 555 |
+
assert dmp_compose([1, 2, 1], [1, 2, 1], 0, ZZ) == [1, 4, 8, 8, 4]
|
| 556 |
+
|
| 557 |
+
assert dmp_compose([[[]]], [[[]]], 2, ZZ) == [[[]]]
|
| 558 |
+
assert dmp_compose([[[]]], [[[1]]], 2, ZZ) == [[[]]]
|
| 559 |
+
assert dmp_compose([[[]]], [[[1]], [[2]]], 2, ZZ) == [[[]]]
|
| 560 |
+
|
| 561 |
+
assert dmp_compose([[[1]]], [], 2, ZZ) == [[[1]]]
|
| 562 |
+
|
| 563 |
+
assert dmp_compose([[1], [2], [ ]], [[]], 1, ZZ) == [[]]
|
| 564 |
+
assert dmp_compose([[1], [2], [1]], [[]], 1, ZZ) == [[1]]
|
| 565 |
+
|
| 566 |
+
assert dmp_compose([[1], [2], [1]], [[1]], 1, ZZ) == [[4]]
|
| 567 |
+
assert dmp_compose([[1], [2], [1]], [[7]], 1, ZZ) == [[64]]
|
| 568 |
+
|
| 569 |
+
assert dmp_compose([[1], [2], [1]], [[1], [-1]], 1, ZZ) == [[1], [ ], [ ]]
|
| 570 |
+
assert dmp_compose([[1], [2], [1]], [[1], [ 1]], 1, ZZ) == [[1], [4], [4]]
|
| 571 |
+
|
| 572 |
+
assert dmp_compose(
|
| 573 |
+
[[1], [2], [1]], [[1], [2], [1]], 1, ZZ) == [[1], [4], [8], [8], [4]]
|
| 574 |
+
|
| 575 |
+
|
| 576 |
+
def test_dup_decompose():
|
| 577 |
+
assert dup_decompose([1], ZZ) == [[1]]
|
| 578 |
+
|
| 579 |
+
assert dup_decompose([1, 0], ZZ) == [[1, 0]]
|
| 580 |
+
assert dup_decompose([1, 0, 0, 0], ZZ) == [[1, 0, 0, 0]]
|
| 581 |
+
|
| 582 |
+
assert dup_decompose([1, 0, 0, 0, 0], ZZ) == [[1, 0, 0], [1, 0, 0]]
|
| 583 |
+
assert dup_decompose(
|
| 584 |
+
[1, 0, 0, 0, 0, 0, 0], ZZ) == [[1, 0, 0, 0], [1, 0, 0]]
|
| 585 |
+
|
| 586 |
+
assert dup_decompose([7, 0, 0, 0, 1], ZZ) == [[7, 0, 1], [1, 0, 0]]
|
| 587 |
+
assert dup_decompose([4, 0, 3, 0, 2], ZZ) == [[4, 3, 2], [1, 0, 0]]
|
| 588 |
+
|
| 589 |
+
f = [1, 0, 20, 0, 150, 0, 500, 0, 625, -2, 0, -10, 9]
|
| 590 |
+
|
| 591 |
+
assert dup_decompose(f, ZZ) == [[1, 0, 0, -2, 9], [1, 0, 5, 0]]
|
| 592 |
+
|
| 593 |
+
f = [2, 0, 40, 0, 300, 0, 1000, 0, 1250, -4, 0, -20, 18]
|
| 594 |
+
|
| 595 |
+
assert dup_decompose(f, ZZ) == [[2, 0, 0, -4, 18], [1, 0, 5, 0]]
|
| 596 |
+
|
| 597 |
+
f = [1, 0, 20, -8, 150, -120, 524, -600, 865, -1034, 600, -170, 29]
|
| 598 |
+
|
| 599 |
+
assert dup_decompose(f, ZZ) == [[1, -8, 24, -34, 29], [1, 0, 5, 0]]
|
| 600 |
+
|
| 601 |
+
R, t = ring("t", ZZ)
|
| 602 |
+
f = [6*t**2 - 42,
|
| 603 |
+
48*t**2 + 96,
|
| 604 |
+
144*t**2 + 648*t + 288,
|
| 605 |
+
624*t**2 + 864*t + 384,
|
| 606 |
+
108*t**3 + 312*t**2 + 432*t + 192]
|
| 607 |
+
|
| 608 |
+
assert dup_decompose(f, R.to_domain()) == [f]
|
| 609 |
+
|
| 610 |
+
|
| 611 |
+
def test_dmp_lift():
|
| 612 |
+
q = [QQ(1, 1), QQ(0, 1), QQ(1, 1)]
|
| 613 |
+
|
| 614 |
+
f_a = [ANP([QQ(1, 1)], q, QQ), ANP([], q, QQ), ANP([], q, QQ),
|
| 615 |
+
ANP([QQ(1, 1), QQ(0, 1)], q, QQ), ANP([QQ(17, 1), QQ(0, 1)], q, QQ)]
|
| 616 |
+
|
| 617 |
+
f_lift = [QQ(1), QQ(0), QQ(0), QQ(0), QQ(0), QQ(0), QQ(2), QQ(0), QQ(578),
|
| 618 |
+
QQ(0), QQ(0), QQ(0), QQ(1), QQ(0), QQ(-578), QQ(0), QQ(83521)]
|
| 619 |
+
|
| 620 |
+
assert dmp_lift(f_a, 0, QQ.algebraic_field(I)) == f_lift
|
| 621 |
+
|
| 622 |
+
f_g = [QQ_I(1), QQ_I(0), QQ_I(0), QQ_I(0, 1), QQ_I(0, 17)]
|
| 623 |
+
|
| 624 |
+
assert dmp_lift(f_g, 0, QQ_I) == f_lift
|
| 625 |
+
|
| 626 |
+
raises(DomainError, lambda: dmp_lift([EX(1), EX(2)], 0, EX))
|
| 627 |
+
|
| 628 |
+
|
| 629 |
+
def test_dup_sign_variations():
|
| 630 |
+
assert dup_sign_variations([], ZZ) == 0
|
| 631 |
+
assert dup_sign_variations([1, 0], ZZ) == 0
|
| 632 |
+
assert dup_sign_variations([1, 0, 2], ZZ) == 0
|
| 633 |
+
assert dup_sign_variations([1, 0, 3, 0], ZZ) == 0
|
| 634 |
+
assert dup_sign_variations([1, 0, 4, 0, 5], ZZ) == 0
|
| 635 |
+
|
| 636 |
+
assert dup_sign_variations([-1, 0, 2], ZZ) == 1
|
| 637 |
+
assert dup_sign_variations([-1, 0, 3, 0], ZZ) == 1
|
| 638 |
+
assert dup_sign_variations([-1, 0, 4, 0, 5], ZZ) == 1
|
| 639 |
+
|
| 640 |
+
assert dup_sign_variations([-1, -4, -5], ZZ) == 0
|
| 641 |
+
assert dup_sign_variations([ 1, -4, -5], ZZ) == 1
|
| 642 |
+
assert dup_sign_variations([ 1, 4, -5], ZZ) == 1
|
| 643 |
+
assert dup_sign_variations([ 1, -4, 5], ZZ) == 2
|
| 644 |
+
assert dup_sign_variations([-1, 4, -5], ZZ) == 2
|
| 645 |
+
assert dup_sign_variations([-1, 4, 5], ZZ) == 1
|
| 646 |
+
assert dup_sign_variations([-1, -4, 5], ZZ) == 1
|
| 647 |
+
assert dup_sign_variations([ 1, 4, 5], ZZ) == 0
|
| 648 |
+
|
| 649 |
+
assert dup_sign_variations([-1, 0, -4, 0, -5], ZZ) == 0
|
| 650 |
+
assert dup_sign_variations([ 1, 0, -4, 0, -5], ZZ) == 1
|
| 651 |
+
assert dup_sign_variations([ 1, 0, 4, 0, -5], ZZ) == 1
|
| 652 |
+
assert dup_sign_variations([ 1, 0, -4, 0, 5], ZZ) == 2
|
| 653 |
+
assert dup_sign_variations([-1, 0, 4, 0, -5], ZZ) == 2
|
| 654 |
+
assert dup_sign_variations([-1, 0, 4, 0, 5], ZZ) == 1
|
| 655 |
+
assert dup_sign_variations([-1, 0, -4, 0, 5], ZZ) == 1
|
| 656 |
+
assert dup_sign_variations([ 1, 0, 4, 0, 5], ZZ) == 0
|
| 657 |
+
|
| 658 |
+
|
| 659 |
+
def test_dup_clear_denoms():
|
| 660 |
+
assert dup_clear_denoms([], QQ, ZZ) == (ZZ(1), [])
|
| 661 |
+
|
| 662 |
+
assert dup_clear_denoms([QQ(1)], QQ, ZZ) == (ZZ(1), [QQ(1)])
|
| 663 |
+
assert dup_clear_denoms([QQ(7)], QQ, ZZ) == (ZZ(1), [QQ(7)])
|
| 664 |
+
|
| 665 |
+
assert dup_clear_denoms([QQ(7, 3)], QQ) == (ZZ(3), [QQ(7)])
|
| 666 |
+
assert dup_clear_denoms([QQ(7, 3)], QQ, ZZ) == (ZZ(3), [QQ(7)])
|
| 667 |
+
|
| 668 |
+
assert dup_clear_denoms(
|
| 669 |
+
[QQ(3), QQ(1), QQ(0)], QQ, ZZ) == (ZZ(1), [QQ(3), QQ(1), QQ(0)])
|
| 670 |
+
assert dup_clear_denoms(
|
| 671 |
+
[QQ(1), QQ(1, 2), QQ(0)], QQ, ZZ) == (ZZ(2), [QQ(2), QQ(1), QQ(0)])
|
| 672 |
+
|
| 673 |
+
assert dup_clear_denoms([QQ(3), QQ(
|
| 674 |
+
1), QQ(0)], QQ, ZZ, convert=True) == (ZZ(1), [ZZ(3), ZZ(1), ZZ(0)])
|
| 675 |
+
assert dup_clear_denoms([QQ(1), QQ(
|
| 676 |
+
1, 2), QQ(0)], QQ, ZZ, convert=True) == (ZZ(2), [ZZ(2), ZZ(1), ZZ(0)])
|
| 677 |
+
|
| 678 |
+
assert dup_clear_denoms(
|
| 679 |
+
[EX(S(3)/2), EX(S(9)/4)], EX) == (EX(4), [EX(6), EX(9)])
|
| 680 |
+
|
| 681 |
+
assert dup_clear_denoms([EX(7)], EX) == (EX(1), [EX(7)])
|
| 682 |
+
assert dup_clear_denoms([EX(sin(x)/x), EX(0)], EX) == (EX(x), [EX(sin(x)), EX(0)])
|
| 683 |
+
|
| 684 |
+
F = RR.frac_field(x)
|
| 685 |
+
result = dup_clear_denoms([F(8.48717/(8.0089*x + 2.83)), F(0.0)], F)
|
| 686 |
+
assert str(result) == "(x + 0.353356890459364, [1.05971731448763, 0.0])"
|
| 687 |
+
|
| 688 |
+
def test_dmp_clear_denoms():
|
| 689 |
+
assert dmp_clear_denoms([[]], 1, QQ, ZZ) == (ZZ(1), [[]])
|
| 690 |
+
|
| 691 |
+
assert dmp_clear_denoms([[QQ(1)]], 1, QQ, ZZ) == (ZZ(1), [[QQ(1)]])
|
| 692 |
+
assert dmp_clear_denoms([[QQ(7)]], 1, QQ, ZZ) == (ZZ(1), [[QQ(7)]])
|
| 693 |
+
|
| 694 |
+
assert dmp_clear_denoms([[QQ(7, 3)]], 1, QQ) == (ZZ(3), [[QQ(7)]])
|
| 695 |
+
assert dmp_clear_denoms([[QQ(7, 3)]], 1, QQ, ZZ) == (ZZ(3), [[QQ(7)]])
|
| 696 |
+
|
| 697 |
+
assert dmp_clear_denoms(
|
| 698 |
+
[[QQ(3)], [QQ(1)], []], 1, QQ, ZZ) == (ZZ(1), [[QQ(3)], [QQ(1)], []])
|
| 699 |
+
assert dmp_clear_denoms([[QQ(
|
| 700 |
+
1)], [QQ(1, 2)], []], 1, QQ, ZZ) == (ZZ(2), [[QQ(2)], [QQ(1)], []])
|
| 701 |
+
|
| 702 |
+
assert dmp_clear_denoms([QQ(3), QQ(
|
| 703 |
+
1), QQ(0)], 0, QQ, ZZ, convert=True) == (ZZ(1), [ZZ(3), ZZ(1), ZZ(0)])
|
| 704 |
+
assert dmp_clear_denoms([QQ(1), QQ(1, 2), QQ(
|
| 705 |
+
0)], 0, QQ, ZZ, convert=True) == (ZZ(2), [ZZ(2), ZZ(1), ZZ(0)])
|
| 706 |
+
|
| 707 |
+
assert dmp_clear_denoms([[QQ(3)], [QQ(
|
| 708 |
+
1)], []], 1, QQ, ZZ, convert=True) == (ZZ(1), [[QQ(3)], [QQ(1)], []])
|
| 709 |
+
assert dmp_clear_denoms([[QQ(1)], [QQ(1, 2)], []], 1, QQ, ZZ,
|
| 710 |
+
convert=True) == (ZZ(2), [[QQ(2)], [QQ(1)], []])
|
| 711 |
+
|
| 712 |
+
assert dmp_clear_denoms(
|
| 713 |
+
[[EX(S(3)/2)], [EX(S(9)/4)]], 1, EX) == (EX(4), [[EX(6)], [EX(9)]])
|
| 714 |
+
assert dmp_clear_denoms([[EX(7)]], 1, EX) == (EX(1), [[EX(7)]])
|
| 715 |
+
assert dmp_clear_denoms([[EX(sin(x)/x), EX(0)]], 1, EX) == (EX(x), [[EX(sin(x)), EX(0)]])
|
pllava/lib/python3.10/site-packages/sympy/polys/tests/test_dispersion.py
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sympy.core import Symbol, S, oo
|
| 2 |
+
from sympy.functions.elementary.miscellaneous import sqrt
|
| 3 |
+
from sympy.polys import poly
|
| 4 |
+
from sympy.polys.dispersion import dispersion, dispersionset
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def test_dispersion():
|
| 8 |
+
x = Symbol("x")
|
| 9 |
+
a = Symbol("a")
|
| 10 |
+
|
| 11 |
+
fp = poly(S.Zero, x)
|
| 12 |
+
assert sorted(dispersionset(fp)) == [0]
|
| 13 |
+
|
| 14 |
+
fp = poly(S(2), x)
|
| 15 |
+
assert sorted(dispersionset(fp)) == [0]
|
| 16 |
+
|
| 17 |
+
fp = poly(x + 1, x)
|
| 18 |
+
assert sorted(dispersionset(fp)) == [0]
|
| 19 |
+
assert dispersion(fp) == 0
|
| 20 |
+
|
| 21 |
+
fp = poly((x + 1)*(x + 2), x)
|
| 22 |
+
assert sorted(dispersionset(fp)) == [0, 1]
|
| 23 |
+
assert dispersion(fp) == 1
|
| 24 |
+
|
| 25 |
+
fp = poly(x*(x + 3), x)
|
| 26 |
+
assert sorted(dispersionset(fp)) == [0, 3]
|
| 27 |
+
assert dispersion(fp) == 3
|
| 28 |
+
|
| 29 |
+
fp = poly((x - 3)*(x + 3), x)
|
| 30 |
+
assert sorted(dispersionset(fp)) == [0, 6]
|
| 31 |
+
assert dispersion(fp) == 6
|
| 32 |
+
|
| 33 |
+
fp = poly(x**4 - 3*x**2 + 1, x)
|
| 34 |
+
gp = fp.shift(-3)
|
| 35 |
+
assert sorted(dispersionset(fp, gp)) == [2, 3, 4]
|
| 36 |
+
assert dispersion(fp, gp) == 4
|
| 37 |
+
assert sorted(dispersionset(gp, fp)) == []
|
| 38 |
+
assert dispersion(gp, fp) is -oo
|
| 39 |
+
|
| 40 |
+
fp = poly(x*(3*x**2+a)*(x-2536)*(x**3+a), x)
|
| 41 |
+
gp = fp.as_expr().subs(x, x-345).as_poly(x)
|
| 42 |
+
assert sorted(dispersionset(fp, gp)) == [345, 2881]
|
| 43 |
+
assert sorted(dispersionset(gp, fp)) == [2191]
|
| 44 |
+
|
| 45 |
+
gp = poly((x-2)**2*(x-3)**3*(x-5)**3, x)
|
| 46 |
+
assert sorted(dispersionset(gp)) == [0, 1, 2, 3]
|
| 47 |
+
assert sorted(dispersionset(gp, (gp+4)**2)) == [1, 2]
|
| 48 |
+
|
| 49 |
+
fp = poly(x*(x+2)*(x-1), x)
|
| 50 |
+
assert sorted(dispersionset(fp)) == [0, 1, 2, 3]
|
| 51 |
+
|
| 52 |
+
fp = poly(x**2 + sqrt(5)*x - 1, x, domain='QQ<sqrt(5)>')
|
| 53 |
+
gp = poly(x**2 + (2 + sqrt(5))*x + sqrt(5), x, domain='QQ<sqrt(5)>')
|
| 54 |
+
assert sorted(dispersionset(fp, gp)) == [2]
|
| 55 |
+
assert sorted(dispersionset(gp, fp)) == [1, 4]
|
| 56 |
+
|
| 57 |
+
# There are some difficulties if we compute over Z[a]
|
| 58 |
+
# and alpha happenes to lie in Z[a] instead of simply Z.
|
| 59 |
+
# Hence we can not decide if alpha is indeed integral
|
| 60 |
+
# in general.
|
| 61 |
+
|
| 62 |
+
fp = poly(4*x**4 + (4*a + 8)*x**3 + (a**2 + 6*a + 4)*x**2 + (a**2 + 2*a)*x, x)
|
| 63 |
+
assert sorted(dispersionset(fp)) == [0, 1]
|
| 64 |
+
|
| 65 |
+
# For any specific value of a, the dispersion is 3*a
|
| 66 |
+
# but the algorithm can not find this in general.
|
| 67 |
+
# This is the point where the resultant based Ansatz
|
| 68 |
+
# is superior to the current one.
|
| 69 |
+
fp = poly(a**2*x**3 + (a**3 + a**2 + a + 1)*x, x)
|
| 70 |
+
gp = fp.as_expr().subs(x, x - 3*a).as_poly(x)
|
| 71 |
+
assert sorted(dispersionset(fp, gp)) == []
|
| 72 |
+
|
| 73 |
+
fpa = fp.as_expr().subs(a, 2).as_poly(x)
|
| 74 |
+
gpa = gp.as_expr().subs(a, 2).as_poly(x)
|
| 75 |
+
assert sorted(dispersionset(fpa, gpa)) == [6]
|
| 76 |
+
|
| 77 |
+
# Work with Expr instead of Poly
|
| 78 |
+
f = (x + 1)*(x + 2)
|
| 79 |
+
assert sorted(dispersionset(f)) == [0, 1]
|
| 80 |
+
assert dispersion(f) == 1
|
| 81 |
+
|
| 82 |
+
f = x**4 - 3*x**2 + 1
|
| 83 |
+
g = x**4 - 12*x**3 + 51*x**2 - 90*x + 55
|
| 84 |
+
assert sorted(dispersionset(f, g)) == [2, 3, 4]
|
| 85 |
+
assert dispersion(f, g) == 4
|
| 86 |
+
|
| 87 |
+
# Work with Expr and specify a generator
|
| 88 |
+
f = (x + 1)*(x + 2)
|
| 89 |
+
assert sorted(dispersionset(f, None, x)) == [0, 1]
|
| 90 |
+
assert dispersion(f, None, x) == 1
|
| 91 |
+
|
| 92 |
+
f = x**4 - 3*x**2 + 1
|
| 93 |
+
g = x**4 - 12*x**3 + 51*x**2 - 90*x + 55
|
| 94 |
+
assert sorted(dispersionset(f, g, x)) == [2, 3, 4]
|
| 95 |
+
assert dispersion(f, g, x) == 4
|
pllava/lib/python3.10/site-packages/sympy/polys/tests/test_distributedmodules.py
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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M, sdm_LT, sdm_mul_term, sdm_zero, sdm_deg,
|
| 6 |
+
sdm_LC, sdm_from_dict,
|
| 7 |
+
sdm_spoly, sdm_ecart, sdm_nf_mora, sdm_groebner,
|
| 8 |
+
sdm_from_vector, sdm_to_vector, sdm_monomial_lcm
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
from sympy.polys.orderings import lex, grlex, InverseOrder
|
| 12 |
+
from sympy.polys.domains import QQ
|
| 13 |
+
|
| 14 |
+
from sympy.abc import x, y, z
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def test_sdm_monomial_mul():
|
| 18 |
+
assert sdm_monomial_mul((1, 1, 0), (1, 3)) == (1, 2, 3)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def test_sdm_monomial_deg():
|
| 22 |
+
assert sdm_monomial_deg((5, 2, 1)) == 3
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def test_sdm_monomial_lcm():
|
| 26 |
+
assert sdm_monomial_lcm((1, 2, 3), (1, 5, 0)) == (1, 5, 3)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def test_sdm_monomial_divides():
|
| 30 |
+
assert sdm_monomial_divides((1, 0, 0), (1, 0, 0)) is True
|
| 31 |
+
assert sdm_monomial_divides((1, 0, 0), (1, 2, 1)) is True
|
| 32 |
+
assert sdm_monomial_divides((5, 1, 1), (5, 2, 1)) is True
|
| 33 |
+
|
| 34 |
+
assert sdm_monomial_divides((1, 0, 0), (2, 0, 0)) is False
|
| 35 |
+
assert sdm_monomial_divides((1, 1, 0), (1, 0, 0)) is False
|
| 36 |
+
assert sdm_monomial_divides((5, 1, 2), (5, 0, 1)) is False
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def test_sdm_LC():
|
| 40 |
+
assert sdm_LC([((1, 2, 3), QQ(5))], QQ) == QQ(5)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def test_sdm_from_dict():
|
| 44 |
+
dic = {(1, 2, 1, 1): QQ(1), (1, 1, 2, 1): QQ(1), (1, 0, 2, 1): QQ(1),
|
| 45 |
+
(1, 0, 0, 3): QQ(1), (1, 1, 1, 0): QQ(1)}
|
| 46 |
+
assert sdm_from_dict(dic, grlex) == \
|
| 47 |
+
[((1, 2, 1, 1), QQ(1)), ((1, 1, 2, 1), QQ(1)),
|
| 48 |
+
((1, 0, 2, 1), QQ(1)), ((1, 0, 0, 3), QQ(1)), ((1, 1, 1, 0), QQ(1))]
|
| 49 |
+
|
| 50 |
+
# TODO test to_dict?
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def test_sdm_add():
|
| 54 |
+
assert sdm_add([((1, 1, 1), QQ(1))], [((2, 0, 0), QQ(1))], lex, QQ) == \
|
| 55 |
+
[((2, 0, 0), QQ(1)), ((1, 1, 1), QQ(1))]
|
| 56 |
+
assert sdm_add([((1, 1, 1), QQ(1))], [((1, 1, 1), QQ(-1))], lex, QQ) == []
|
| 57 |
+
assert sdm_add([((1, 0, 0), QQ(1))], [((1, 0, 0), QQ(2))], lex, QQ) == \
|
| 58 |
+
[((1, 0, 0), QQ(3))]
|
| 59 |
+
assert sdm_add([((1, 0, 1), QQ(1))], [((1, 1, 0), QQ(1))], lex, QQ) == \
|
| 60 |
+
[((1, 1, 0), QQ(1)), ((1, 0, 1), QQ(1))]
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def test_sdm_LM():
|
| 64 |
+
dic = {(1, 2, 3): QQ(1), (4, 0, 0): QQ(1), (4, 0, 1): QQ(1)}
|
| 65 |
+
assert sdm_LM(sdm_from_dict(dic, lex)) == (4, 0, 1)
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def test_sdm_LT():
|
| 69 |
+
dic = {(1, 2, 3): QQ(1), (4, 0, 0): QQ(2), (4, 0, 1): QQ(3)}
|
| 70 |
+
assert sdm_LT(sdm_from_dict(dic, lex)) == ((4, 0, 1), QQ(3))
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def test_sdm_mul_term():
|
| 74 |
+
assert sdm_mul_term([((1, 0, 0), QQ(1))], ((0, 0), QQ(0)), lex, QQ) == []
|
| 75 |
+
assert sdm_mul_term([], ((1, 0), QQ(1)), lex, QQ) == []
|
| 76 |
+
assert sdm_mul_term([((1, 0, 0), QQ(1))], ((1, 0), QQ(1)), lex, QQ) == \
|
| 77 |
+
[((1, 1, 0), QQ(1))]
|
| 78 |
+
f = [((2, 0, 1), QQ(4)), ((1, 1, 0), QQ(3))]
|
| 79 |
+
assert sdm_mul_term(f, ((1, 1), QQ(2)), lex, QQ) == \
|
| 80 |
+
[((2, 1, 2), QQ(8)), ((1, 2, 1), QQ(6))]
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def test_sdm_zero():
|
| 84 |
+
assert sdm_zero() == []
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
def test_sdm_deg():
|
| 88 |
+
assert sdm_deg([((1, 2, 3), 1), ((10, 0, 1), 1), ((2, 3, 4), 4)]) == 7
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
def test_sdm_spoly():
|
| 92 |
+
f = [((2, 1, 1), QQ(1)), ((1, 0, 1), QQ(1))]
|
| 93 |
+
g = [((2, 3, 0), QQ(1))]
|
| 94 |
+
h = [((1, 2, 3), QQ(1))]
|
| 95 |
+
assert sdm_spoly(f, h, lex, QQ) == []
|
| 96 |
+
assert sdm_spoly(f, g, lex, QQ) == [((1, 2, 1), QQ(1))]
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
def test_sdm_ecart():
|
| 100 |
+
assert sdm_ecart([((1, 2, 3), 1), ((1, 0, 1), 1)]) == 0
|
| 101 |
+
assert sdm_ecart([((2, 2, 1), 1), ((1, 5, 1), 1)]) == 3
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
def test_sdm_nf_mora():
|
| 105 |
+
f = sdm_from_dict({(1, 2, 1, 1): QQ(1), (1, 1, 2, 1): QQ(1),
|
| 106 |
+
(1, 0, 2, 1): QQ(1), (1, 0, 0, 3): QQ(1), (1, 1, 1, 0): QQ(1)},
|
| 107 |
+
grlex)
|
| 108 |
+
f1 = sdm_from_dict({(1, 1, 1, 0): QQ(1), (1, 0, 2, 0): QQ(1),
|
| 109 |
+
(1, 0, 0, 0): QQ(-1)}, grlex)
|
| 110 |
+
f2 = sdm_from_dict({(1, 1, 1, 0): QQ(1)}, grlex)
|
| 111 |
+
(id0, id1, id2) = [sdm_from_dict({(i, 0, 0, 0): QQ(1)}, grlex)
|
| 112 |
+
for i in range(3)]
|
| 113 |
+
|
| 114 |
+
assert sdm_nf_mora(f, [f1, f2], grlex, QQ, phantom=(id0, [id1, id2])) == \
|
| 115 |
+
([((1, 0, 2, 1), QQ(1)), ((1, 0, 0, 3), QQ(1)), ((1, 1, 1, 0), QQ(1)),
|
| 116 |
+
((1, 1, 0, 1), QQ(1))],
|
| 117 |
+
[((1, 1, 0, 1), QQ(-1)), ((0, 0, 0, 0), QQ(1))])
|
| 118 |
+
assert sdm_nf_mora(f, [f2, f1], grlex, QQ, phantom=(id0, [id2, id1])) == \
|
| 119 |
+
([((1, 0, 2, 1), QQ(1)), ((1, 0, 0, 3), QQ(1)), ((1, 1, 1, 0), QQ(1))],
|
| 120 |
+
[((2, 1, 0, 1), QQ(-1)), ((2, 0, 1, 1), QQ(-1)), ((0, 0, 0, 0), QQ(1))])
|
| 121 |
+
|
| 122 |
+
f = sdm_from_vector([x*z, y**2 + y*z - z, y], lex, QQ, gens=[x, y, z])
|
| 123 |
+
f1 = sdm_from_vector([x, y, 1], lex, QQ, gens=[x, y, z])
|
| 124 |
+
f2 = sdm_from_vector([x*y, z, z**2], lex, QQ, gens=[x, y, z])
|
| 125 |
+
assert sdm_nf_mora(f, [f1, f2], lex, QQ) == \
|
| 126 |
+
sdm_nf_mora(f, [f2, f1], lex, QQ) == \
|
| 127 |
+
[((1, 0, 1, 1), QQ(1)), ((1, 0, 0, 1), QQ(-1)), ((0, 1, 1, 0), QQ(-1)),
|
| 128 |
+
((0, 1, 0, 1), QQ(1))]
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
def test_conversion():
|
| 132 |
+
f = [x**2 + y**2, 2*z]
|
| 133 |
+
g = [((1, 0, 0, 1), QQ(2)), ((0, 2, 0, 0), QQ(1)), ((0, 0, 2, 0), QQ(1))]
|
| 134 |
+
assert sdm_to_vector(g, [x, y, z], QQ) == f
|
| 135 |
+
assert sdm_from_vector(f, lex, QQ) == g
|
| 136 |
+
assert sdm_from_vector(
|
| 137 |
+
[x, 1], lex, QQ) == [((1, 0), QQ(1)), ((0, 1), QQ(1))]
|
| 138 |
+
assert sdm_to_vector([((1, 1, 0, 0), 1)], [x, y, z], QQ, n=3) == [0, x, 0]
|
| 139 |
+
assert sdm_from_vector([0, 0], lex, QQ, gens=[x, y]) == sdm_zero()
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
def test_nontrivial():
|
| 143 |
+
gens = [x, y, z]
|
| 144 |
+
|
| 145 |
+
def contains(I, f):
|
| 146 |
+
S = [sdm_from_vector([g], lex, QQ, gens=gens) for g in I]
|
| 147 |
+
G = sdm_groebner(S, sdm_nf_mora, lex, QQ)
|
| 148 |
+
return sdm_nf_mora(sdm_from_vector([f], lex, QQ, gens=gens),
|
| 149 |
+
G, lex, QQ) == sdm_zero()
|
| 150 |
+
|
| 151 |
+
assert contains([x, y], x)
|
| 152 |
+
assert contains([x, y], x + y)
|
| 153 |
+
assert not contains([x, y], 1)
|
| 154 |
+
assert not contains([x, y], z)
|
| 155 |
+
assert contains([x**2 + y, x**2 + x], x - y)
|
| 156 |
+
assert not contains([x + y + z, x*y + x*z + y*z, x*y*z], x**2)
|
| 157 |
+
assert contains([x + y + z, x*y + x*z + y*z, x*y*z], x**3)
|
| 158 |
+
assert contains([x + y + z, x*y + x*z + y*z, x*y*z], x**4)
|
| 159 |
+
assert not contains([x + y + z, x*y + x*z + y*z, x*y*z], x*y**2)
|
| 160 |
+
assert contains([x + y + z, x*y + x*z + y*z, x*y*z], x**4 + y**3 + 2*z*y*x)
|
| 161 |
+
assert contains([x + y + z, x*y + x*z + y*z, x*y*z], x*y*z)
|
| 162 |
+
assert contains([x, 1 + x + y, 5 - 7*y], 1)
|
| 163 |
+
assert contains(
|
| 164 |
+
[x**3 + y**3, y**3 + z**3, z**3 + x**3, x**2*y + x**2*z + y**2*z],
|
| 165 |
+
x**3)
|
| 166 |
+
assert not contains(
|
| 167 |
+
[x**3 + y**3, y**3 + z**3, z**3 + x**3, x**2*y + x**2*z + y**2*z],
|
| 168 |
+
x**2 + y**2)
|
| 169 |
+
|
| 170 |
+
# compare local order
|
| 171 |
+
assert not contains([x*(1 + x + y), y*(1 + z)], x)
|
| 172 |
+
assert not contains([x*(1 + x + y), y*(1 + z)], x + y)
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
def test_local():
|
| 176 |
+
igrlex = InverseOrder(grlex)
|
| 177 |
+
gens = [x, y, z]
|
| 178 |
+
|
| 179 |
+
def contains(I, f):
|
| 180 |
+
S = [sdm_from_vector([g], igrlex, QQ, gens=gens) for g in I]
|
| 181 |
+
G = sdm_groebner(S, sdm_nf_mora, igrlex, QQ)
|
| 182 |
+
return sdm_nf_mora(sdm_from_vector([f], lex, QQ, gens=gens),
|
| 183 |
+
G, lex, QQ) == sdm_zero()
|
| 184 |
+
assert contains([x, y], x)
|
| 185 |
+
assert contains([x, y], x + y)
|
| 186 |
+
assert not contains([x, y], 1)
|
| 187 |
+
assert not contains([x, y], z)
|
| 188 |
+
assert contains([x**2 + y, x**2 + x], x - y)
|
| 189 |
+
assert not contains([x + y + z, x*y + x*z + y*z, x*y*z], x**2)
|
| 190 |
+
assert contains([x*(1 + x + y), y*(1 + z)], x)
|
| 191 |
+
assert contains([x*(1 + x + y), y*(1 + z)], x + y)
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
def test_uncovered_line():
|
| 195 |
+
gens = [x, y]
|
| 196 |
+
f1 = sdm_zero()
|
| 197 |
+
f2 = sdm_from_vector([x, 0], lex, QQ, gens=gens)
|
| 198 |
+
f3 = sdm_from_vector([0, y], lex, QQ, gens=gens)
|
| 199 |
+
|
| 200 |
+
assert sdm_spoly(f1, f2, lex, QQ) == sdm_zero()
|
| 201 |
+
assert sdm_spoly(f3, f2, lex, QQ) == sdm_zero()
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
def test_chain_criterion():
|
| 205 |
+
gens = [x]
|
| 206 |
+
f1 = sdm_from_vector([1, x], grlex, QQ, gens=gens)
|
| 207 |
+
f2 = sdm_from_vector([0, x - 2], grlex, QQ, gens=gens)
|
| 208 |
+
assert len(sdm_groebner([f1, f2], sdm_nf_mora, grlex, QQ)) == 2
|
pllava/lib/python3.10/site-packages/sympy/polys/tests/test_euclidtools.py
ADDED
|
@@ -0,0 +1,712 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for Euclidean algorithms, GCDs, LCMs and polynomial remainder sequences. """
|
| 2 |
+
|
| 3 |
+
from sympy.polys.rings import ring
|
| 4 |
+
from sympy.polys.domains import ZZ, QQ, RR
|
| 5 |
+
|
| 6 |
+
from sympy.polys.specialpolys import (
|
| 7 |
+
f_polys,
|
| 8 |
+
dmp_fateman_poly_F_1,
|
| 9 |
+
dmp_fateman_poly_F_2,
|
| 10 |
+
dmp_fateman_poly_F_3)
|
| 11 |
+
|
| 12 |
+
f_0, f_1, f_2, f_3, f_4, f_5, f_6 = f_polys()
|
| 13 |
+
|
| 14 |
+
def test_dup_gcdex():
|
| 15 |
+
R, x = ring("x", QQ)
|
| 16 |
+
|
| 17 |
+
f = x**4 - 2*x**3 - 6*x**2 + 12*x + 15
|
| 18 |
+
g = x**3 + x**2 - 4*x - 4
|
| 19 |
+
|
| 20 |
+
s = -QQ(1,5)*x + QQ(3,5)
|
| 21 |
+
t = QQ(1,5)*x**2 - QQ(6,5)*x + 2
|
| 22 |
+
h = x + 1
|
| 23 |
+
|
| 24 |
+
assert R.dup_half_gcdex(f, g) == (s, h)
|
| 25 |
+
assert R.dup_gcdex(f, g) == (s, t, h)
|
| 26 |
+
|
| 27 |
+
f = x**4 + 4*x**3 - x + 1
|
| 28 |
+
g = x**3 - x + 1
|
| 29 |
+
|
| 30 |
+
s, t, h = R.dup_gcdex(f, g)
|
| 31 |
+
S, T, H = R.dup_gcdex(g, f)
|
| 32 |
+
|
| 33 |
+
assert R.dup_add(R.dup_mul(s, f),
|
| 34 |
+
R.dup_mul(t, g)) == h
|
| 35 |
+
assert R.dup_add(R.dup_mul(S, g),
|
| 36 |
+
R.dup_mul(T, f)) == H
|
| 37 |
+
|
| 38 |
+
f = 2*x
|
| 39 |
+
g = x**2 - 16
|
| 40 |
+
|
| 41 |
+
s = QQ(1,32)*x
|
| 42 |
+
t = -QQ(1,16)
|
| 43 |
+
h = 1
|
| 44 |
+
|
| 45 |
+
assert R.dup_half_gcdex(f, g) == (s, h)
|
| 46 |
+
assert R.dup_gcdex(f, g) == (s, t, h)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def test_dup_invert():
|
| 50 |
+
R, x = ring("x", QQ)
|
| 51 |
+
assert R.dup_invert(2*x, x**2 - 16) == QQ(1,32)*x
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def test_dup_euclidean_prs():
|
| 55 |
+
R, x = ring("x", QQ)
|
| 56 |
+
|
| 57 |
+
f = x**8 + x**6 - 3*x**4 - 3*x**3 + 8*x**2 + 2*x - 5
|
| 58 |
+
g = 3*x**6 + 5*x**4 - 4*x**2 - 9*x + 21
|
| 59 |
+
|
| 60 |
+
assert R.dup_euclidean_prs(f, g) == [
|
| 61 |
+
f,
|
| 62 |
+
g,
|
| 63 |
+
-QQ(5,9)*x**4 + QQ(1,9)*x**2 - QQ(1,3),
|
| 64 |
+
-QQ(117,25)*x**2 - 9*x + QQ(441,25),
|
| 65 |
+
QQ(233150,19773)*x - QQ(102500,6591),
|
| 66 |
+
-QQ(1288744821,543589225)]
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def test_dup_primitive_prs():
|
| 70 |
+
R, x = ring("x", ZZ)
|
| 71 |
+
|
| 72 |
+
f = x**8 + x**6 - 3*x**4 - 3*x**3 + 8*x**2 + 2*x - 5
|
| 73 |
+
g = 3*x**6 + 5*x**4 - 4*x**2 - 9*x + 21
|
| 74 |
+
|
| 75 |
+
assert R.dup_primitive_prs(f, g) == [
|
| 76 |
+
f,
|
| 77 |
+
g,
|
| 78 |
+
-5*x**4 + x**2 - 3,
|
| 79 |
+
13*x**2 + 25*x - 49,
|
| 80 |
+
4663*x - 6150,
|
| 81 |
+
1]
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def test_dup_subresultants():
|
| 85 |
+
R, x = ring("x", ZZ)
|
| 86 |
+
|
| 87 |
+
assert R.dup_resultant(0, 0) == 0
|
| 88 |
+
|
| 89 |
+
assert R.dup_resultant(1, 0) == 0
|
| 90 |
+
assert R.dup_resultant(0, 1) == 0
|
| 91 |
+
|
| 92 |
+
f = x**8 + x**6 - 3*x**4 - 3*x**3 + 8*x**2 + 2*x - 5
|
| 93 |
+
g = 3*x**6 + 5*x**4 - 4*x**2 - 9*x + 21
|
| 94 |
+
|
| 95 |
+
a = 15*x**4 - 3*x**2 + 9
|
| 96 |
+
b = 65*x**2 + 125*x - 245
|
| 97 |
+
c = 9326*x - 12300
|
| 98 |
+
d = 260708
|
| 99 |
+
|
| 100 |
+
assert R.dup_subresultants(f, g) == [f, g, a, b, c, d]
|
| 101 |
+
assert R.dup_resultant(f, g) == R.dup_LC(d)
|
| 102 |
+
|
| 103 |
+
f = x**2 - 2*x + 1
|
| 104 |
+
g = x**2 - 1
|
| 105 |
+
|
| 106 |
+
a = 2*x - 2
|
| 107 |
+
|
| 108 |
+
assert R.dup_subresultants(f, g) == [f, g, a]
|
| 109 |
+
assert R.dup_resultant(f, g) == 0
|
| 110 |
+
|
| 111 |
+
f = x**2 + 1
|
| 112 |
+
g = x**2 - 1
|
| 113 |
+
|
| 114 |
+
a = -2
|
| 115 |
+
|
| 116 |
+
assert R.dup_subresultants(f, g) == [f, g, a]
|
| 117 |
+
assert R.dup_resultant(f, g) == 4
|
| 118 |
+
|
| 119 |
+
f = x**2 - 1
|
| 120 |
+
g = x**3 - x**2 + 2
|
| 121 |
+
|
| 122 |
+
assert R.dup_resultant(f, g) == 0
|
| 123 |
+
|
| 124 |
+
f = 3*x**3 - x
|
| 125 |
+
g = 5*x**2 + 1
|
| 126 |
+
|
| 127 |
+
assert R.dup_resultant(f, g) == 64
|
| 128 |
+
|
| 129 |
+
f = x**2 - 2*x + 7
|
| 130 |
+
g = x**3 - x + 5
|
| 131 |
+
|
| 132 |
+
assert R.dup_resultant(f, g) == 265
|
| 133 |
+
|
| 134 |
+
f = x**3 - 6*x**2 + 11*x - 6
|
| 135 |
+
g = x**3 - 15*x**2 + 74*x - 120
|
| 136 |
+
|
| 137 |
+
assert R.dup_resultant(f, g) == -8640
|
| 138 |
+
|
| 139 |
+
f = x**3 - 6*x**2 + 11*x - 6
|
| 140 |
+
g = x**3 - 10*x**2 + 29*x - 20
|
| 141 |
+
|
| 142 |
+
assert R.dup_resultant(f, g) == 0
|
| 143 |
+
|
| 144 |
+
f = x**3 - 1
|
| 145 |
+
g = x**3 + 2*x**2 + 2*x - 1
|
| 146 |
+
|
| 147 |
+
assert R.dup_resultant(f, g) == 16
|
| 148 |
+
|
| 149 |
+
f = x**8 - 2
|
| 150 |
+
g = x - 1
|
| 151 |
+
|
| 152 |
+
assert R.dup_resultant(f, g) == -1
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
def test_dmp_subresultants():
|
| 156 |
+
R, x, y = ring("x,y", ZZ)
|
| 157 |
+
|
| 158 |
+
assert R.dmp_resultant(0, 0) == 0
|
| 159 |
+
assert R.dmp_prs_resultant(0, 0)[0] == 0
|
| 160 |
+
assert R.dmp_zz_collins_resultant(0, 0) == 0
|
| 161 |
+
assert R.dmp_qq_collins_resultant(0, 0) == 0
|
| 162 |
+
|
| 163 |
+
assert R.dmp_resultant(1, 0) == 0
|
| 164 |
+
assert R.dmp_resultant(1, 0) == 0
|
| 165 |
+
assert R.dmp_resultant(1, 0) == 0
|
| 166 |
+
|
| 167 |
+
assert R.dmp_resultant(0, 1) == 0
|
| 168 |
+
assert R.dmp_prs_resultant(0, 1)[0] == 0
|
| 169 |
+
assert R.dmp_zz_collins_resultant(0, 1) == 0
|
| 170 |
+
assert R.dmp_qq_collins_resultant(0, 1) == 0
|
| 171 |
+
|
| 172 |
+
f = 3*x**2*y - y**3 - 4
|
| 173 |
+
g = x**2 + x*y**3 - 9
|
| 174 |
+
|
| 175 |
+
a = 3*x*y**4 + y**3 - 27*y + 4
|
| 176 |
+
b = -3*y**10 - 12*y**7 + y**6 - 54*y**4 + 8*y**3 + 729*y**2 - 216*y + 16
|
| 177 |
+
|
| 178 |
+
r = R.dmp_LC(b)
|
| 179 |
+
|
| 180 |
+
assert R.dmp_subresultants(f, g) == [f, g, a, b]
|
| 181 |
+
|
| 182 |
+
assert R.dmp_resultant(f, g) == r
|
| 183 |
+
assert R.dmp_prs_resultant(f, g)[0] == r
|
| 184 |
+
assert R.dmp_zz_collins_resultant(f, g) == r
|
| 185 |
+
assert R.dmp_qq_collins_resultant(f, g) == r
|
| 186 |
+
|
| 187 |
+
f = -x**3 + 5
|
| 188 |
+
g = 3*x**2*y + x**2
|
| 189 |
+
|
| 190 |
+
a = 45*y**2 + 30*y + 5
|
| 191 |
+
b = 675*y**3 + 675*y**2 + 225*y + 25
|
| 192 |
+
|
| 193 |
+
r = R.dmp_LC(b)
|
| 194 |
+
|
| 195 |
+
assert R.dmp_subresultants(f, g) == [f, g, a]
|
| 196 |
+
assert R.dmp_resultant(f, g) == r
|
| 197 |
+
assert R.dmp_prs_resultant(f, g)[0] == r
|
| 198 |
+
assert R.dmp_zz_collins_resultant(f, g) == r
|
| 199 |
+
assert R.dmp_qq_collins_resultant(f, g) == r
|
| 200 |
+
|
| 201 |
+
R, x, y, z, u, v = ring("x,y,z,u,v", ZZ)
|
| 202 |
+
|
| 203 |
+
f = 6*x**2 - 3*x*y - 2*x*z + y*z
|
| 204 |
+
g = x**2 - x*u - x*v + u*v
|
| 205 |
+
|
| 206 |
+
r = y**2*z**2 - 3*y**2*z*u - 3*y**2*z*v + 9*y**2*u*v - 2*y*z**2*u \
|
| 207 |
+
- 2*y*z**2*v + 6*y*z*u**2 + 12*y*z*u*v + 6*y*z*v**2 - 18*y*u**2*v \
|
| 208 |
+
- 18*y*u*v**2 + 4*z**2*u*v - 12*z*u**2*v - 12*z*u*v**2 + 36*u**2*v**2
|
| 209 |
+
|
| 210 |
+
assert R.dmp_zz_collins_resultant(f, g) == r.drop(x)
|
| 211 |
+
|
| 212 |
+
R, x, y, z, u, v = ring("x,y,z,u,v", QQ)
|
| 213 |
+
|
| 214 |
+
f = x**2 - QQ(1,2)*x*y - QQ(1,3)*x*z + QQ(1,6)*y*z
|
| 215 |
+
g = x**2 - x*u - x*v + u*v
|
| 216 |
+
|
| 217 |
+
r = QQ(1,36)*y**2*z**2 - QQ(1,12)*y**2*z*u - QQ(1,12)*y**2*z*v + QQ(1,4)*y**2*u*v \
|
| 218 |
+
- QQ(1,18)*y*z**2*u - QQ(1,18)*y*z**2*v + QQ(1,6)*y*z*u**2 + QQ(1,3)*y*z*u*v \
|
| 219 |
+
+ QQ(1,6)*y*z*v**2 - QQ(1,2)*y*u**2*v - QQ(1,2)*y*u*v**2 + QQ(1,9)*z**2*u*v \
|
| 220 |
+
- QQ(1,3)*z*u**2*v - QQ(1,3)*z*u*v**2 + u**2*v**2
|
| 221 |
+
|
| 222 |
+
assert R.dmp_qq_collins_resultant(f, g) == r.drop(x)
|
| 223 |
+
|
| 224 |
+
Rt, t = ring("t", ZZ)
|
| 225 |
+
Rx, x = ring("x", Rt)
|
| 226 |
+
|
| 227 |
+
f = x**6 - 5*x**4 + 5*x**2 + 4
|
| 228 |
+
g = -6*t*x**5 + x**4 + 20*t*x**3 - 3*x**2 - 10*t*x + 6
|
| 229 |
+
|
| 230 |
+
assert Rx.dup_resultant(f, g) == 2930944*t**6 + 2198208*t**4 + 549552*t**2 + 45796
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
def test_dup_discriminant():
|
| 234 |
+
R, x = ring("x", ZZ)
|
| 235 |
+
|
| 236 |
+
assert R.dup_discriminant(0) == 0
|
| 237 |
+
assert R.dup_discriminant(x) == 1
|
| 238 |
+
|
| 239 |
+
assert R.dup_discriminant(x**3 + 3*x**2 + 9*x - 13) == -11664
|
| 240 |
+
assert R.dup_discriminant(5*x**5 + x**3 + 2) == 31252160
|
| 241 |
+
assert R.dup_discriminant(x**4 + 2*x**3 + 6*x**2 - 22*x + 13) == 0
|
| 242 |
+
assert R.dup_discriminant(12*x**7 + 15*x**4 + 30*x**3 + x**2 + 1) == -220289699947514112
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
def test_dmp_discriminant():
|
| 246 |
+
R, x = ring("x", ZZ)
|
| 247 |
+
|
| 248 |
+
assert R.dmp_discriminant(0) == 0
|
| 249 |
+
|
| 250 |
+
R, x, y = ring("x,y", ZZ)
|
| 251 |
+
|
| 252 |
+
assert R.dmp_discriminant(0) == 0
|
| 253 |
+
assert R.dmp_discriminant(y) == 0
|
| 254 |
+
|
| 255 |
+
assert R.dmp_discriminant(x**3 + 3*x**2 + 9*x - 13) == -11664
|
| 256 |
+
assert R.dmp_discriminant(5*x**5 + x**3 + 2) == 31252160
|
| 257 |
+
assert R.dmp_discriminant(x**4 + 2*x**3 + 6*x**2 - 22*x + 13) == 0
|
| 258 |
+
assert R.dmp_discriminant(12*x**7 + 15*x**4 + 30*x**3 + x**2 + 1) == -220289699947514112
|
| 259 |
+
|
| 260 |
+
assert R.dmp_discriminant(x**2*y + 2*y) == (-8*y**2).drop(x)
|
| 261 |
+
assert R.dmp_discriminant(x*y**2 + 2*x) == 1
|
| 262 |
+
|
| 263 |
+
R, x, y, z = ring("x,y,z", ZZ)
|
| 264 |
+
assert R.dmp_discriminant(x*y + z) == 1
|
| 265 |
+
|
| 266 |
+
R, x, y, z, u = ring("x,y,z,u", ZZ)
|
| 267 |
+
assert R.dmp_discriminant(x**2*y + x*z + u) == (-4*y*u + z**2).drop(x)
|
| 268 |
+
|
| 269 |
+
R, x, y, z, u, v = ring("x,y,z,u,v", ZZ)
|
| 270 |
+
assert R.dmp_discriminant(x**3*y + x**2*z + x*u + v) == \
|
| 271 |
+
(-27*y**2*v**2 + 18*y*z*u*v - 4*y*u**3 - 4*z**3*v + z**2*u**2).drop(x)
|
| 272 |
+
|
| 273 |
+
|
| 274 |
+
def test_dup_gcd():
|
| 275 |
+
R, x = ring("x", ZZ)
|
| 276 |
+
|
| 277 |
+
f, g = 0, 0
|
| 278 |
+
assert R.dup_zz_heu_gcd(f, g) == R.dup_rr_prs_gcd(f, g) == (0, 0, 0)
|
| 279 |
+
|
| 280 |
+
f, g = 2, 0
|
| 281 |
+
assert R.dup_zz_heu_gcd(f, g) == R.dup_rr_prs_gcd(f, g) == (2, 1, 0)
|
| 282 |
+
|
| 283 |
+
f, g = -2, 0
|
| 284 |
+
assert R.dup_zz_heu_gcd(f, g) == R.dup_rr_prs_gcd(f, g) == (2, -1, 0)
|
| 285 |
+
|
| 286 |
+
f, g = 0, -2
|
| 287 |
+
assert R.dup_zz_heu_gcd(f, g) == R.dup_rr_prs_gcd(f, g) == (2, 0, -1)
|
| 288 |
+
|
| 289 |
+
f, g = 0, 2*x + 4
|
| 290 |
+
assert R.dup_zz_heu_gcd(f, g) == R.dup_rr_prs_gcd(f, g) == (2*x + 4, 0, 1)
|
| 291 |
+
|
| 292 |
+
f, g = 2*x + 4, 0
|
| 293 |
+
assert R.dup_zz_heu_gcd(f, g) == R.dup_rr_prs_gcd(f, g) == (2*x + 4, 1, 0)
|
| 294 |
+
|
| 295 |
+
f, g = 2, 2
|
| 296 |
+
assert R.dup_zz_heu_gcd(f, g) == R.dup_rr_prs_gcd(f, g) == (2, 1, 1)
|
| 297 |
+
|
| 298 |
+
f, g = -2, 2
|
| 299 |
+
assert R.dup_zz_heu_gcd(f, g) == R.dup_rr_prs_gcd(f, g) == (2, -1, 1)
|
| 300 |
+
|
| 301 |
+
f, g = 2, -2
|
| 302 |
+
assert R.dup_zz_heu_gcd(f, g) == R.dup_rr_prs_gcd(f, g) == (2, 1, -1)
|
| 303 |
+
|
| 304 |
+
f, g = -2, -2
|
| 305 |
+
assert R.dup_zz_heu_gcd(f, g) == R.dup_rr_prs_gcd(f, g) == (2, -1, -1)
|
| 306 |
+
|
| 307 |
+
f, g = x**2 + 2*x + 1, 1
|
| 308 |
+
assert R.dup_zz_heu_gcd(f, g) == R.dup_rr_prs_gcd(f, g) == (1, x**2 + 2*x + 1, 1)
|
| 309 |
+
|
| 310 |
+
f, g = x**2 + 2*x + 1, 2
|
| 311 |
+
assert R.dup_zz_heu_gcd(f, g) == R.dup_rr_prs_gcd(f, g) == (1, x**2 + 2*x + 1, 2)
|
| 312 |
+
|
| 313 |
+
f, g = 2*x**2 + 4*x + 2, 2
|
| 314 |
+
assert R.dup_zz_heu_gcd(f, g) == R.dup_rr_prs_gcd(f, g) == (2, x**2 + 2*x + 1, 1)
|
| 315 |
+
|
| 316 |
+
f, g = 2, 2*x**2 + 4*x + 2
|
| 317 |
+
assert R.dup_zz_heu_gcd(f, g) == R.dup_rr_prs_gcd(f, g) == (2, 1, x**2 + 2*x + 1)
|
| 318 |
+
|
| 319 |
+
f, g = 2*x**2 + 4*x + 2, x + 1
|
| 320 |
+
assert R.dup_zz_heu_gcd(f, g) == R.dup_rr_prs_gcd(f, g) == (x + 1, 2*x + 2, 1)
|
| 321 |
+
|
| 322 |
+
f, g = x + 1, 2*x**2 + 4*x + 2
|
| 323 |
+
assert R.dup_zz_heu_gcd(f, g) == R.dup_rr_prs_gcd(f, g) == (x + 1, 1, 2*x + 2)
|
| 324 |
+
|
| 325 |
+
f, g = x - 31, x
|
| 326 |
+
assert R.dup_zz_heu_gcd(f, g) == R.dup_rr_prs_gcd(f, g) == (1, f, g)
|
| 327 |
+
|
| 328 |
+
f = x**4 + 8*x**3 + 21*x**2 + 22*x + 8
|
| 329 |
+
g = x**3 + 6*x**2 + 11*x + 6
|
| 330 |
+
|
| 331 |
+
h = x**2 + 3*x + 2
|
| 332 |
+
|
| 333 |
+
cff = x**2 + 5*x + 4
|
| 334 |
+
cfg = x + 3
|
| 335 |
+
|
| 336 |
+
assert R.dup_zz_heu_gcd(f, g) == (h, cff, cfg)
|
| 337 |
+
assert R.dup_rr_prs_gcd(f, g) == (h, cff, cfg)
|
| 338 |
+
|
| 339 |
+
f = x**4 - 4
|
| 340 |
+
g = x**4 + 4*x**2 + 4
|
| 341 |
+
|
| 342 |
+
h = x**2 + 2
|
| 343 |
+
|
| 344 |
+
cff = x**2 - 2
|
| 345 |
+
cfg = x**2 + 2
|
| 346 |
+
|
| 347 |
+
assert R.dup_zz_heu_gcd(f, g) == (h, cff, cfg)
|
| 348 |
+
assert R.dup_rr_prs_gcd(f, g) == (h, cff, cfg)
|
| 349 |
+
|
| 350 |
+
f = x**8 + x**6 - 3*x**4 - 3*x**3 + 8*x**2 + 2*x - 5
|
| 351 |
+
g = 3*x**6 + 5*x**4 - 4*x**2 - 9*x + 21
|
| 352 |
+
|
| 353 |
+
h = 1
|
| 354 |
+
|
| 355 |
+
cff = f
|
| 356 |
+
cfg = g
|
| 357 |
+
|
| 358 |
+
assert R.dup_zz_heu_gcd(f, g) == (h, cff, cfg)
|
| 359 |
+
assert R.dup_rr_prs_gcd(f, g) == (h, cff, cfg)
|
| 360 |
+
|
| 361 |
+
R, x = ring("x", QQ)
|
| 362 |
+
|
| 363 |
+
f = x**8 + x**6 - 3*x**4 - 3*x**3 + 8*x**2 + 2*x - 5
|
| 364 |
+
g = 3*x**6 + 5*x**4 - 4*x**2 - 9*x + 21
|
| 365 |
+
|
| 366 |
+
h = 1
|
| 367 |
+
|
| 368 |
+
cff = f
|
| 369 |
+
cfg = g
|
| 370 |
+
|
| 371 |
+
assert R.dup_qq_heu_gcd(f, g) == (h, cff, cfg)
|
| 372 |
+
assert R.dup_ff_prs_gcd(f, g) == (h, cff, cfg)
|
| 373 |
+
|
| 374 |
+
R, x = ring("x", ZZ)
|
| 375 |
+
|
| 376 |
+
f = - 352518131239247345597970242177235495263669787845475025293906825864749649589178600387510272*x**49 \
|
| 377 |
+
+ 46818041807522713962450042363465092040687472354933295397472942006618953623327997952*x**42 \
|
| 378 |
+
+ 378182690892293941192071663536490788434899030680411695933646320291525827756032*x**35 \
|
| 379 |
+
+ 112806468807371824947796775491032386836656074179286744191026149539708928*x**28 \
|
| 380 |
+
- 12278371209708240950316872681744825481125965781519138077173235712*x**21 \
|
| 381 |
+
+ 289127344604779611146960547954288113529690984687482920704*x**14 \
|
| 382 |
+
+ 19007977035740498977629742919480623972236450681*x**7 \
|
| 383 |
+
+ 311973482284542371301330321821976049
|
| 384 |
+
|
| 385 |
+
g = 365431878023781158602430064717380211405897160759702125019136*x**21 \
|
| 386 |
+
+ 197599133478719444145775798221171663643171734081650688*x**14 \
|
| 387 |
+
- 9504116979659010018253915765478924103928886144*x**7 \
|
| 388 |
+
- 311973482284542371301330321821976049
|
| 389 |
+
|
| 390 |
+
assert R.dup_zz_heu_gcd(f, R.dup_diff(f, 1))[0] == g
|
| 391 |
+
assert R.dup_rr_prs_gcd(f, R.dup_diff(f, 1))[0] == g
|
| 392 |
+
|
| 393 |
+
R, x = ring("x", QQ)
|
| 394 |
+
|
| 395 |
+
f = QQ(1,2)*x**2 + x + QQ(1,2)
|
| 396 |
+
g = QQ(1,2)*x + QQ(1,2)
|
| 397 |
+
|
| 398 |
+
h = x + 1
|
| 399 |
+
|
| 400 |
+
assert R.dup_qq_heu_gcd(f, g) == (h, g, QQ(1,2))
|
| 401 |
+
assert R.dup_ff_prs_gcd(f, g) == (h, g, QQ(1,2))
|
| 402 |
+
|
| 403 |
+
R, x = ring("x", ZZ)
|
| 404 |
+
|
| 405 |
+
f = 1317378933230047068160*x + 2945748836994210856960
|
| 406 |
+
g = 120352542776360960*x + 269116466014453760
|
| 407 |
+
|
| 408 |
+
h = 120352542776360960*x + 269116466014453760
|
| 409 |
+
cff = 10946
|
| 410 |
+
cfg = 1
|
| 411 |
+
|
| 412 |
+
assert R.dup_zz_heu_gcd(f, g) == (h, cff, cfg)
|
| 413 |
+
|
| 414 |
+
|
| 415 |
+
def test_dmp_gcd():
|
| 416 |
+
R, x, y = ring("x,y", ZZ)
|
| 417 |
+
|
| 418 |
+
f, g = 0, 0
|
| 419 |
+
assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (0, 0, 0)
|
| 420 |
+
|
| 421 |
+
f, g = 2, 0
|
| 422 |
+
assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (2, 1, 0)
|
| 423 |
+
|
| 424 |
+
f, g = -2, 0
|
| 425 |
+
assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (2, -1, 0)
|
| 426 |
+
|
| 427 |
+
f, g = 0, -2
|
| 428 |
+
assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (2, 0, -1)
|
| 429 |
+
|
| 430 |
+
f, g = 0, 2*x + 4
|
| 431 |
+
assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (2*x + 4, 0, 1)
|
| 432 |
+
|
| 433 |
+
f, g = 2*x + 4, 0
|
| 434 |
+
assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (2*x + 4, 1, 0)
|
| 435 |
+
|
| 436 |
+
f, g = 2, 2
|
| 437 |
+
assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (2, 1, 1)
|
| 438 |
+
|
| 439 |
+
f, g = -2, 2
|
| 440 |
+
assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (2, -1, 1)
|
| 441 |
+
|
| 442 |
+
f, g = 2, -2
|
| 443 |
+
assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (2, 1, -1)
|
| 444 |
+
|
| 445 |
+
f, g = -2, -2
|
| 446 |
+
assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (2, -1, -1)
|
| 447 |
+
|
| 448 |
+
f, g = x**2 + 2*x + 1, 1
|
| 449 |
+
assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (1, x**2 + 2*x + 1, 1)
|
| 450 |
+
|
| 451 |
+
f, g = x**2 + 2*x + 1, 2
|
| 452 |
+
assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (1, x**2 + 2*x + 1, 2)
|
| 453 |
+
|
| 454 |
+
f, g = 2*x**2 + 4*x + 2, 2
|
| 455 |
+
assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (2, x**2 + 2*x + 1, 1)
|
| 456 |
+
|
| 457 |
+
f, g = 2, 2*x**2 + 4*x + 2
|
| 458 |
+
assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (2, 1, x**2 + 2*x + 1)
|
| 459 |
+
|
| 460 |
+
f, g = 2*x**2 + 4*x + 2, x + 1
|
| 461 |
+
assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (x + 1, 2*x + 2, 1)
|
| 462 |
+
|
| 463 |
+
f, g = x + 1, 2*x**2 + 4*x + 2
|
| 464 |
+
assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (x + 1, 1, 2*x + 2)
|
| 465 |
+
|
| 466 |
+
R, x, y, z, u = ring("x,y,z,u", ZZ)
|
| 467 |
+
|
| 468 |
+
f, g = u**2 + 2*u + 1, 2*u + 2
|
| 469 |
+
assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (u + 1, u + 1, 2)
|
| 470 |
+
|
| 471 |
+
f, g = z**2*u**2 + 2*z**2*u + z**2 + z*u + z, u**2 + 2*u + 1
|
| 472 |
+
h, cff, cfg = u + 1, z**2*u + z**2 + z, u + 1
|
| 473 |
+
|
| 474 |
+
assert R.dmp_zz_heu_gcd(f, g) == (h, cff, cfg)
|
| 475 |
+
assert R.dmp_rr_prs_gcd(f, g) == (h, cff, cfg)
|
| 476 |
+
|
| 477 |
+
assert R.dmp_zz_heu_gcd(g, f) == (h, cfg, cff)
|
| 478 |
+
assert R.dmp_rr_prs_gcd(g, f) == (h, cfg, cff)
|
| 479 |
+
|
| 480 |
+
R, x, y, z = ring("x,y,z", ZZ)
|
| 481 |
+
|
| 482 |
+
f, g, h = map(R.from_dense, dmp_fateman_poly_F_1(2, ZZ))
|
| 483 |
+
H, cff, cfg = R.dmp_zz_heu_gcd(f, g)
|
| 484 |
+
|
| 485 |
+
assert H == h and R.dmp_mul(H, cff) == f \
|
| 486 |
+
and R.dmp_mul(H, cfg) == g
|
| 487 |
+
|
| 488 |
+
H, cff, cfg = R.dmp_rr_prs_gcd(f, g)
|
| 489 |
+
|
| 490 |
+
assert H == h and R.dmp_mul(H, cff) == f \
|
| 491 |
+
and R.dmp_mul(H, cfg) == g
|
| 492 |
+
|
| 493 |
+
R, x, y, z, u, v = ring("x,y,z,u,v", ZZ)
|
| 494 |
+
|
| 495 |
+
f, g, h = map(R.from_dense, dmp_fateman_poly_F_1(4, ZZ))
|
| 496 |
+
H, cff, cfg = R.dmp_zz_heu_gcd(f, g)
|
| 497 |
+
|
| 498 |
+
assert H == h and R.dmp_mul(H, cff) == f \
|
| 499 |
+
and R.dmp_mul(H, cfg) == g
|
| 500 |
+
|
| 501 |
+
R, x, y, z, u, v, a, b = ring("x,y,z,u,v,a,b", ZZ)
|
| 502 |
+
|
| 503 |
+
f, g, h = map(R.from_dense, dmp_fateman_poly_F_1(6, ZZ))
|
| 504 |
+
H, cff, cfg = R.dmp_zz_heu_gcd(f, g)
|
| 505 |
+
|
| 506 |
+
assert H == h and R.dmp_mul(H, cff) == f \
|
| 507 |
+
and R.dmp_mul(H, cfg) == g
|
| 508 |
+
|
| 509 |
+
R, x, y, z, u, v, a, b, c, d = ring("x,y,z,u,v,a,b,c,d", ZZ)
|
| 510 |
+
|
| 511 |
+
f, g, h = map(R.from_dense, dmp_fateman_poly_F_1(8, ZZ))
|
| 512 |
+
H, cff, cfg = R.dmp_zz_heu_gcd(f, g)
|
| 513 |
+
|
| 514 |
+
assert H == h and R.dmp_mul(H, cff) == f \
|
| 515 |
+
and R.dmp_mul(H, cfg) == g
|
| 516 |
+
|
| 517 |
+
R, x, y, z = ring("x,y,z", ZZ)
|
| 518 |
+
|
| 519 |
+
f, g, h = map(R.from_dense, dmp_fateman_poly_F_2(2, ZZ))
|
| 520 |
+
H, cff, cfg = R.dmp_zz_heu_gcd(f, g)
|
| 521 |
+
|
| 522 |
+
assert H == h and R.dmp_mul(H, cff) == f \
|
| 523 |
+
and R.dmp_mul(H, cfg) == g
|
| 524 |
+
|
| 525 |
+
H, cff, cfg = R.dmp_rr_prs_gcd(f, g)
|
| 526 |
+
|
| 527 |
+
assert H == h and R.dmp_mul(H, cff) == f \
|
| 528 |
+
and R.dmp_mul(H, cfg) == g
|
| 529 |
+
|
| 530 |
+
f, g, h = map(R.from_dense, dmp_fateman_poly_F_3(2, ZZ))
|
| 531 |
+
H, cff, cfg = R.dmp_zz_heu_gcd(f, g)
|
| 532 |
+
|
| 533 |
+
assert H == h and R.dmp_mul(H, cff) == f \
|
| 534 |
+
and R.dmp_mul(H, cfg) == g
|
| 535 |
+
|
| 536 |
+
H, cff, cfg = R.dmp_rr_prs_gcd(f, g)
|
| 537 |
+
|
| 538 |
+
assert H == h and R.dmp_mul(H, cff) == f \
|
| 539 |
+
and R.dmp_mul(H, cfg) == g
|
| 540 |
+
|
| 541 |
+
R, x, y, z, u, v = ring("x,y,z,u,v", ZZ)
|
| 542 |
+
|
| 543 |
+
f, g, h = map(R.from_dense, dmp_fateman_poly_F_3(4, ZZ))
|
| 544 |
+
H, cff, cfg = R.dmp_inner_gcd(f, g)
|
| 545 |
+
|
| 546 |
+
assert H == h and R.dmp_mul(H, cff) == f \
|
| 547 |
+
and R.dmp_mul(H, cfg) == g
|
| 548 |
+
|
| 549 |
+
R, x, y = ring("x,y", QQ)
|
| 550 |
+
|
| 551 |
+
f = QQ(1,2)*x**2 + x + QQ(1,2)
|
| 552 |
+
g = QQ(1,2)*x + QQ(1,2)
|
| 553 |
+
|
| 554 |
+
h = x + 1
|
| 555 |
+
|
| 556 |
+
assert R.dmp_qq_heu_gcd(f, g) == (h, g, QQ(1,2))
|
| 557 |
+
assert R.dmp_ff_prs_gcd(f, g) == (h, g, QQ(1,2))
|
| 558 |
+
|
| 559 |
+
R, x, y = ring("x,y", RR)
|
| 560 |
+
|
| 561 |
+
f = 2.1*x*y**2 - 2.2*x*y + 2.1*x
|
| 562 |
+
g = 1.0*x**3
|
| 563 |
+
|
| 564 |
+
assert R.dmp_ff_prs_gcd(f, g) == \
|
| 565 |
+
(1.0*x, 2.1*y**2 - 2.2*y + 2.1, 1.0*x**2)
|
| 566 |
+
|
| 567 |
+
|
| 568 |
+
def test_dup_lcm():
|
| 569 |
+
R, x = ring("x", ZZ)
|
| 570 |
+
|
| 571 |
+
assert R.dup_lcm(2, 6) == 6
|
| 572 |
+
|
| 573 |
+
assert R.dup_lcm(2*x**3, 6*x) == 6*x**3
|
| 574 |
+
assert R.dup_lcm(2*x**3, 3*x) == 6*x**3
|
| 575 |
+
|
| 576 |
+
assert R.dup_lcm(x**2 + x, x) == x**2 + x
|
| 577 |
+
assert R.dup_lcm(x**2 + x, 2*x) == 2*x**2 + 2*x
|
| 578 |
+
assert R.dup_lcm(x**2 + 2*x, x) == x**2 + 2*x
|
| 579 |
+
assert R.dup_lcm(2*x**2 + x, x) == 2*x**2 + x
|
| 580 |
+
assert R.dup_lcm(2*x**2 + x, 2*x) == 4*x**2 + 2*x
|
| 581 |
+
|
| 582 |
+
|
| 583 |
+
def test_dmp_lcm():
|
| 584 |
+
R, x, y = ring("x,y", ZZ)
|
| 585 |
+
|
| 586 |
+
assert R.dmp_lcm(2, 6) == 6
|
| 587 |
+
assert R.dmp_lcm(x, y) == x*y
|
| 588 |
+
|
| 589 |
+
assert R.dmp_lcm(2*x**3, 6*x*y**2) == 6*x**3*y**2
|
| 590 |
+
assert R.dmp_lcm(2*x**3, 3*x*y**2) == 6*x**3*y**2
|
| 591 |
+
|
| 592 |
+
assert R.dmp_lcm(x**2*y, x*y**2) == x**2*y**2
|
| 593 |
+
|
| 594 |
+
f = 2*x*y**5 - 3*x*y**4 - 2*x*y**3 + 3*x*y**2
|
| 595 |
+
g = y**5 - 2*y**3 + y
|
| 596 |
+
h = 2*x*y**7 - 3*x*y**6 - 4*x*y**5 + 6*x*y**4 + 2*x*y**3 - 3*x*y**2
|
| 597 |
+
|
| 598 |
+
assert R.dmp_lcm(f, g) == h
|
| 599 |
+
|
| 600 |
+
f = x**3 - 3*x**2*y - 9*x*y**2 - 5*y**3
|
| 601 |
+
g = x**4 + 6*x**3*y + 12*x**2*y**2 + 10*x*y**3 + 3*y**4
|
| 602 |
+
h = x**5 + x**4*y - 18*x**3*y**2 - 50*x**2*y**3 - 47*x*y**4 - 15*y**5
|
| 603 |
+
|
| 604 |
+
assert R.dmp_lcm(f, g) == h
|
| 605 |
+
|
| 606 |
+
|
| 607 |
+
def test_dmp_content():
|
| 608 |
+
R, x,y = ring("x,y", ZZ)
|
| 609 |
+
|
| 610 |
+
assert R.dmp_content(-2) == 2
|
| 611 |
+
|
| 612 |
+
f, g, F = 3*y**2 + 2*y + 1, 1, 0
|
| 613 |
+
|
| 614 |
+
for i in range(0, 5):
|
| 615 |
+
g *= f
|
| 616 |
+
F += x**i*g
|
| 617 |
+
|
| 618 |
+
assert R.dmp_content(F) == f.drop(x)
|
| 619 |
+
|
| 620 |
+
R, x,y,z = ring("x,y,z", ZZ)
|
| 621 |
+
|
| 622 |
+
assert R.dmp_content(f_4) == 1
|
| 623 |
+
assert R.dmp_content(f_5) == 1
|
| 624 |
+
|
| 625 |
+
R, x,y,z,t = ring("x,y,z,t", ZZ)
|
| 626 |
+
assert R.dmp_content(f_6) == 1
|
| 627 |
+
|
| 628 |
+
|
| 629 |
+
def test_dmp_primitive():
|
| 630 |
+
R, x,y = ring("x,y", ZZ)
|
| 631 |
+
|
| 632 |
+
assert R.dmp_primitive(0) == (0, 0)
|
| 633 |
+
assert R.dmp_primitive(1) == (1, 1)
|
| 634 |
+
|
| 635 |
+
f, g, F = 3*y**2 + 2*y + 1, 1, 0
|
| 636 |
+
|
| 637 |
+
for i in range(0, 5):
|
| 638 |
+
g *= f
|
| 639 |
+
F += x**i*g
|
| 640 |
+
|
| 641 |
+
assert R.dmp_primitive(F) == (f.drop(x), F / f)
|
| 642 |
+
|
| 643 |
+
R, x,y,z = ring("x,y,z", ZZ)
|
| 644 |
+
|
| 645 |
+
cont, f = R.dmp_primitive(f_4)
|
| 646 |
+
assert cont == 1 and f == f_4
|
| 647 |
+
cont, f = R.dmp_primitive(f_5)
|
| 648 |
+
assert cont == 1 and f == f_5
|
| 649 |
+
|
| 650 |
+
R, x,y,z,t = ring("x,y,z,t", ZZ)
|
| 651 |
+
|
| 652 |
+
cont, f = R.dmp_primitive(f_6)
|
| 653 |
+
assert cont == 1 and f == f_6
|
| 654 |
+
|
| 655 |
+
|
| 656 |
+
def test_dup_cancel():
|
| 657 |
+
R, x = ring("x", ZZ)
|
| 658 |
+
|
| 659 |
+
f = 2*x**2 - 2
|
| 660 |
+
g = x**2 - 2*x + 1
|
| 661 |
+
|
| 662 |
+
p = 2*x + 2
|
| 663 |
+
q = x - 1
|
| 664 |
+
|
| 665 |
+
assert R.dup_cancel(f, g) == (p, q)
|
| 666 |
+
assert R.dup_cancel(f, g, include=False) == (1, 1, p, q)
|
| 667 |
+
|
| 668 |
+
f = -x - 2
|
| 669 |
+
g = 3*x - 4
|
| 670 |
+
|
| 671 |
+
F = x + 2
|
| 672 |
+
G = -3*x + 4
|
| 673 |
+
|
| 674 |
+
assert R.dup_cancel(f, g) == (f, g)
|
| 675 |
+
assert R.dup_cancel(F, G) == (f, g)
|
| 676 |
+
|
| 677 |
+
assert R.dup_cancel(0, 0) == (0, 0)
|
| 678 |
+
assert R.dup_cancel(0, 0, include=False) == (1, 1, 0, 0)
|
| 679 |
+
|
| 680 |
+
assert R.dup_cancel(x, 0) == (1, 0)
|
| 681 |
+
assert R.dup_cancel(x, 0, include=False) == (1, 1, 1, 0)
|
| 682 |
+
|
| 683 |
+
assert R.dup_cancel(0, x) == (0, 1)
|
| 684 |
+
assert R.dup_cancel(0, x, include=False) == (1, 1, 0, 1)
|
| 685 |
+
|
| 686 |
+
f = 0
|
| 687 |
+
g = x
|
| 688 |
+
one = 1
|
| 689 |
+
|
| 690 |
+
assert R.dup_cancel(f, g, include=True) == (f, one)
|
| 691 |
+
|
| 692 |
+
|
| 693 |
+
def test_dmp_cancel():
|
| 694 |
+
R, x, y = ring("x,y", ZZ)
|
| 695 |
+
|
| 696 |
+
f = 2*x**2 - 2
|
| 697 |
+
g = x**2 - 2*x + 1
|
| 698 |
+
|
| 699 |
+
p = 2*x + 2
|
| 700 |
+
q = x - 1
|
| 701 |
+
|
| 702 |
+
assert R.dmp_cancel(f, g) == (p, q)
|
| 703 |
+
assert R.dmp_cancel(f, g, include=False) == (1, 1, p, q)
|
| 704 |
+
|
| 705 |
+
assert R.dmp_cancel(0, 0) == (0, 0)
|
| 706 |
+
assert R.dmp_cancel(0, 0, include=False) == (1, 1, 0, 0)
|
| 707 |
+
|
| 708 |
+
assert R.dmp_cancel(y, 0) == (1, 0)
|
| 709 |
+
assert R.dmp_cancel(y, 0, include=False) == (1, 1, 1, 0)
|
| 710 |
+
|
| 711 |
+
assert R.dmp_cancel(0, y) == (0, 1)
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tools for polynomial factorization routines in characteristic zero. """
|
| 2 |
+
|
| 3 |
+
from sympy.polys.rings import ring, xring
|
| 4 |
+
from sympy.polys.domains import FF, ZZ, QQ, ZZ_I, QQ_I, RR, EX
|
| 5 |
+
|
| 6 |
+
from sympy.polys import polyconfig as config
|
| 7 |
+
from sympy.polys.polyerrors import DomainError
|
| 8 |
+
from sympy.polys.polyclasses import ANP
|
| 9 |
+
from sympy.polys.specialpolys import f_polys, w_polys
|
| 10 |
+
|
| 11 |
+
from sympy.core.numbers import I
|
| 12 |
+
from sympy.functions.elementary.miscellaneous import sqrt
|
| 13 |
+
from sympy.functions.elementary.trigonometric import sin
|
| 14 |
+
from sympy.ntheory.generate import nextprime
|
| 15 |
+
from sympy.testing.pytest import raises, XFAIL
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
f_0, f_1, f_2, f_3, f_4, f_5, f_6 = f_polys()
|
| 19 |
+
w_1, w_2 = w_polys()
|
| 20 |
+
|
| 21 |
+
def test_dup_trial_division():
|
| 22 |
+
R, x = ring("x", ZZ)
|
| 23 |
+
assert R.dup_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)]
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def test_dmp_trial_division():
|
| 27 |
+
R, x, y = ring("x,y", ZZ)
|
| 28 |
+
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)]
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def test_dup_zz_mignotte_bound():
|
| 32 |
+
R, x = ring("x", ZZ)
|
| 33 |
+
assert R.dup_zz_mignotte_bound(2*x**2 + 3*x + 4) == 6
|
| 34 |
+
assert R.dup_zz_mignotte_bound(x**3 + 14*x**2 + 56*x + 64) == 152
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def test_dmp_zz_mignotte_bound():
|
| 38 |
+
R, x, y = ring("x,y", ZZ)
|
| 39 |
+
assert R.dmp_zz_mignotte_bound(2*x**2 + 3*x + 4) == 32
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def test_dup_zz_hensel_step():
|
| 43 |
+
R, x = ring("x", ZZ)
|
| 44 |
+
|
| 45 |
+
f = x**4 - 1
|
| 46 |
+
g = x**3 + 2*x**2 - x - 2
|
| 47 |
+
h = x - 2
|
| 48 |
+
s = -2
|
| 49 |
+
t = 2*x**2 - 2*x - 1
|
| 50 |
+
|
| 51 |
+
G, H, S, T = R.dup_zz_hensel_step(5, f, g, h, s, t)
|
| 52 |
+
|
| 53 |
+
assert G == x**3 + 7*x**2 - x - 7
|
| 54 |
+
assert H == x - 7
|
| 55 |
+
assert S == 8
|
| 56 |
+
assert T == -8*x**2 - 12*x - 1
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def test_dup_zz_hensel_lift():
|
| 60 |
+
R, x = ring("x", ZZ)
|
| 61 |
+
|
| 62 |
+
f = x**4 - 1
|
| 63 |
+
F = [x - 1, x - 2, x + 2, x + 1]
|
| 64 |
+
|
| 65 |
+
assert R.dup_zz_hensel_lift(ZZ(5), f, F, 4) == \
|
| 66 |
+
[x - 1, x - 182, x + 182, x + 1]
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def test_dup_zz_irreducible_p():
|
| 70 |
+
R, x = ring("x", ZZ)
|
| 71 |
+
|
| 72 |
+
assert R.dup_zz_irreducible_p(3*x**4 + 2*x**3 + 6*x**2 + 8*x + 7) is None
|
| 73 |
+
assert R.dup_zz_irreducible_p(3*x**4 + 2*x**3 + 6*x**2 + 8*x + 4) is None
|
| 74 |
+
|
| 75 |
+
assert R.dup_zz_irreducible_p(3*x**4 + 2*x**3 + 6*x**2 + 8*x + 10) is True
|
| 76 |
+
assert R.dup_zz_irreducible_p(3*x**4 + 2*x**3 + 6*x**2 + 8*x + 14) is True
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def test_dup_cyclotomic_p():
|
| 80 |
+
R, x = ring("x", ZZ)
|
| 81 |
+
|
| 82 |
+
assert R.dup_cyclotomic_p(x - 1) is True
|
| 83 |
+
assert R.dup_cyclotomic_p(x + 1) is True
|
| 84 |
+
assert R.dup_cyclotomic_p(x**2 + x + 1) is True
|
| 85 |
+
assert R.dup_cyclotomic_p(x**2 + 1) is True
|
| 86 |
+
assert R.dup_cyclotomic_p(x**4 + x**3 + x**2 + x + 1) is True
|
| 87 |
+
assert R.dup_cyclotomic_p(x**2 - x + 1) is True
|
| 88 |
+
assert R.dup_cyclotomic_p(x**6 + x**5 + x**4 + x**3 + x**2 + x + 1) is True
|
| 89 |
+
assert R.dup_cyclotomic_p(x**4 + 1) is True
|
| 90 |
+
assert R.dup_cyclotomic_p(x**6 + x**3 + 1) is True
|
| 91 |
+
|
| 92 |
+
assert R.dup_cyclotomic_p(0) is False
|
| 93 |
+
assert R.dup_cyclotomic_p(1) is False
|
| 94 |
+
assert R.dup_cyclotomic_p(x) is False
|
| 95 |
+
assert R.dup_cyclotomic_p(x + 2) is False
|
| 96 |
+
assert R.dup_cyclotomic_p(3*x + 1) is False
|
| 97 |
+
assert R.dup_cyclotomic_p(x**2 - 1) is False
|
| 98 |
+
|
| 99 |
+
f = x**16 + x**14 - x**10 + x**8 - x**6 + x**2 + 1
|
| 100 |
+
assert R.dup_cyclotomic_p(f) is False
|
| 101 |
+
|
| 102 |
+
g = x**16 + x**14 - x**10 - x**8 - x**6 + x**2 + 1
|
| 103 |
+
assert R.dup_cyclotomic_p(g) is True
|
| 104 |
+
|
| 105 |
+
R, x = ring("x", QQ)
|
| 106 |
+
assert R.dup_cyclotomic_p(x**2 + x + 1) is True
|
| 107 |
+
assert R.dup_cyclotomic_p(QQ(1,2)*x**2 + x + 1) is False
|
| 108 |
+
|
| 109 |
+
R, x = ring("x", ZZ["y"])
|
| 110 |
+
assert R.dup_cyclotomic_p(x**2 + x + 1) is False
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
def test_dup_zz_cyclotomic_poly():
|
| 114 |
+
R, x = ring("x", ZZ)
|
| 115 |
+
|
| 116 |
+
assert R.dup_zz_cyclotomic_poly(1) == x - 1
|
| 117 |
+
assert R.dup_zz_cyclotomic_poly(2) == x + 1
|
| 118 |
+
assert R.dup_zz_cyclotomic_poly(3) == x**2 + x + 1
|
| 119 |
+
assert R.dup_zz_cyclotomic_poly(4) == x**2 + 1
|
| 120 |
+
assert R.dup_zz_cyclotomic_poly(5) == x**4 + x**3 + x**2 + x + 1
|
| 121 |
+
assert R.dup_zz_cyclotomic_poly(6) == x**2 - x + 1
|
| 122 |
+
assert R.dup_zz_cyclotomic_poly(7) == x**6 + x**5 + x**4 + x**3 + x**2 + x + 1
|
| 123 |
+
assert R.dup_zz_cyclotomic_poly(8) == x**4 + 1
|
| 124 |
+
assert R.dup_zz_cyclotomic_poly(9) == x**6 + x**3 + 1
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
def test_dup_zz_cyclotomic_factor():
|
| 128 |
+
R, x = ring("x", ZZ)
|
| 129 |
+
|
| 130 |
+
assert R.dup_zz_cyclotomic_factor(0) is None
|
| 131 |
+
assert R.dup_zz_cyclotomic_factor(1) is None
|
| 132 |
+
|
| 133 |
+
assert R.dup_zz_cyclotomic_factor(2*x**10 - 1) is None
|
| 134 |
+
assert R.dup_zz_cyclotomic_factor(x**10 - 3) is None
|
| 135 |
+
assert R.dup_zz_cyclotomic_factor(x**10 + x**5 - 1) is None
|
| 136 |
+
|
| 137 |
+
assert R.dup_zz_cyclotomic_factor(x + 1) == [x + 1]
|
| 138 |
+
assert R.dup_zz_cyclotomic_factor(x - 1) == [x - 1]
|
| 139 |
+
|
| 140 |
+
assert R.dup_zz_cyclotomic_factor(x**2 + 1) == [x**2 + 1]
|
| 141 |
+
assert R.dup_zz_cyclotomic_factor(x**2 - 1) == [x - 1, x + 1]
|
| 142 |
+
|
| 143 |
+
assert R.dup_zz_cyclotomic_factor(x**27 + 1) == \
|
| 144 |
+
[x + 1, x**2 - x + 1, x**6 - x**3 + 1, x**18 - x**9 + 1]
|
| 145 |
+
assert R.dup_zz_cyclotomic_factor(x**27 - 1) == \
|
| 146 |
+
[x - 1, x**2 + x + 1, x**6 + x**3 + 1, x**18 + x**9 + 1]
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
def test_dup_zz_factor():
|
| 150 |
+
R, x = ring("x", ZZ)
|
| 151 |
+
|
| 152 |
+
assert R.dup_zz_factor(0) == (0, [])
|
| 153 |
+
assert R.dup_zz_factor(7) == (7, [])
|
| 154 |
+
assert R.dup_zz_factor(-7) == (-7, [])
|
| 155 |
+
|
| 156 |
+
assert R.dup_zz_factor_sqf(0) == (0, [])
|
| 157 |
+
assert R.dup_zz_factor_sqf(7) == (7, [])
|
| 158 |
+
assert R.dup_zz_factor_sqf(-7) == (-7, [])
|
| 159 |
+
|
| 160 |
+
assert R.dup_zz_factor(2*x + 4) == (2, [(x + 2, 1)])
|
| 161 |
+
assert R.dup_zz_factor_sqf(2*x + 4) == (2, [x + 2])
|
| 162 |
+
|
| 163 |
+
f = x**4 + x + 1
|
| 164 |
+
|
| 165 |
+
for i in range(0, 20):
|
| 166 |
+
assert R.dup_zz_factor(f) == (1, [(f, 1)])
|
| 167 |
+
|
| 168 |
+
assert R.dup_zz_factor(x**2 + 2*x + 2) == \
|
| 169 |
+
(1, [(x**2 + 2*x + 2, 1)])
|
| 170 |
+
|
| 171 |
+
assert R.dup_zz_factor(18*x**2 + 12*x + 2) == \
|
| 172 |
+
(2, [(3*x + 1, 2)])
|
| 173 |
+
|
| 174 |
+
assert R.dup_zz_factor(-9*x**2 + 1) == \
|
| 175 |
+
(-1, [(3*x - 1, 1),
|
| 176 |
+
(3*x + 1, 1)])
|
| 177 |
+
|
| 178 |
+
assert R.dup_zz_factor_sqf(-9*x**2 + 1) == \
|
| 179 |
+
(-1, [3*x - 1,
|
| 180 |
+
3*x + 1])
|
| 181 |
+
|
| 182 |
+
# The order of the factors will be different when the ground types are
|
| 183 |
+
# flint. At the higher level dup_factor_list will sort the factors.
|
| 184 |
+
c, factors = R.dup_zz_factor(x**3 - 6*x**2 + 11*x - 6)
|
| 185 |
+
assert c == 1
|
| 186 |
+
assert set(factors) == {(x - 3, 1), (x - 2, 1), (x - 1, 1)}
|
| 187 |
+
|
| 188 |
+
assert R.dup_zz_factor_sqf(x**3 - 6*x**2 + 11*x - 6) == \
|
| 189 |
+
(1, [x - 3,
|
| 190 |
+
x - 2,
|
| 191 |
+
x - 1])
|
| 192 |
+
|
| 193 |
+
assert R.dup_zz_factor(3*x**3 + 10*x**2 + 13*x + 10) == \
|
| 194 |
+
(1, [(x + 2, 1),
|
| 195 |
+
(3*x**2 + 4*x + 5, 1)])
|
| 196 |
+
|
| 197 |
+
assert R.dup_zz_factor_sqf(3*x**3 + 10*x**2 + 13*x + 10) == \
|
| 198 |
+
(1, [x + 2,
|
| 199 |
+
3*x**2 + 4*x + 5])
|
| 200 |
+
|
| 201 |
+
c, factors = R.dup_zz_factor(-x**6 + x**2)
|
| 202 |
+
assert c == -1
|
| 203 |
+
assert set(factors) == {(x, 2), (x - 1, 1), (x + 1, 1), (x**2 + 1, 1)}
|
| 204 |
+
|
| 205 |
+
f = 1080*x**8 + 5184*x**7 + 2099*x**6 + 744*x**5 + 2736*x**4 - 648*x**3 + 129*x**2 - 324
|
| 206 |
+
|
| 207 |
+
assert R.dup_zz_factor(f) == \
|
| 208 |
+
(1, [(5*x**4 + 24*x**3 + 9*x**2 + 12, 1),
|
| 209 |
+
(216*x**4 + 31*x**2 - 27, 1)])
|
| 210 |
+
|
| 211 |
+
f = -29802322387695312500000000000000000000*x**25 \
|
| 212 |
+
+ 2980232238769531250000000000000000*x**20 \
|
| 213 |
+
+ 1743435859680175781250000000000*x**15 \
|
| 214 |
+
+ 114142894744873046875000000*x**10 \
|
| 215 |
+
- 210106372833251953125*x**5 \
|
| 216 |
+
+ 95367431640625
|
| 217 |
+
|
| 218 |
+
c, factors = R.dup_zz_factor(f)
|
| 219 |
+
assert c == -95367431640625
|
| 220 |
+
assert set(factors) == {
|
| 221 |
+
(5*x - 1, 1),
|
| 222 |
+
(100*x**2 + 10*x - 1, 2),
|
| 223 |
+
(625*x**4 + 125*x**3 + 25*x**2 + 5*x + 1, 1),
|
| 224 |
+
(10000*x**4 - 3000*x**3 + 400*x**2 - 20*x + 1, 2),
|
| 225 |
+
(10000*x**4 + 2000*x**3 + 400*x**2 + 30*x + 1, 2),
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
f = x**10 - 1
|
| 229 |
+
|
| 230 |
+
config.setup('USE_CYCLOTOMIC_FACTOR', True)
|
| 231 |
+
c0, F_0 = R.dup_zz_factor(f)
|
| 232 |
+
|
| 233 |
+
config.setup('USE_CYCLOTOMIC_FACTOR', False)
|
| 234 |
+
c1, F_1 = R.dup_zz_factor(f)
|
| 235 |
+
|
| 236 |
+
assert c0 == c1 == 1
|
| 237 |
+
assert set(F_0) == set(F_1) == {
|
| 238 |
+
(x - 1, 1),
|
| 239 |
+
(x + 1, 1),
|
| 240 |
+
(x**4 - x**3 + x**2 - x + 1, 1),
|
| 241 |
+
(x**4 + x**3 + x**2 + x + 1, 1),
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
config.setup('USE_CYCLOTOMIC_FACTOR')
|
| 245 |
+
|
| 246 |
+
f = x**10 + 1
|
| 247 |
+
|
| 248 |
+
config.setup('USE_CYCLOTOMIC_FACTOR', True)
|
| 249 |
+
F_0 = R.dup_zz_factor(f)
|
| 250 |
+
|
| 251 |
+
config.setup('USE_CYCLOTOMIC_FACTOR', False)
|
| 252 |
+
F_1 = R.dup_zz_factor(f)
|
| 253 |
+
|
| 254 |
+
assert F_0 == F_1 == \
|
| 255 |
+
(1, [(x**2 + 1, 1),
|
| 256 |
+
(x**8 - x**6 + x**4 - x**2 + 1, 1)])
|
| 257 |
+
|
| 258 |
+
config.setup('USE_CYCLOTOMIC_FACTOR')
|
| 259 |
+
|
| 260 |
+
def test_dmp_zz_wang():
|
| 261 |
+
R, x,y,z = ring("x,y,z", ZZ)
|
| 262 |
+
UV, _x = ring("x", ZZ)
|
| 263 |
+
|
| 264 |
+
p = ZZ(nextprime(R.dmp_zz_mignotte_bound(w_1)))
|
| 265 |
+
assert p == 6291469
|
| 266 |
+
|
| 267 |
+
t_1, k_1, e_1 = y, 1, ZZ(-14)
|
| 268 |
+
t_2, k_2, e_2 = z, 2, ZZ(3)
|
| 269 |
+
t_3, k_3, e_3 = y + z, 2, ZZ(-11)
|
| 270 |
+
t_4, k_4, e_4 = y - z, 1, ZZ(-17)
|
| 271 |
+
|
| 272 |
+
T = [t_1, t_2, t_3, t_4]
|
| 273 |
+
K = [k_1, k_2, k_3, k_4]
|
| 274 |
+
E = [e_1, e_2, e_3, e_4]
|
| 275 |
+
|
| 276 |
+
T = zip([ t.drop(x) for t in T ], K)
|
| 277 |
+
|
| 278 |
+
A = [ZZ(-14), ZZ(3)]
|
| 279 |
+
|
| 280 |
+
S = R.dmp_eval_tail(w_1, A)
|
| 281 |
+
cs, s = UV.dup_primitive(S)
|
| 282 |
+
|
| 283 |
+
assert cs == 1 and s == S == \
|
| 284 |
+
1036728*_x**6 + 915552*_x**5 + 55748*_x**4 + 105621*_x**3 - 17304*_x**2 - 26841*_x - 644
|
| 285 |
+
|
| 286 |
+
assert R.dmp_zz_wang_non_divisors(E, cs, ZZ(4)) == [7, 3, 11, 17]
|
| 287 |
+
assert UV.dup_sqf_p(s) and UV.dup_degree(s) == R.dmp_degree(w_1)
|
| 288 |
+
|
| 289 |
+
_, H = UV.dup_zz_factor_sqf(s)
|
| 290 |
+
|
| 291 |
+
h_1 = 44*_x**2 + 42*_x + 1
|
| 292 |
+
h_2 = 126*_x**2 - 9*_x + 28
|
| 293 |
+
h_3 = 187*_x**2 - 23
|
| 294 |
+
|
| 295 |
+
assert H == [h_1, h_2, h_3]
|
| 296 |
+
|
| 297 |
+
LC = [ lc.drop(x) for lc in [-4*y - 4*z, -y*z**2, y**2 - z**2] ]
|
| 298 |
+
|
| 299 |
+
assert R.dmp_zz_wang_lead_coeffs(w_1, T, cs, E, H, A) == (w_1, H, LC)
|
| 300 |
+
|
| 301 |
+
factors = R.dmp_zz_wang_hensel_lifting(w_1, H, LC, A, p)
|
| 302 |
+
assert R.dmp_expand(factors) == w_1
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
@XFAIL
|
| 306 |
+
def test_dmp_zz_wang_fail():
|
| 307 |
+
R, x,y,z = ring("x,y,z", ZZ)
|
| 308 |
+
UV, _x = ring("x", ZZ)
|
| 309 |
+
|
| 310 |
+
p = ZZ(nextprime(R.dmp_zz_mignotte_bound(w_1)))
|
| 311 |
+
assert p == 6291469
|
| 312 |
+
|
| 313 |
+
H_1 = [44*x**2 + 42*x + 1, 126*x**2 - 9*x + 28, 187*x**2 - 23]
|
| 314 |
+
H_2 = [-4*x**2*y - 12*x**2 - 3*x*y + 1, -9*x**2*y - 9*x - 2*y, x**2*y**2 - 9*x**2 + y - 9]
|
| 315 |
+
H_3 = [-4*x**2*y - 12*x**2 - 3*x*y + 1, -9*x**2*y - 9*x - 2*y, x**2*y**2 - 9*x**2 + y - 9]
|
| 316 |
+
|
| 317 |
+
c_1 = -70686*x**5 - 5863*x**4 - 17826*x**3 + 2009*x**2 + 5031*x + 74
|
| 318 |
+
c_2 = 9*x**5*y**4 + 12*x**5*y**3 - 45*x**5*y**2 - 108*x**5*y - 324*x**5 + 18*x**4*y**3 - 216*x**4*y**2 - 810*x**4*y + 2*x**3*y**4 + 9*x**3*y**3 - 252*x**3*y**2 - 288*x**3*y - 945*x**3 - 30*x**2*y**2 - 414*x**2*y + 2*x*y**3 - 54*x*y**2 - 3*x*y + 81*x + 12*y
|
| 319 |
+
c_3 = -36*x**4*y**2 - 108*x**4*y - 27*x**3*y**2 - 36*x**3*y - 108*x**3 - 8*x**2*y**2 - 42*x**2*y - 6*x*y**2 + 9*x + 2*y
|
| 320 |
+
|
| 321 |
+
assert R.dmp_zz_diophantine(H_1, c_1, [], 5, p) == [-3*x, -2, 1]
|
| 322 |
+
assert R.dmp_zz_diophantine(H_2, c_2, [ZZ(-14)], 5, p) == [-x*y, -3*x, -6]
|
| 323 |
+
assert R.dmp_zz_diophantine(H_3, c_3, [ZZ(-14)], 5, p) == [0, 0, -1]
|
| 324 |
+
|
| 325 |
+
|
| 326 |
+
def test_issue_6355():
|
| 327 |
+
# This tests a bug in the Wang algorithm that occurred only with a very
|
| 328 |
+
# specific set of random numbers.
|
| 329 |
+
random_sequence = [-1, -1, 0, 0, 0, 0, -1, -1, 0, -1, 3, -1, 3, 3, 3, 3, -1, 3]
|
| 330 |
+
|
| 331 |
+
R, x, y, z = ring("x,y,z", ZZ)
|
| 332 |
+
f = 2*x**2 + y*z - y - z**2 + z
|
| 333 |
+
|
| 334 |
+
assert R.dmp_zz_wang(f, seed=random_sequence) == [f]
|
| 335 |
+
|
| 336 |
+
|
| 337 |
+
def test_dmp_zz_factor():
|
| 338 |
+
R, x = ring("x", ZZ)
|
| 339 |
+
assert R.dmp_zz_factor(0) == (0, [])
|
| 340 |
+
assert R.dmp_zz_factor(7) == (7, [])
|
| 341 |
+
assert R.dmp_zz_factor(-7) == (-7, [])
|
| 342 |
+
|
| 343 |
+
assert R.dmp_zz_factor(x**2 - 9) == (1, [(x - 3, 1), (x + 3, 1)])
|
| 344 |
+
|
| 345 |
+
R, x, y = ring("x,y", ZZ)
|
| 346 |
+
assert R.dmp_zz_factor(0) == (0, [])
|
| 347 |
+
assert R.dmp_zz_factor(7) == (7, [])
|
| 348 |
+
assert R.dmp_zz_factor(-7) == (-7, [])
|
| 349 |
+
|
| 350 |
+
assert R.dmp_zz_factor(x) == (1, [(x, 1)])
|
| 351 |
+
assert R.dmp_zz_factor(4*x) == (4, [(x, 1)])
|
| 352 |
+
assert R.dmp_zz_factor(4*x + 2) == (2, [(2*x + 1, 1)])
|
| 353 |
+
assert R.dmp_zz_factor(x*y + 1) == (1, [(x*y + 1, 1)])
|
| 354 |
+
assert R.dmp_zz_factor(y**2 + 1) == (1, [(y**2 + 1, 1)])
|
| 355 |
+
assert R.dmp_zz_factor(y**2 - 1) == (1, [(y - 1, 1), (y + 1, 1)])
|
| 356 |
+
|
| 357 |
+
assert R.dmp_zz_factor(x**2*y**2 + 6*x**2*y + 9*x**2 - 1) == (1, [(x*y + 3*x - 1, 1), (x*y + 3*x + 1, 1)])
|
| 358 |
+
assert R.dmp_zz_factor(x**2*y**2 - 9) == (1, [(x*y - 3, 1), (x*y + 3, 1)])
|
| 359 |
+
|
| 360 |
+
R, x, y, z = ring("x,y,z", ZZ)
|
| 361 |
+
assert R.dmp_zz_factor(x**2*y**2*z**2 - 9) == \
|
| 362 |
+
(1, [(x*y*z - 3, 1),
|
| 363 |
+
(x*y*z + 3, 1)])
|
| 364 |
+
|
| 365 |
+
R, x, y, z, u = ring("x,y,z,u", ZZ)
|
| 366 |
+
assert R.dmp_zz_factor(x**2*y**2*z**2*u**2 - 9) == \
|
| 367 |
+
(1, [(x*y*z*u - 3, 1),
|
| 368 |
+
(x*y*z*u + 3, 1)])
|
| 369 |
+
|
| 370 |
+
R, x, y, z = ring("x,y,z", ZZ)
|
| 371 |
+
assert R.dmp_zz_factor(f_1) == \
|
| 372 |
+
(1, [(x + y*z + 20, 1),
|
| 373 |
+
(x*y + z + 10, 1),
|
| 374 |
+
(x*z + y + 30, 1)])
|
| 375 |
+
|
| 376 |
+
assert R.dmp_zz_factor(f_2) == \
|
| 377 |
+
(1, [(x**2*y**2 + x**2*z**2 + y + 90, 1),
|
| 378 |
+
(x**3*y + x**3*z + z - 11, 1)])
|
| 379 |
+
|
| 380 |
+
assert R.dmp_zz_factor(f_3) == \
|
| 381 |
+
(1, [(x**2*y**2 + x*z**4 + x + z, 1),
|
| 382 |
+
(x**3 + x*y*z + y**2 + y*z**3, 1)])
|
| 383 |
+
|
| 384 |
+
assert R.dmp_zz_factor(f_4) == \
|
| 385 |
+
(-1, [(x*y**3 + z**2, 1),
|
| 386 |
+
(x**2*z + y**4*z**2 + 5, 1),
|
| 387 |
+
(x**3*y - z**2 - 3, 1),
|
| 388 |
+
(x**3*y**4 + z**2, 1)])
|
| 389 |
+
|
| 390 |
+
assert R.dmp_zz_factor(f_5) == \
|
| 391 |
+
(-1, [(x + y - z, 3)])
|
| 392 |
+
|
| 393 |
+
R, x, y, z, t = ring("x,y,z,t", ZZ)
|
| 394 |
+
assert R.dmp_zz_factor(f_6) == \
|
| 395 |
+
(1, [(47*x*y + z**3*t**2 - t**2, 1),
|
| 396 |
+
(45*x**3 - 9*y**3 - y**2 + 3*z**3 + 2*z*t, 1)])
|
| 397 |
+
|
| 398 |
+
R, x, y, z = ring("x,y,z", ZZ)
|
| 399 |
+
assert R.dmp_zz_factor(w_1) == \
|
| 400 |
+
(1, [(x**2*y**2 - x**2*z**2 + y - z**2, 1),
|
| 401 |
+
(x**2*y*z**2 + 3*x*z + 2*y, 1),
|
| 402 |
+
(4*x**2*y + 4*x**2*z + x*y*z - 1, 1)])
|
| 403 |
+
|
| 404 |
+
R, x, y = ring("x,y", ZZ)
|
| 405 |
+
f = -12*x**16*y + 240*x**12*y**3 - 768*x**10*y**4 + 1080*x**8*y**5 - 768*x**6*y**6 + 240*x**4*y**7 - 12*y**9
|
| 406 |
+
|
| 407 |
+
assert R.dmp_zz_factor(f) == \
|
| 408 |
+
(-12, [(y, 1),
|
| 409 |
+
(x**2 - y, 6),
|
| 410 |
+
(x**4 + 6*x**2*y + y**2, 1)])
|
| 411 |
+
|
| 412 |
+
|
| 413 |
+
def test_dup_qq_i_factor():
|
| 414 |
+
R, x = ring("x", QQ_I)
|
| 415 |
+
i = QQ_I(0, 1)
|
| 416 |
+
|
| 417 |
+
assert R.dup_qq_i_factor(x**2 - 2) == (QQ_I(1, 0), [(x**2 - 2, 1)])
|
| 418 |
+
|
| 419 |
+
assert R.dup_qq_i_factor(x**2 - 1) == (QQ_I(1, 0), [(x - 1, 1), (x + 1, 1)])
|
| 420 |
+
|
| 421 |
+
assert R.dup_qq_i_factor(x**2 + 1) == (QQ_I(1, 0), [(x - i, 1), (x + i, 1)])
|
| 422 |
+
|
| 423 |
+
assert R.dup_qq_i_factor(x**2/4 + 1) == \
|
| 424 |
+
(QQ_I(QQ(1, 4), 0), [(x - 2*i, 1), (x + 2*i, 1)])
|
| 425 |
+
|
| 426 |
+
assert R.dup_qq_i_factor(x**2 + 4) == \
|
| 427 |
+
(QQ_I(1, 0), [(x - 2*i, 1), (x + 2*i, 1)])
|
| 428 |
+
|
| 429 |
+
assert R.dup_qq_i_factor(x**2 + 2*x + 1) == \
|
| 430 |
+
(QQ_I(1, 0), [(x + 1, 2)])
|
| 431 |
+
|
| 432 |
+
assert R.dup_qq_i_factor(x**2 + 2*i*x - 1) == \
|
| 433 |
+
(QQ_I(1, 0), [(x + i, 2)])
|
| 434 |
+
|
| 435 |
+
f = 8192*x**2 + x*(22656 + 175232*i) - 921416 + 242313*i
|
| 436 |
+
|
| 437 |
+
assert R.dup_qq_i_factor(f) == \
|
| 438 |
+
(QQ_I(8192, 0), [(x + QQ_I(QQ(177, 128), QQ(1369, 128)), 2)])
|
| 439 |
+
|
| 440 |
+
|
| 441 |
+
def test_dmp_qq_i_factor():
|
| 442 |
+
R, x, y = ring("x, y", QQ_I)
|
| 443 |
+
i = QQ_I(0, 1)
|
| 444 |
+
|
| 445 |
+
assert R.dmp_qq_i_factor(x**2 + 2*y**2) == \
|
| 446 |
+
(QQ_I(1, 0), [(x**2 + 2*y**2, 1)])
|
| 447 |
+
|
| 448 |
+
assert R.dmp_qq_i_factor(x**2 + y**2) == \
|
| 449 |
+
(QQ_I(1, 0), [(x - i*y, 1), (x + i*y, 1)])
|
| 450 |
+
|
| 451 |
+
assert R.dmp_qq_i_factor(x**2 + y**2/4) == \
|
| 452 |
+
(QQ_I(1, 0), [(x - i*y/2, 1), (x + i*y/2, 1)])
|
| 453 |
+
|
| 454 |
+
assert R.dmp_qq_i_factor(4*x**2 + y**2) == \
|
| 455 |
+
(QQ_I(4, 0), [(x - i*y/2, 1), (x + i*y/2, 1)])
|
| 456 |
+
|
| 457 |
+
|
| 458 |
+
def test_dup_zz_i_factor():
|
| 459 |
+
R, x = ring("x", ZZ_I)
|
| 460 |
+
i = ZZ_I(0, 1)
|
| 461 |
+
|
| 462 |
+
assert R.dup_zz_i_factor(x**2 - 2) == (ZZ_I(1, 0), [(x**2 - 2, 1)])
|
| 463 |
+
|
| 464 |
+
assert R.dup_zz_i_factor(x**2 - 1) == (ZZ_I(1, 0), [(x - 1, 1), (x + 1, 1)])
|
| 465 |
+
|
| 466 |
+
assert R.dup_zz_i_factor(x**2 + 1) == (ZZ_I(1, 0), [(x - i, 1), (x + i, 1)])
|
| 467 |
+
|
| 468 |
+
assert R.dup_zz_i_factor(x**2 + 4) == \
|
| 469 |
+
(ZZ_I(1, 0), [(x - 2*i, 1), (x + 2*i, 1)])
|
| 470 |
+
|
| 471 |
+
assert R.dup_zz_i_factor(x**2 + 2*x + 1) == \
|
| 472 |
+
(ZZ_I(1, 0), [(x + 1, 2)])
|
| 473 |
+
|
| 474 |
+
assert R.dup_zz_i_factor(x**2 + 2*i*x - 1) == \
|
| 475 |
+
(ZZ_I(1, 0), [(x + i, 2)])
|
| 476 |
+
|
| 477 |
+
f = 8192*x**2 + x*(22656 + 175232*i) - 921416 + 242313*i
|
| 478 |
+
|
| 479 |
+
assert R.dup_zz_i_factor(f) == \
|
| 480 |
+
(ZZ_I(0, 1), [((64 - 64*i)*x + (773 + 596*i), 2)])
|
| 481 |
+
|
| 482 |
+
|
| 483 |
+
def test_dmp_zz_i_factor():
|
| 484 |
+
R, x, y = ring("x, y", ZZ_I)
|
| 485 |
+
i = ZZ_I(0, 1)
|
| 486 |
+
|
| 487 |
+
assert R.dmp_zz_i_factor(x**2 + 2*y**2) == \
|
| 488 |
+
(ZZ_I(1, 0), [(x**2 + 2*y**2, 1)])
|
| 489 |
+
|
| 490 |
+
assert R.dmp_zz_i_factor(x**2 + y**2) == \
|
| 491 |
+
(ZZ_I(1, 0), [(x - i*y, 1), (x + i*y, 1)])
|
| 492 |
+
|
| 493 |
+
assert R.dmp_zz_i_factor(4*x**2 + y**2) == \
|
| 494 |
+
(ZZ_I(1, 0), [(2*x - i*y, 1), (2*x + i*y, 1)])
|
| 495 |
+
|
| 496 |
+
|
| 497 |
+
def test_dup_ext_factor():
|
| 498 |
+
R, x = ring("x", QQ.algebraic_field(I))
|
| 499 |
+
def anp(element):
|
| 500 |
+
return ANP(element, [QQ(1), QQ(0), QQ(1)], QQ)
|
| 501 |
+
|
| 502 |
+
assert R.dup_ext_factor(0) == (anp([]), [])
|
| 503 |
+
|
| 504 |
+
f = anp([QQ(1)])*x + anp([QQ(1)])
|
| 505 |
+
|
| 506 |
+
assert R.dup_ext_factor(f) == (anp([QQ(1)]), [(f, 1)])
|
| 507 |
+
|
| 508 |
+
g = anp([QQ(2)])*x + anp([QQ(2)])
|
| 509 |
+
|
| 510 |
+
assert R.dup_ext_factor(g) == (anp([QQ(2)]), [(f, 1)])
|
| 511 |
+
|
| 512 |
+
f = anp([QQ(7)])*x**4 + anp([QQ(1, 1)])
|
| 513 |
+
g = anp([QQ(1)])*x**4 + anp([QQ(1, 7)])
|
| 514 |
+
|
| 515 |
+
assert R.dup_ext_factor(f) == (anp([QQ(7)]), [(g, 1)])
|
| 516 |
+
|
| 517 |
+
f = anp([QQ(1)])*x**4 + anp([QQ(1)])
|
| 518 |
+
|
| 519 |
+
assert R.dup_ext_factor(f) == \
|
| 520 |
+
(anp([QQ(1, 1)]), [(anp([QQ(1)])*x**2 + anp([QQ(-1), QQ(0)]), 1),
|
| 521 |
+
(anp([QQ(1)])*x**2 + anp([QQ( 1), QQ(0)]), 1)])
|
| 522 |
+
|
| 523 |
+
f = anp([QQ(4, 1)])*x**2 + anp([QQ(9, 1)])
|
| 524 |
+
|
| 525 |
+
assert R.dup_ext_factor(f) == \
|
| 526 |
+
(anp([QQ(4, 1)]), [(anp([QQ(1, 1)])*x + anp([-QQ(3, 2), QQ(0, 1)]), 1),
|
| 527 |
+
(anp([QQ(1, 1)])*x + anp([ QQ(3, 2), QQ(0, 1)]), 1)])
|
| 528 |
+
|
| 529 |
+
f = anp([QQ(4, 1)])*x**4 + anp([QQ(8, 1)])*x**3 + anp([QQ(77, 1)])*x**2 + anp([QQ(18, 1)])*x + anp([QQ(153, 1)])
|
| 530 |
+
|
| 531 |
+
assert R.dup_ext_factor(f) == \
|
| 532 |
+
(anp([QQ(4, 1)]), [(anp([QQ(1, 1)])*x + anp([-QQ(4, 1), QQ(1, 1)]), 1),
|
| 533 |
+
(anp([QQ(1, 1)])*x + anp([-QQ(3, 2), QQ(0, 1)]), 1),
|
| 534 |
+
(anp([QQ(1, 1)])*x + anp([ QQ(3, 2), QQ(0, 1)]), 1),
|
| 535 |
+
(anp([QQ(1, 1)])*x + anp([ QQ(4, 1), QQ(1, 1)]), 1)])
|
| 536 |
+
|
| 537 |
+
R, x = ring("x", QQ.algebraic_field(sqrt(2)))
|
| 538 |
+
def anp(element):
|
| 539 |
+
return ANP(element, [QQ(1), QQ(0), QQ(-2)], QQ)
|
| 540 |
+
|
| 541 |
+
f = anp([QQ(1)])*x**4 + anp([QQ(1, 1)])
|
| 542 |
+
|
| 543 |
+
assert R.dup_ext_factor(f) == \
|
| 544 |
+
(anp([QQ(1)]), [(anp([QQ(1)])*x**2 + anp([QQ(-1), QQ(0)])*x + anp([QQ(1)]), 1),
|
| 545 |
+
(anp([QQ(1)])*x**2 + anp([QQ( 1), QQ(0)])*x + anp([QQ(1)]), 1)])
|
| 546 |
+
|
| 547 |
+
f = anp([QQ(1, 1)])*x**2 + anp([QQ(2), QQ(0)])*x + anp([QQ(2, 1)])
|
| 548 |
+
|
| 549 |
+
assert R.dup_ext_factor(f) == \
|
| 550 |
+
(anp([QQ(1, 1)]), [(anp([1])*x + anp([1, 0]), 2)])
|
| 551 |
+
|
| 552 |
+
assert R.dup_ext_factor(f**3) == \
|
| 553 |
+
(anp([QQ(1, 1)]), [(anp([1])*x + anp([1, 0]), 6)])
|
| 554 |
+
|
| 555 |
+
f *= anp([QQ(2, 1)])
|
| 556 |
+
|
| 557 |
+
assert R.dup_ext_factor(f) == \
|
| 558 |
+
(anp([QQ(2, 1)]), [(anp([1])*x + anp([1, 0]), 2)])
|
| 559 |
+
|
| 560 |
+
assert R.dup_ext_factor(f**3) == \
|
| 561 |
+
(anp([QQ(8, 1)]), [(anp([1])*x + anp([1, 0]), 6)])
|
| 562 |
+
|
| 563 |
+
|
| 564 |
+
def test_dmp_ext_factor():
|
| 565 |
+
K = QQ.algebraic_field(sqrt(2))
|
| 566 |
+
R, x,y = ring("x,y", K)
|
| 567 |
+
sqrt2 = K.unit
|
| 568 |
+
|
| 569 |
+
def anp(x):
|
| 570 |
+
return ANP(x, [QQ(1), QQ(0), QQ(-2)], QQ)
|
| 571 |
+
|
| 572 |
+
assert R.dmp_ext_factor(0) == (anp([]), [])
|
| 573 |
+
|
| 574 |
+
f = anp([QQ(1)])*x + anp([QQ(1)])
|
| 575 |
+
|
| 576 |
+
assert R.dmp_ext_factor(f) == (anp([QQ(1)]), [(f, 1)])
|
| 577 |
+
|
| 578 |
+
g = anp([QQ(2)])*x + anp([QQ(2)])
|
| 579 |
+
|
| 580 |
+
assert R.dmp_ext_factor(g) == (anp([QQ(2)]), [(f, 1)])
|
| 581 |
+
|
| 582 |
+
f = anp([QQ(1)])*x**2 + anp([QQ(-2)])*y**2
|
| 583 |
+
|
| 584 |
+
assert R.dmp_ext_factor(f) == \
|
| 585 |
+
(anp([QQ(1)]), [(anp([QQ(1)])*x + anp([QQ(-1), QQ(0)])*y, 1),
|
| 586 |
+
(anp([QQ(1)])*x + anp([QQ( 1), QQ(0)])*y, 1)])
|
| 587 |
+
|
| 588 |
+
f = anp([QQ(2)])*x**2 + anp([QQ(-4)])*y**2
|
| 589 |
+
|
| 590 |
+
assert R.dmp_ext_factor(f) == \
|
| 591 |
+
(anp([QQ(2)]), [(anp([QQ(1)])*x + anp([QQ(-1), QQ(0)])*y, 1),
|
| 592 |
+
(anp([QQ(1)])*x + anp([QQ( 1), QQ(0)])*y, 1)])
|
| 593 |
+
|
| 594 |
+
f1 = y + 1
|
| 595 |
+
f2 = y + sqrt2
|
| 596 |
+
f3 = x**2 + x + 2 + 3*sqrt2
|
| 597 |
+
f = f1**2 * f2**2 * f3**2
|
| 598 |
+
assert R.dmp_ext_factor(f) == (K.one, [(f1, 2), (f2, 2), (f3, 2)])
|
| 599 |
+
|
| 600 |
+
|
| 601 |
+
def test_dup_factor_list():
|
| 602 |
+
R, x = ring("x", ZZ)
|
| 603 |
+
assert R.dup_factor_list(0) == (0, [])
|
| 604 |
+
assert R.dup_factor_list(7) == (7, [])
|
| 605 |
+
|
| 606 |
+
R, x = ring("x", QQ)
|
| 607 |
+
assert R.dup_factor_list(0) == (0, [])
|
| 608 |
+
assert R.dup_factor_list(QQ(1, 7)) == (QQ(1, 7), [])
|
| 609 |
+
|
| 610 |
+
R, x = ring("x", ZZ['t'])
|
| 611 |
+
assert R.dup_factor_list(0) == (0, [])
|
| 612 |
+
assert R.dup_factor_list(7) == (7, [])
|
| 613 |
+
|
| 614 |
+
R, x = ring("x", QQ['t'])
|
| 615 |
+
assert R.dup_factor_list(0) == (0, [])
|
| 616 |
+
assert R.dup_factor_list(QQ(1, 7)) == (QQ(1, 7), [])
|
| 617 |
+
|
| 618 |
+
R, x = ring("x", ZZ)
|
| 619 |
+
assert R.dup_factor_list_include(0) == [(0, 1)]
|
| 620 |
+
assert R.dup_factor_list_include(7) == [(7, 1)]
|
| 621 |
+
|
| 622 |
+
assert R.dup_factor_list(x**2 + 2*x + 1) == (1, [(x + 1, 2)])
|
| 623 |
+
assert R.dup_factor_list_include(x**2 + 2*x + 1) == [(x + 1, 2)]
|
| 624 |
+
# issue 8037
|
| 625 |
+
assert R.dup_factor_list(6*x**2 - 5*x - 6) == (1, [(2*x - 3, 1), (3*x + 2, 1)])
|
| 626 |
+
|
| 627 |
+
R, x = ring("x", QQ)
|
| 628 |
+
assert R.dup_factor_list(QQ(1,2)*x**2 + x + QQ(1,2)) == (QQ(1, 2), [(x + 1, 2)])
|
| 629 |
+
|
| 630 |
+
R, x = ring("x", FF(2))
|
| 631 |
+
assert R.dup_factor_list(x**2 + 1) == (1, [(x + 1, 2)])
|
| 632 |
+
|
| 633 |
+
R, x = ring("x", RR)
|
| 634 |
+
assert R.dup_factor_list(1.0*x**2 + 2.0*x + 1.0) == (1.0, [(1.0*x + 1.0, 2)])
|
| 635 |
+
assert R.dup_factor_list(2.0*x**2 + 4.0*x + 2.0) == (2.0, [(1.0*x + 1.0, 2)])
|
| 636 |
+
|
| 637 |
+
f = 6.7225336055071*x**2 - 10.6463972754741*x - 0.33469524022264
|
| 638 |
+
coeff, factors = R.dup_factor_list(f)
|
| 639 |
+
assert coeff == RR(10.6463972754741)
|
| 640 |
+
assert len(factors) == 1
|
| 641 |
+
assert factors[0][0].max_norm() == RR(1.0)
|
| 642 |
+
assert factors[0][1] == 1
|
| 643 |
+
|
| 644 |
+
Rt, t = ring("t", ZZ)
|
| 645 |
+
R, x = ring("x", Rt)
|
| 646 |
+
|
| 647 |
+
f = 4*t*x**2 + 4*t**2*x
|
| 648 |
+
|
| 649 |
+
assert R.dup_factor_list(f) == \
|
| 650 |
+
(4*t, [(x, 1),
|
| 651 |
+
(x + t, 1)])
|
| 652 |
+
|
| 653 |
+
Rt, t = ring("t", QQ)
|
| 654 |
+
R, x = ring("x", Rt)
|
| 655 |
+
|
| 656 |
+
f = QQ(1, 2)*t*x**2 + QQ(1, 2)*t**2*x
|
| 657 |
+
|
| 658 |
+
assert R.dup_factor_list(f) == \
|
| 659 |
+
(QQ(1, 2)*t, [(x, 1),
|
| 660 |
+
(x + t, 1)])
|
| 661 |
+
|
| 662 |
+
R, x = ring("x", QQ.algebraic_field(I))
|
| 663 |
+
def anp(element):
|
| 664 |
+
return ANP(element, [QQ(1), QQ(0), QQ(1)], QQ)
|
| 665 |
+
|
| 666 |
+
f = anp([QQ(1, 1)])*x**4 + anp([QQ(2, 1)])*x**2
|
| 667 |
+
|
| 668 |
+
assert R.dup_factor_list(f) == \
|
| 669 |
+
(anp([QQ(1, 1)]), [(anp([QQ(1, 1)])*x, 2),
|
| 670 |
+
(anp([QQ(1, 1)])*x**2 + anp([])*x + anp([QQ(2, 1)]), 1)])
|
| 671 |
+
|
| 672 |
+
R, x = ring("x", EX)
|
| 673 |
+
raises(DomainError, lambda: R.dup_factor_list(EX(sin(1))))
|
| 674 |
+
|
| 675 |
+
|
| 676 |
+
def test_dmp_factor_list():
|
| 677 |
+
R, x, y = ring("x,y", ZZ)
|
| 678 |
+
assert R.dmp_factor_list(0) == (ZZ(0), [])
|
| 679 |
+
assert R.dmp_factor_list(7) == (7, [])
|
| 680 |
+
|
| 681 |
+
R, x, y = ring("x,y", QQ)
|
| 682 |
+
assert R.dmp_factor_list(0) == (QQ(0), [])
|
| 683 |
+
assert R.dmp_factor_list(QQ(1, 7)) == (QQ(1, 7), [])
|
| 684 |
+
|
| 685 |
+
Rt, t = ring("t", ZZ)
|
| 686 |
+
R, x, y = ring("x,y", Rt)
|
| 687 |
+
assert R.dmp_factor_list(0) == (0, [])
|
| 688 |
+
assert R.dmp_factor_list(7) == (ZZ(7), [])
|
| 689 |
+
|
| 690 |
+
Rt, t = ring("t", QQ)
|
| 691 |
+
R, x, y = ring("x,y", Rt)
|
| 692 |
+
assert R.dmp_factor_list(0) == (0, [])
|
| 693 |
+
assert R.dmp_factor_list(QQ(1, 7)) == (QQ(1, 7), [])
|
| 694 |
+
|
| 695 |
+
R, x, y = ring("x,y", ZZ)
|
| 696 |
+
assert R.dmp_factor_list_include(0) == [(0, 1)]
|
| 697 |
+
assert R.dmp_factor_list_include(7) == [(7, 1)]
|
| 698 |
+
|
| 699 |
+
R, X = xring("x:200", ZZ)
|
| 700 |
+
|
| 701 |
+
f, g = X[0]**2 + 2*X[0] + 1, X[0] + 1
|
| 702 |
+
assert R.dmp_factor_list(f) == (1, [(g, 2)])
|
| 703 |
+
|
| 704 |
+
f, g = X[-1]**2 + 2*X[-1] + 1, X[-1] + 1
|
| 705 |
+
assert R.dmp_factor_list(f) == (1, [(g, 2)])
|
| 706 |
+
|
| 707 |
+
R, x = ring("x", ZZ)
|
| 708 |
+
assert R.dmp_factor_list(x**2 + 2*x + 1) == (1, [(x + 1, 2)])
|
| 709 |
+
R, x = ring("x", QQ)
|
| 710 |
+
assert R.dmp_factor_list(QQ(1,2)*x**2 + x + QQ(1,2)) == (QQ(1,2), [(x + 1, 2)])
|
| 711 |
+
|
| 712 |
+
R, x, y = ring("x,y", ZZ)
|
| 713 |
+
assert R.dmp_factor_list(x**2 + 2*x + 1) == (1, [(x + 1, 2)])
|
| 714 |
+
R, x, y = ring("x,y", QQ)
|
| 715 |
+
assert R.dmp_factor_list(QQ(1,2)*x**2 + x + QQ(1,2)) == (QQ(1,2), [(x + 1, 2)])
|
| 716 |
+
|
| 717 |
+
R, x, y = ring("x,y", ZZ)
|
| 718 |
+
f = 4*x**2*y + 4*x*y**2
|
| 719 |
+
|
| 720 |
+
assert R.dmp_factor_list(f) == \
|
| 721 |
+
(4, [(y, 1),
|
| 722 |
+
(x, 1),
|
| 723 |
+
(x + y, 1)])
|
| 724 |
+
|
| 725 |
+
assert R.dmp_factor_list_include(f) == \
|
| 726 |
+
[(4*y, 1),
|
| 727 |
+
(x, 1),
|
| 728 |
+
(x + y, 1)]
|
| 729 |
+
|
| 730 |
+
R, x, y = ring("x,y", QQ)
|
| 731 |
+
f = QQ(1,2)*x**2*y + QQ(1,2)*x*y**2
|
| 732 |
+
|
| 733 |
+
assert R.dmp_factor_list(f) == \
|
| 734 |
+
(QQ(1,2), [(y, 1),
|
| 735 |
+
(x, 1),
|
| 736 |
+
(x + y, 1)])
|
| 737 |
+
|
| 738 |
+
R, x, y = ring("x,y", RR)
|
| 739 |
+
f = 2.0*x**2 - 8.0*y**2
|
| 740 |
+
|
| 741 |
+
assert R.dmp_factor_list(f) == \
|
| 742 |
+
(RR(8.0), [(0.5*x - y, 1),
|
| 743 |
+
(0.5*x + y, 1)])
|
| 744 |
+
|
| 745 |
+
f = 6.7225336055071*x**2*y**2 - 10.6463972754741*x*y - 0.33469524022264
|
| 746 |
+
coeff, factors = R.dmp_factor_list(f)
|
| 747 |
+
assert coeff == RR(10.6463972754741)
|
| 748 |
+
assert len(factors) == 1
|
| 749 |
+
assert factors[0][0].max_norm() == RR(1.0)
|
| 750 |
+
assert factors[0][1] == 1
|
| 751 |
+
|
| 752 |
+
Rt, t = ring("t", ZZ)
|
| 753 |
+
R, x, y = ring("x,y", Rt)
|
| 754 |
+
f = 4*t*x**2 + 4*t**2*x
|
| 755 |
+
|
| 756 |
+
assert R.dmp_factor_list(f) == \
|
| 757 |
+
(4*t, [(x, 1),
|
| 758 |
+
(x + t, 1)])
|
| 759 |
+
|
| 760 |
+
Rt, t = ring("t", QQ)
|
| 761 |
+
R, x, y = ring("x,y", Rt)
|
| 762 |
+
f = QQ(1, 2)*t*x**2 + QQ(1, 2)*t**2*x
|
| 763 |
+
|
| 764 |
+
assert R.dmp_factor_list(f) == \
|
| 765 |
+
(QQ(1, 2)*t, [(x, 1),
|
| 766 |
+
(x + t, 1)])
|
| 767 |
+
|
| 768 |
+
R, x, y = ring("x,y", FF(2))
|
| 769 |
+
raises(NotImplementedError, lambda: R.dmp_factor_list(x**2 + y**2))
|
| 770 |
+
|
| 771 |
+
R, x, y = ring("x,y", EX)
|
| 772 |
+
raises(DomainError, lambda: R.dmp_factor_list(EX(sin(1))))
|
| 773 |
+
|
| 774 |
+
|
| 775 |
+
def test_dup_irreducible_p():
|
| 776 |
+
R, x = ring("x", ZZ)
|
| 777 |
+
assert R.dup_irreducible_p(x**2 + x + 1) is True
|
| 778 |
+
assert R.dup_irreducible_p(x**2 + 2*x + 1) is False
|
| 779 |
+
|
| 780 |
+
|
| 781 |
+
def test_dmp_irreducible_p():
|
| 782 |
+
R, x, y = ring("x,y", ZZ)
|
| 783 |
+
assert R.dmp_irreducible_p(x**2 + x + 1) is True
|
| 784 |
+
assert R.dmp_irreducible_p(x**2 + 2*x + 1) is False
|
pllava/lib/python3.10/site-packages/sympy/polys/tests/test_fields.py
ADDED
|
@@ -0,0 +1,362 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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Element
|
| 4 |
+
from sympy.polys.rings import ring
|
| 5 |
+
from sympy.polys.domains import ZZ, QQ
|
| 6 |
+
from sympy.polys.orderings import lex
|
| 7 |
+
|
| 8 |
+
from sympy.testing.pytest import raises, XFAIL
|
| 9 |
+
from sympy.core import symbols, E
|
| 10 |
+
from sympy.core.numbers import Rational
|
| 11 |
+
from sympy.functions.elementary.exponential import (exp, log)
|
| 12 |
+
from sympy.functions.elementary.miscellaneous import sqrt
|
| 13 |
+
|
| 14 |
+
def test_FracField___init__():
|
| 15 |
+
F1 = FracField("x,y", ZZ, lex)
|
| 16 |
+
F2 = FracField("x,y", ZZ, lex)
|
| 17 |
+
F3 = FracField("x,y,z", ZZ, lex)
|
| 18 |
+
|
| 19 |
+
assert F1.x == F1.gens[0]
|
| 20 |
+
assert F1.y == F1.gens[1]
|
| 21 |
+
assert F1.x == F2.x
|
| 22 |
+
assert F1.y == F2.y
|
| 23 |
+
assert F1.x != F3.x
|
| 24 |
+
assert F1.y != F3.y
|
| 25 |
+
|
| 26 |
+
def test_FracField___hash__():
|
| 27 |
+
F, x, y, z = field("x,y,z", QQ)
|
| 28 |
+
assert hash(F)
|
| 29 |
+
|
| 30 |
+
def test_FracField___eq__():
|
| 31 |
+
assert field("x,y,z", QQ)[0] == field("x,y,z", QQ)[0]
|
| 32 |
+
assert field("x,y,z", QQ)[0] is field("x,y,z", QQ)[0]
|
| 33 |
+
|
| 34 |
+
assert field("x,y,z", QQ)[0] != field("x,y,z", ZZ)[0]
|
| 35 |
+
assert field("x,y,z", QQ)[0] is not field("x,y,z", ZZ)[0]
|
| 36 |
+
|
| 37 |
+
assert field("x,y,z", ZZ)[0] != field("x,y,z", QQ)[0]
|
| 38 |
+
assert field("x,y,z", ZZ)[0] is not field("x,y,z", QQ)[0]
|
| 39 |
+
|
| 40 |
+
assert field("x,y,z", QQ)[0] != field("x,y", QQ)[0]
|
| 41 |
+
assert field("x,y,z", QQ)[0] is not field("x,y", QQ)[0]
|
| 42 |
+
|
| 43 |
+
assert field("x,y", QQ)[0] != field("x,y,z", QQ)[0]
|
| 44 |
+
assert field("x,y", QQ)[0] is not field("x,y,z", QQ)[0]
|
| 45 |
+
|
| 46 |
+
def test_sfield():
|
| 47 |
+
x = symbols("x")
|
| 48 |
+
|
| 49 |
+
F = FracField((E, exp(exp(x)), exp(x)), ZZ, lex)
|
| 50 |
+
e, exex, ex = F.gens
|
| 51 |
+
assert sfield(exp(x)*exp(exp(x) + 1 + log(exp(x) + 3)/2)**2/(exp(x) + 3)) \
|
| 52 |
+
== (F, e**2*exex**2*ex)
|
| 53 |
+
|
| 54 |
+
F = FracField((x, exp(1/x), log(x), x**QQ(1, 3)), ZZ, lex)
|
| 55 |
+
_, ex, lg, x3 = F.gens
|
| 56 |
+
assert sfield(((x-3)*log(x)+4*x**2)*exp(1/x+log(x)/3)/x**2) == \
|
| 57 |
+
(F, (4*F.x**2*ex + F.x*ex*lg - 3*ex*lg)/x3**5)
|
| 58 |
+
|
| 59 |
+
F = FracField((x, log(x), sqrt(x + log(x))), ZZ, lex)
|
| 60 |
+
_, lg, srt = F.gens
|
| 61 |
+
assert sfield((x + 1) / (x * (x + log(x))**QQ(3, 2)) - 1/(x * log(x)**2)) \
|
| 62 |
+
== (F, (F.x*lg**2 - F.x*srt + lg**2 - lg*srt)/
|
| 63 |
+
(F.x**2*lg**2*srt + F.x*lg**3*srt))
|
| 64 |
+
|
| 65 |
+
def test_FracElement___hash__():
|
| 66 |
+
F, x, y, z = field("x,y,z", QQ)
|
| 67 |
+
assert hash(x*y/z)
|
| 68 |
+
|
| 69 |
+
def test_FracElement_copy():
|
| 70 |
+
F, x, y, z = field("x,y,z", ZZ)
|
| 71 |
+
|
| 72 |
+
f = x*y/3*z
|
| 73 |
+
g = f.copy()
|
| 74 |
+
|
| 75 |
+
assert f == g
|
| 76 |
+
g.numer[(1, 1, 1)] = 7
|
| 77 |
+
assert f != g
|
| 78 |
+
|
| 79 |
+
def test_FracElement_as_expr():
|
| 80 |
+
F, x, y, z = field("x,y,z", ZZ)
|
| 81 |
+
f = (3*x**2*y - x*y*z)/(7*z**3 + 1)
|
| 82 |
+
|
| 83 |
+
X, Y, Z = F.symbols
|
| 84 |
+
g = (3*X**2*Y - X*Y*Z)/(7*Z**3 + 1)
|
| 85 |
+
|
| 86 |
+
assert f != g
|
| 87 |
+
assert f.as_expr() == g
|
| 88 |
+
|
| 89 |
+
X, Y, Z = symbols("x,y,z")
|
| 90 |
+
g = (3*X**2*Y - X*Y*Z)/(7*Z**3 + 1)
|
| 91 |
+
|
| 92 |
+
assert f != g
|
| 93 |
+
assert f.as_expr(X, Y, Z) == g
|
| 94 |
+
|
| 95 |
+
raises(ValueError, lambda: f.as_expr(X))
|
| 96 |
+
|
| 97 |
+
def test_FracElement_from_expr():
|
| 98 |
+
x, y, z = symbols("x,y,z")
|
| 99 |
+
F, X, Y, Z = field((x, y, z), ZZ)
|
| 100 |
+
|
| 101 |
+
f = F.from_expr(1)
|
| 102 |
+
assert f == 1 and isinstance(f, F.dtype)
|
| 103 |
+
|
| 104 |
+
f = F.from_expr(Rational(3, 7))
|
| 105 |
+
assert f == F(3)/7 and isinstance(f, F.dtype)
|
| 106 |
+
|
| 107 |
+
f = F.from_expr(x)
|
| 108 |
+
assert f == X and isinstance(f, F.dtype)
|
| 109 |
+
|
| 110 |
+
f = F.from_expr(Rational(3,7)*x)
|
| 111 |
+
assert f == X*Rational(3, 7) and isinstance(f, F.dtype)
|
| 112 |
+
|
| 113 |
+
f = F.from_expr(1/x)
|
| 114 |
+
assert f == 1/X and isinstance(f, F.dtype)
|
| 115 |
+
|
| 116 |
+
f = F.from_expr(x*y*z)
|
| 117 |
+
assert f == X*Y*Z and isinstance(f, F.dtype)
|
| 118 |
+
|
| 119 |
+
f = F.from_expr(x*y/z)
|
| 120 |
+
assert f == X*Y/Z and isinstance(f, F.dtype)
|
| 121 |
+
|
| 122 |
+
f = F.from_expr(x*y*z + x*y + x)
|
| 123 |
+
assert f == X*Y*Z + X*Y + X and isinstance(f, F.dtype)
|
| 124 |
+
|
| 125 |
+
f = F.from_expr((x*y*z + x*y + x)/(x*y + 7))
|
| 126 |
+
assert f == (X*Y*Z + X*Y + X)/(X*Y + 7) and isinstance(f, F.dtype)
|
| 127 |
+
|
| 128 |
+
f = F.from_expr(x**3*y*z + x**2*y**7 + 1)
|
| 129 |
+
assert f == X**3*Y*Z + X**2*Y**7 + 1 and isinstance(f, F.dtype)
|
| 130 |
+
|
| 131 |
+
raises(ValueError, lambda: F.from_expr(2**x))
|
| 132 |
+
raises(ValueError, lambda: F.from_expr(7*x + sqrt(2)))
|
| 133 |
+
|
| 134 |
+
assert isinstance(ZZ[2**x].get_field().convert(2**(-x)),
|
| 135 |
+
FracElement)
|
| 136 |
+
assert isinstance(ZZ[x**2].get_field().convert(x**(-6)),
|
| 137 |
+
FracElement)
|
| 138 |
+
assert isinstance(ZZ[exp(Rational(1, 3))].get_field().convert(E),
|
| 139 |
+
FracElement)
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
def test_FracField_nested():
|
| 143 |
+
a, b, x = symbols('a b x')
|
| 144 |
+
F1 = ZZ.frac_field(a, b)
|
| 145 |
+
F2 = F1.frac_field(x)
|
| 146 |
+
frac = F2(a + b)
|
| 147 |
+
assert frac.numer == F1.poly_ring(x)(a + b)
|
| 148 |
+
assert frac.numer.coeffs() == [F1(a + b)]
|
| 149 |
+
assert frac.denom == F1.poly_ring(x)(1)
|
| 150 |
+
|
| 151 |
+
F3 = ZZ.poly_ring(a, b)
|
| 152 |
+
F4 = F3.frac_field(x)
|
| 153 |
+
frac = F4(a + b)
|
| 154 |
+
assert frac.numer == F3.poly_ring(x)(a + b)
|
| 155 |
+
assert frac.numer.coeffs() == [F3(a + b)]
|
| 156 |
+
assert frac.denom == F3.poly_ring(x)(1)
|
| 157 |
+
|
| 158 |
+
frac = F2(F3(a + b))
|
| 159 |
+
assert frac.numer == F1.poly_ring(x)(a + b)
|
| 160 |
+
assert frac.numer.coeffs() == [F1(a + b)]
|
| 161 |
+
assert frac.denom == F1.poly_ring(x)(1)
|
| 162 |
+
|
| 163 |
+
frac = F4(F1(a + b))
|
| 164 |
+
assert frac.numer == F3.poly_ring(x)(a + b)
|
| 165 |
+
assert frac.numer.coeffs() == [F3(a + b)]
|
| 166 |
+
assert frac.denom == F3.poly_ring(x)(1)
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
def test_FracElement__lt_le_gt_ge__():
|
| 170 |
+
F, x, y = field("x,y", ZZ)
|
| 171 |
+
|
| 172 |
+
assert F(1) < 1/x < 1/x**2 < 1/x**3
|
| 173 |
+
assert F(1) <= 1/x <= 1/x**2 <= 1/x**3
|
| 174 |
+
|
| 175 |
+
assert -7/x < 1/x < 3/x < y/x < 1/x**2
|
| 176 |
+
assert -7/x <= 1/x <= 3/x <= y/x <= 1/x**2
|
| 177 |
+
|
| 178 |
+
assert 1/x**3 > 1/x**2 > 1/x > F(1)
|
| 179 |
+
assert 1/x**3 >= 1/x**2 >= 1/x >= F(1)
|
| 180 |
+
|
| 181 |
+
assert 1/x**2 > y/x > 3/x > 1/x > -7/x
|
| 182 |
+
assert 1/x**2 >= y/x >= 3/x >= 1/x >= -7/x
|
| 183 |
+
|
| 184 |
+
def test_FracElement___neg__():
|
| 185 |
+
F, x,y = field("x,y", QQ)
|
| 186 |
+
|
| 187 |
+
f = (7*x - 9)/y
|
| 188 |
+
g = (-7*x + 9)/y
|
| 189 |
+
|
| 190 |
+
assert -f == g
|
| 191 |
+
assert -g == f
|
| 192 |
+
|
| 193 |
+
def test_FracElement___add__():
|
| 194 |
+
F, x,y = field("x,y", QQ)
|
| 195 |
+
|
| 196 |
+
f, g = 1/x, 1/y
|
| 197 |
+
assert f + g == g + f == (x + y)/(x*y)
|
| 198 |
+
|
| 199 |
+
assert x + F.ring.gens[0] == F.ring.gens[0] + x == 2*x
|
| 200 |
+
|
| 201 |
+
F, x,y = field("x,y", ZZ)
|
| 202 |
+
assert x + 3 == 3 + x
|
| 203 |
+
assert x + QQ(3,7) == QQ(3,7) + x == (7*x + 3)/7
|
| 204 |
+
|
| 205 |
+
Fuv, u,v = field("u,v", ZZ)
|
| 206 |
+
Fxyzt, x,y,z,t = field("x,y,z,t", Fuv)
|
| 207 |
+
|
| 208 |
+
f = (u*v + x)/(y + u*v)
|
| 209 |
+
assert dict(f.numer) == {(1, 0, 0, 0): 1, (0, 0, 0, 0): u*v}
|
| 210 |
+
assert dict(f.denom) == {(0, 1, 0, 0): 1, (0, 0, 0, 0): u*v}
|
| 211 |
+
|
| 212 |
+
Ruv, u,v = ring("u,v", ZZ)
|
| 213 |
+
Fxyzt, x,y,z,t = field("x,y,z,t", Ruv)
|
| 214 |
+
|
| 215 |
+
f = (u*v + x)/(y + u*v)
|
| 216 |
+
assert dict(f.numer) == {(1, 0, 0, 0): 1, (0, 0, 0, 0): u*v}
|
| 217 |
+
assert dict(f.denom) == {(0, 1, 0, 0): 1, (0, 0, 0, 0): u*v}
|
| 218 |
+
|
| 219 |
+
def test_FracElement___sub__():
|
| 220 |
+
F, x,y = field("x,y", QQ)
|
| 221 |
+
|
| 222 |
+
f, g = 1/x, 1/y
|
| 223 |
+
assert f - g == (-x + y)/(x*y)
|
| 224 |
+
|
| 225 |
+
assert x - F.ring.gens[0] == F.ring.gens[0] - x == 0
|
| 226 |
+
|
| 227 |
+
F, x,y = field("x,y", ZZ)
|
| 228 |
+
assert x - 3 == -(3 - x)
|
| 229 |
+
assert x - QQ(3,7) == -(QQ(3,7) - x) == (7*x - 3)/7
|
| 230 |
+
|
| 231 |
+
Fuv, u,v = field("u,v", ZZ)
|
| 232 |
+
Fxyzt, x,y,z,t = field("x,y,z,t", Fuv)
|
| 233 |
+
|
| 234 |
+
f = (u*v - x)/(y - u*v)
|
| 235 |
+
assert dict(f.numer) == {(1, 0, 0, 0):-1, (0, 0, 0, 0): u*v}
|
| 236 |
+
assert dict(f.denom) == {(0, 1, 0, 0): 1, (0, 0, 0, 0):-u*v}
|
| 237 |
+
|
| 238 |
+
Ruv, u,v = ring("u,v", ZZ)
|
| 239 |
+
Fxyzt, x,y,z,t = field("x,y,z,t", Ruv)
|
| 240 |
+
|
| 241 |
+
f = (u*v - x)/(y - u*v)
|
| 242 |
+
assert dict(f.numer) == {(1, 0, 0, 0):-1, (0, 0, 0, 0): u*v}
|
| 243 |
+
assert dict(f.denom) == {(0, 1, 0, 0): 1, (0, 0, 0, 0):-u*v}
|
| 244 |
+
|
| 245 |
+
def test_FracElement___mul__():
|
| 246 |
+
F, x,y = field("x,y", QQ)
|
| 247 |
+
|
| 248 |
+
f, g = 1/x, 1/y
|
| 249 |
+
assert f*g == g*f == 1/(x*y)
|
| 250 |
+
|
| 251 |
+
assert x*F.ring.gens[0] == F.ring.gens[0]*x == x**2
|
| 252 |
+
|
| 253 |
+
F, x,y = field("x,y", ZZ)
|
| 254 |
+
assert x*3 == 3*x
|
| 255 |
+
assert x*QQ(3,7) == QQ(3,7)*x == x*Rational(3, 7)
|
| 256 |
+
|
| 257 |
+
Fuv, u,v = field("u,v", ZZ)
|
| 258 |
+
Fxyzt, x,y,z,t = field("x,y,z,t", Fuv)
|
| 259 |
+
|
| 260 |
+
f = ((u + 1)*x*y + 1)/((v - 1)*z - t*u*v - 1)
|
| 261 |
+
assert dict(f.numer) == {(1, 1, 0, 0): u + 1, (0, 0, 0, 0): 1}
|
| 262 |
+
assert dict(f.denom) == {(0, 0, 1, 0): v - 1, (0, 0, 0, 1): -u*v, (0, 0, 0, 0): -1}
|
| 263 |
+
|
| 264 |
+
Ruv, u,v = ring("u,v", ZZ)
|
| 265 |
+
Fxyzt, x,y,z,t = field("x,y,z,t", Ruv)
|
| 266 |
+
|
| 267 |
+
f = ((u + 1)*x*y + 1)/((v - 1)*z - t*u*v - 1)
|
| 268 |
+
assert dict(f.numer) == {(1, 1, 0, 0): u + 1, (0, 0, 0, 0): 1}
|
| 269 |
+
assert dict(f.denom) == {(0, 0, 1, 0): v - 1, (0, 0, 0, 1): -u*v, (0, 0, 0, 0): -1}
|
| 270 |
+
|
| 271 |
+
def test_FracElement___truediv__():
|
| 272 |
+
F, x,y = field("x,y", QQ)
|
| 273 |
+
|
| 274 |
+
f, g = 1/x, 1/y
|
| 275 |
+
assert f/g == y/x
|
| 276 |
+
|
| 277 |
+
assert x/F.ring.gens[0] == F.ring.gens[0]/x == 1
|
| 278 |
+
|
| 279 |
+
F, x,y = field("x,y", ZZ)
|
| 280 |
+
assert x*3 == 3*x
|
| 281 |
+
assert x/QQ(3,7) == (QQ(3,7)/x)**-1 == x*Rational(7, 3)
|
| 282 |
+
|
| 283 |
+
raises(ZeroDivisionError, lambda: x/0)
|
| 284 |
+
raises(ZeroDivisionError, lambda: 1/(x - x))
|
| 285 |
+
raises(ZeroDivisionError, lambda: x/(x - x))
|
| 286 |
+
|
| 287 |
+
Fuv, u,v = field("u,v", ZZ)
|
| 288 |
+
Fxyzt, x,y,z,t = field("x,y,z,t", Fuv)
|
| 289 |
+
|
| 290 |
+
f = (u*v)/(x*y)
|
| 291 |
+
assert dict(f.numer) == {(0, 0, 0, 0): u*v}
|
| 292 |
+
assert dict(f.denom) == {(1, 1, 0, 0): 1}
|
| 293 |
+
|
| 294 |
+
g = (x*y)/(u*v)
|
| 295 |
+
assert dict(g.numer) == {(1, 1, 0, 0): 1}
|
| 296 |
+
assert dict(g.denom) == {(0, 0, 0, 0): u*v}
|
| 297 |
+
|
| 298 |
+
Ruv, u,v = ring("u,v", ZZ)
|
| 299 |
+
Fxyzt, x,y,z,t = field("x,y,z,t", Ruv)
|
| 300 |
+
|
| 301 |
+
f = (u*v)/(x*y)
|
| 302 |
+
assert dict(f.numer) == {(0, 0, 0, 0): u*v}
|
| 303 |
+
assert dict(f.denom) == {(1, 1, 0, 0): 1}
|
| 304 |
+
|
| 305 |
+
g = (x*y)/(u*v)
|
| 306 |
+
assert dict(g.numer) == {(1, 1, 0, 0): 1}
|
| 307 |
+
assert dict(g.denom) == {(0, 0, 0, 0): u*v}
|
| 308 |
+
|
| 309 |
+
def test_FracElement___pow__():
|
| 310 |
+
F, x,y = field("x,y", QQ)
|
| 311 |
+
|
| 312 |
+
f, g = 1/x, 1/y
|
| 313 |
+
|
| 314 |
+
assert f**3 == 1/x**3
|
| 315 |
+
assert g**3 == 1/y**3
|
| 316 |
+
|
| 317 |
+
assert (f*g)**3 == 1/(x**3*y**3)
|
| 318 |
+
assert (f*g)**-3 == (x*y)**3
|
| 319 |
+
|
| 320 |
+
raises(ZeroDivisionError, lambda: (x - x)**-3)
|
| 321 |
+
|
| 322 |
+
def test_FracElement_diff():
|
| 323 |
+
F, x,y,z = field("x,y,z", ZZ)
|
| 324 |
+
|
| 325 |
+
assert ((x**2 + y)/(z + 1)).diff(x) == 2*x/(z + 1)
|
| 326 |
+
|
| 327 |
+
@XFAIL
|
| 328 |
+
def test_FracElement___call__():
|
| 329 |
+
F, x,y,z = field("x,y,z", ZZ)
|
| 330 |
+
f = (x**2 + 3*y)/z
|
| 331 |
+
|
| 332 |
+
r = f(1, 1, 1)
|
| 333 |
+
assert r == 4 and not isinstance(r, FracElement)
|
| 334 |
+
raises(ZeroDivisionError, lambda: f(1, 1, 0))
|
| 335 |
+
|
| 336 |
+
def test_FracElement_evaluate():
|
| 337 |
+
F, x,y,z = field("x,y,z", ZZ)
|
| 338 |
+
Fyz = field("y,z", ZZ)[0]
|
| 339 |
+
f = (x**2 + 3*y)/z
|
| 340 |
+
|
| 341 |
+
assert f.evaluate(x, 0) == 3*Fyz.y/Fyz.z
|
| 342 |
+
raises(ZeroDivisionError, lambda: f.evaluate(z, 0))
|
| 343 |
+
|
| 344 |
+
def test_FracElement_subs():
|
| 345 |
+
F, x,y,z = field("x,y,z", ZZ)
|
| 346 |
+
f = (x**2 + 3*y)/z
|
| 347 |
+
|
| 348 |
+
assert f.subs(x, 0) == 3*y/z
|
| 349 |
+
raises(ZeroDivisionError, lambda: f.subs(z, 0))
|
| 350 |
+
|
| 351 |
+
def test_FracElement_compose():
|
| 352 |
+
pass
|
| 353 |
+
|
| 354 |
+
def test_FracField_index():
|
| 355 |
+
a = symbols("a")
|
| 356 |
+
F, x, y, z = field('x y z', QQ)
|
| 357 |
+
assert F.index(x) == 0
|
| 358 |
+
assert F.index(y) == 1
|
| 359 |
+
|
| 360 |
+
raises(ValueError, lambda: F.index(1))
|
| 361 |
+
raises(ValueError, lambda: F.index(a))
|
| 362 |
+
pass
|
pllava/lib/python3.10/site-packages/sympy/polys/tests/test_galoistools.py
ADDED
|
@@ -0,0 +1,875 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sympy.polys.galoistools import (
|
| 2 |
+
gf_crt, gf_crt1, gf_crt2, gf_int,
|
| 3 |
+
gf_degree, gf_strip, gf_trunc, gf_normal,
|
| 4 |
+
gf_from_dict, gf_to_dict,
|
| 5 |
+
gf_from_int_poly, gf_to_int_poly,
|
| 6 |
+
gf_neg, gf_add_ground, gf_sub_ground, gf_mul_ground,
|
| 7 |
+
gf_add, gf_sub, gf_add_mul, gf_sub_mul, gf_mul, gf_sqr,
|
| 8 |
+
gf_div, gf_rem, gf_quo, gf_exquo,
|
| 9 |
+
gf_lshift, gf_rshift, gf_expand,
|
| 10 |
+
gf_pow, gf_pow_mod,
|
| 11 |
+
gf_gcdex, gf_gcd, gf_lcm, gf_cofactors,
|
| 12 |
+
gf_LC, gf_TC, gf_monic,
|
| 13 |
+
gf_eval, gf_multi_eval,
|
| 14 |
+
gf_compose, gf_compose_mod,
|
| 15 |
+
gf_trace_map,
|
| 16 |
+
gf_diff,
|
| 17 |
+
gf_irreducible, gf_irreducible_p,
|
| 18 |
+
gf_irred_p_ben_or, gf_irred_p_rabin,
|
| 19 |
+
gf_sqf_list, gf_sqf_part, gf_sqf_p,
|
| 20 |
+
gf_Qmatrix, gf_Qbasis,
|
| 21 |
+
gf_ddf_zassenhaus, gf_ddf_shoup,
|
| 22 |
+
gf_edf_zassenhaus, gf_edf_shoup,
|
| 23 |
+
gf_berlekamp,
|
| 24 |
+
gf_factor_sqf, gf_factor,
|
| 25 |
+
gf_value, linear_congruence, _csolve_prime_las_vegas,
|
| 26 |
+
csolve_prime, gf_csolve, gf_frobenius_map, gf_frobenius_monomial_base
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
from sympy.polys.polyerrors import (
|
| 30 |
+
ExactQuotientFailed,
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
from sympy.polys import polyconfig as config
|
| 34 |
+
|
| 35 |
+
from sympy.polys.domains import ZZ
|
| 36 |
+
from sympy.core.numbers import pi
|
| 37 |
+
from sympy.ntheory.generate import nextprime
|
| 38 |
+
from sympy.testing.pytest import raises
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def test_gf_crt():
|
| 42 |
+
U = [49, 76, 65]
|
| 43 |
+
M = [99, 97, 95]
|
| 44 |
+
|
| 45 |
+
p = 912285
|
| 46 |
+
u = 639985
|
| 47 |
+
|
| 48 |
+
assert gf_crt(U, M, ZZ) == u
|
| 49 |
+
|
| 50 |
+
E = [9215, 9405, 9603]
|
| 51 |
+
S = [62, 24, 12]
|
| 52 |
+
|
| 53 |
+
assert gf_crt1(M, ZZ) == (p, E, S)
|
| 54 |
+
assert gf_crt2(U, M, p, E, S, ZZ) == u
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def test_gf_int():
|
| 58 |
+
assert gf_int(0, 5) == 0
|
| 59 |
+
assert gf_int(1, 5) == 1
|
| 60 |
+
assert gf_int(2, 5) == 2
|
| 61 |
+
assert gf_int(3, 5) == -2
|
| 62 |
+
assert gf_int(4, 5) == -1
|
| 63 |
+
assert gf_int(5, 5) == 0
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def test_gf_degree():
|
| 67 |
+
assert gf_degree([]) == -1
|
| 68 |
+
assert gf_degree([1]) == 0
|
| 69 |
+
assert gf_degree([1, 0]) == 1
|
| 70 |
+
assert gf_degree([1, 0, 0, 0, 1]) == 4
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def test_gf_strip():
|
| 74 |
+
assert gf_strip([]) == []
|
| 75 |
+
assert gf_strip([0]) == []
|
| 76 |
+
assert gf_strip([0, 0, 0]) == []
|
| 77 |
+
|
| 78 |
+
assert gf_strip([1]) == [1]
|
| 79 |
+
assert gf_strip([0, 1]) == [1]
|
| 80 |
+
assert gf_strip([0, 0, 0, 1]) == [1]
|
| 81 |
+
|
| 82 |
+
assert gf_strip([1, 2, 0]) == [1, 2, 0]
|
| 83 |
+
assert gf_strip([0, 1, 2, 0]) == [1, 2, 0]
|
| 84 |
+
assert gf_strip([0, 0, 0, 1, 2, 0]) == [1, 2, 0]
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
def test_gf_trunc():
|
| 88 |
+
assert gf_trunc([], 11) == []
|
| 89 |
+
assert gf_trunc([1], 11) == [1]
|
| 90 |
+
assert gf_trunc([22], 11) == []
|
| 91 |
+
assert gf_trunc([12], 11) == [1]
|
| 92 |
+
|
| 93 |
+
assert gf_trunc([11, 22, 17, 1, 0], 11) == [6, 1, 0]
|
| 94 |
+
assert gf_trunc([12, 23, 17, 1, 0], 11) == [1, 1, 6, 1, 0]
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
def test_gf_normal():
|
| 98 |
+
assert gf_normal([11, 22, 17, 1, 0], 11, ZZ) == [6, 1, 0]
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
def test_gf_from_to_dict():
|
| 102 |
+
f = {11: 12, 6: 2, 0: 25}
|
| 103 |
+
F = {11: 1, 6: 2, 0: 3}
|
| 104 |
+
g = [1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 3]
|
| 105 |
+
|
| 106 |
+
assert gf_from_dict(f, 11, ZZ) == g
|
| 107 |
+
assert gf_to_dict(g, 11) == F
|
| 108 |
+
|
| 109 |
+
f = {11: -5, 4: 0, 3: 1, 0: 12}
|
| 110 |
+
F = {11: -5, 3: 1, 0: 1}
|
| 111 |
+
g = [6, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1]
|
| 112 |
+
|
| 113 |
+
assert gf_from_dict(f, 11, ZZ) == g
|
| 114 |
+
assert gf_to_dict(g, 11) == F
|
| 115 |
+
|
| 116 |
+
assert gf_to_dict([10], 11, symmetric=True) == {0: -1}
|
| 117 |
+
assert gf_to_dict([10], 11, symmetric=False) == {0: 10}
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
def test_gf_from_to_int_poly():
|
| 121 |
+
assert gf_from_int_poly([1, 0, 7, 2, 20], 5) == [1, 0, 2, 2, 0]
|
| 122 |
+
assert gf_to_int_poly([1, 0, 4, 2, 3], 5) == [1, 0, -1, 2, -2]
|
| 123 |
+
|
| 124 |
+
assert gf_to_int_poly([10], 11, symmetric=True) == [-1]
|
| 125 |
+
assert gf_to_int_poly([10], 11, symmetric=False) == [10]
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
def test_gf_LC():
|
| 129 |
+
assert gf_LC([], ZZ) == 0
|
| 130 |
+
assert gf_LC([1], ZZ) == 1
|
| 131 |
+
assert gf_LC([1, 2], ZZ) == 1
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
def test_gf_TC():
|
| 135 |
+
assert gf_TC([], ZZ) == 0
|
| 136 |
+
assert gf_TC([1], ZZ) == 1
|
| 137 |
+
assert gf_TC([1, 2], ZZ) == 2
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
def test_gf_monic():
|
| 141 |
+
assert gf_monic(ZZ.map([]), 11, ZZ) == (0, [])
|
| 142 |
+
|
| 143 |
+
assert gf_monic(ZZ.map([1]), 11, ZZ) == (1, [1])
|
| 144 |
+
assert gf_monic(ZZ.map([2]), 11, ZZ) == (2, [1])
|
| 145 |
+
|
| 146 |
+
assert gf_monic(ZZ.map([1, 2, 3, 4]), 11, ZZ) == (1, [1, 2, 3, 4])
|
| 147 |
+
assert gf_monic(ZZ.map([2, 3, 4, 5]), 11, ZZ) == (2, [1, 7, 2, 8])
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
def test_gf_arith():
|
| 151 |
+
assert gf_neg([], 11, ZZ) == []
|
| 152 |
+
assert gf_neg([1], 11, ZZ) == [10]
|
| 153 |
+
assert gf_neg([1, 2, 3], 11, ZZ) == [10, 9, 8]
|
| 154 |
+
|
| 155 |
+
assert gf_add_ground([], 0, 11, ZZ) == []
|
| 156 |
+
assert gf_sub_ground([], 0, 11, ZZ) == []
|
| 157 |
+
|
| 158 |
+
assert gf_add_ground([], 3, 11, ZZ) == [3]
|
| 159 |
+
assert gf_sub_ground([], 3, 11, ZZ) == [8]
|
| 160 |
+
|
| 161 |
+
assert gf_add_ground([1], 3, 11, ZZ) == [4]
|
| 162 |
+
assert gf_sub_ground([1], 3, 11, ZZ) == [9]
|
| 163 |
+
|
| 164 |
+
assert gf_add_ground([8], 3, 11, ZZ) == []
|
| 165 |
+
assert gf_sub_ground([3], 3, 11, ZZ) == []
|
| 166 |
+
|
| 167 |
+
assert gf_add_ground([1, 2, 3], 3, 11, ZZ) == [1, 2, 6]
|
| 168 |
+
assert gf_sub_ground([1, 2, 3], 3, 11, ZZ) == [1, 2, 0]
|
| 169 |
+
|
| 170 |
+
assert gf_mul_ground([], 0, 11, ZZ) == []
|
| 171 |
+
assert gf_mul_ground([], 1, 11, ZZ) == []
|
| 172 |
+
|
| 173 |
+
assert gf_mul_ground([1], 0, 11, ZZ) == []
|
| 174 |
+
assert gf_mul_ground([1], 1, 11, ZZ) == [1]
|
| 175 |
+
|
| 176 |
+
assert gf_mul_ground([1, 2, 3], 0, 11, ZZ) == []
|
| 177 |
+
assert gf_mul_ground([1, 2, 3], 1, 11, ZZ) == [1, 2, 3]
|
| 178 |
+
assert gf_mul_ground([1, 2, 3], 7, 11, ZZ) == [7, 3, 10]
|
| 179 |
+
|
| 180 |
+
assert gf_add([], [], 11, ZZ) == []
|
| 181 |
+
assert gf_add([1], [], 11, ZZ) == [1]
|
| 182 |
+
assert gf_add([], [1], 11, ZZ) == [1]
|
| 183 |
+
assert gf_add([1], [1], 11, ZZ) == [2]
|
| 184 |
+
assert gf_add([1], [2], 11, ZZ) == [3]
|
| 185 |
+
|
| 186 |
+
assert gf_add([1, 2], [1], 11, ZZ) == [1, 3]
|
| 187 |
+
assert gf_add([1], [1, 2], 11, ZZ) == [1, 3]
|
| 188 |
+
|
| 189 |
+
assert gf_add([1, 2, 3], [8, 9, 10], 11, ZZ) == [9, 0, 2]
|
| 190 |
+
|
| 191 |
+
assert gf_sub([], [], 11, ZZ) == []
|
| 192 |
+
assert gf_sub([1], [], 11, ZZ) == [1]
|
| 193 |
+
assert gf_sub([], [1], 11, ZZ) == [10]
|
| 194 |
+
assert gf_sub([1], [1], 11, ZZ) == []
|
| 195 |
+
assert gf_sub([1], [2], 11, ZZ) == [10]
|
| 196 |
+
|
| 197 |
+
assert gf_sub([1, 2], [1], 11, ZZ) == [1, 1]
|
| 198 |
+
assert gf_sub([1], [1, 2], 11, ZZ) == [10, 10]
|
| 199 |
+
|
| 200 |
+
assert gf_sub([3, 2, 1], [8, 9, 10], 11, ZZ) == [6, 4, 2]
|
| 201 |
+
|
| 202 |
+
assert gf_add_mul(
|
| 203 |
+
[1, 5, 6], [7, 3], [8, 0, 6, 1], 11, ZZ) == [1, 2, 10, 8, 9]
|
| 204 |
+
assert gf_sub_mul(
|
| 205 |
+
[1, 5, 6], [7, 3], [8, 0, 6, 1], 11, ZZ) == [10, 9, 3, 2, 3]
|
| 206 |
+
|
| 207 |
+
assert gf_mul([], [], 11, ZZ) == []
|
| 208 |
+
assert gf_mul([], [1], 11, ZZ) == []
|
| 209 |
+
assert gf_mul([1], [], 11, ZZ) == []
|
| 210 |
+
assert gf_mul([1], [1], 11, ZZ) == [1]
|
| 211 |
+
assert gf_mul([5], [7], 11, ZZ) == [2]
|
| 212 |
+
|
| 213 |
+
assert gf_mul([3, 0, 0, 6, 1, 2], [4, 0, 1, 0], 11, ZZ) == [1, 0,
|
| 214 |
+
3, 2, 4, 3, 1, 2, 0]
|
| 215 |
+
assert gf_mul([4, 0, 1, 0], [3, 0, 0, 6, 1, 2], 11, ZZ) == [1, 0,
|
| 216 |
+
3, 2, 4, 3, 1, 2, 0]
|
| 217 |
+
|
| 218 |
+
assert gf_mul([2, 0, 0, 1, 7], [2, 0, 0, 1, 7], 11, ZZ) == [4, 0,
|
| 219 |
+
0, 4, 6, 0, 1, 3, 5]
|
| 220 |
+
|
| 221 |
+
assert gf_sqr([], 11, ZZ) == []
|
| 222 |
+
assert gf_sqr([2], 11, ZZ) == [4]
|
| 223 |
+
assert gf_sqr([1, 2], 11, ZZ) == [1, 4, 4]
|
| 224 |
+
|
| 225 |
+
assert gf_sqr([2, 0, 0, 1, 7], 11, ZZ) == [4, 0, 0, 4, 6, 0, 1, 3, 5]
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
def test_gf_division():
|
| 229 |
+
raises(ZeroDivisionError, lambda: gf_div([1, 2, 3], [], 11, ZZ))
|
| 230 |
+
raises(ZeroDivisionError, lambda: gf_rem([1, 2, 3], [], 11, ZZ))
|
| 231 |
+
raises(ZeroDivisionError, lambda: gf_quo([1, 2, 3], [], 11, ZZ))
|
| 232 |
+
raises(ZeroDivisionError, lambda: gf_quo([1, 2, 3], [], 11, ZZ))
|
| 233 |
+
|
| 234 |
+
assert gf_div([1], [1, 2, 3], 7, ZZ) == ([], [1])
|
| 235 |
+
assert gf_rem([1], [1, 2, 3], 7, ZZ) == [1]
|
| 236 |
+
assert gf_quo([1], [1, 2, 3], 7, ZZ) == []
|
| 237 |
+
|
| 238 |
+
f = ZZ.map([5, 4, 3, 2, 1, 0])
|
| 239 |
+
g = ZZ.map([1, 2, 3])
|
| 240 |
+
q = [5, 1, 0, 6]
|
| 241 |
+
r = [3, 3]
|
| 242 |
+
|
| 243 |
+
assert gf_div(f, g, 7, ZZ) == (q, r)
|
| 244 |
+
assert gf_rem(f, g, 7, ZZ) == r
|
| 245 |
+
assert gf_quo(f, g, 7, ZZ) == q
|
| 246 |
+
|
| 247 |
+
raises(ExactQuotientFailed, lambda: gf_exquo(f, g, 7, ZZ))
|
| 248 |
+
|
| 249 |
+
f = ZZ.map([5, 4, 3, 2, 1, 0])
|
| 250 |
+
g = ZZ.map([1, 2, 3, 0])
|
| 251 |
+
q = [5, 1, 0]
|
| 252 |
+
r = [6, 1, 0]
|
| 253 |
+
|
| 254 |
+
assert gf_div(f, g, 7, ZZ) == (q, r)
|
| 255 |
+
assert gf_rem(f, g, 7, ZZ) == r
|
| 256 |
+
assert gf_quo(f, g, 7, ZZ) == q
|
| 257 |
+
|
| 258 |
+
raises(ExactQuotientFailed, lambda: gf_exquo(f, g, 7, ZZ))
|
| 259 |
+
|
| 260 |
+
assert gf_quo(ZZ.map([1, 2, 1]), ZZ.map([1, 1]), 11, ZZ) == [1, 1]
|
| 261 |
+
|
| 262 |
+
|
| 263 |
+
def test_gf_shift():
|
| 264 |
+
f = [1, 2, 3, 4, 5]
|
| 265 |
+
|
| 266 |
+
assert gf_lshift([], 5, ZZ) == []
|
| 267 |
+
assert gf_rshift([], 5, ZZ) == ([], [])
|
| 268 |
+
|
| 269 |
+
assert gf_lshift(f, 1, ZZ) == [1, 2, 3, 4, 5, 0]
|
| 270 |
+
assert gf_lshift(f, 2, ZZ) == [1, 2, 3, 4, 5, 0, 0]
|
| 271 |
+
|
| 272 |
+
assert gf_rshift(f, 0, ZZ) == (f, [])
|
| 273 |
+
assert gf_rshift(f, 1, ZZ) == ([1, 2, 3, 4], [5])
|
| 274 |
+
assert gf_rshift(f, 3, ZZ) == ([1, 2], [3, 4, 5])
|
| 275 |
+
assert gf_rshift(f, 5, ZZ) == ([], f)
|
| 276 |
+
|
| 277 |
+
|
| 278 |
+
def test_gf_expand():
|
| 279 |
+
F = [([1, 1], 2), ([1, 2], 3)]
|
| 280 |
+
|
| 281 |
+
assert gf_expand(F, 11, ZZ) == [1, 8, 3, 5, 6, 8]
|
| 282 |
+
assert gf_expand((4, F), 11, ZZ) == [4, 10, 1, 9, 2, 10]
|
| 283 |
+
|
| 284 |
+
|
| 285 |
+
def test_gf_powering():
|
| 286 |
+
assert gf_pow([1, 0, 0, 1, 8], 0, 11, ZZ) == [1]
|
| 287 |
+
assert gf_pow([1, 0, 0, 1, 8], 1, 11, ZZ) == [1, 0, 0, 1, 8]
|
| 288 |
+
assert gf_pow([1, 0, 0, 1, 8], 2, 11, ZZ) == [1, 0, 0, 2, 5, 0, 1, 5, 9]
|
| 289 |
+
|
| 290 |
+
assert gf_pow([1, 0, 0, 1, 8], 5, 11, ZZ) == \
|
| 291 |
+
[1, 0, 0, 5, 7, 0, 10, 6, 2, 10, 9, 6, 10, 6, 6, 0, 5, 2, 5, 9, 10]
|
| 292 |
+
|
| 293 |
+
assert gf_pow([1, 0, 0, 1, 8], 8, 11, ZZ) == \
|
| 294 |
+
[1, 0, 0, 8, 9, 0, 6, 8, 10, 1, 2, 5, 10, 7, 7, 9, 1, 2, 0, 0, 6, 2,
|
| 295 |
+
5, 2, 5, 7, 7, 9, 10, 10, 7, 5, 5]
|
| 296 |
+
|
| 297 |
+
assert gf_pow([1, 0, 0, 1, 8], 45, 11, ZZ) == \
|
| 298 |
+
[ 1, 0, 0, 1, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
| 299 |
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 4, 10, 0, 0, 0, 0, 0, 0,
|
| 300 |
+
10, 0, 0, 10, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
| 301 |
+
6, 0, 0, 6, 4, 0, 0, 0, 0, 0, 0, 8, 0, 0, 8, 9, 0, 0, 0, 0, 0, 0,
|
| 302 |
+
10, 0, 0, 10, 3, 0, 0, 0, 0, 0, 0, 4, 0, 0, 4, 10, 0, 0, 0, 0, 0, 0,
|
| 303 |
+
8, 0, 0, 8, 9, 0, 0, 0, 0, 0, 0, 9, 0, 0, 9, 6, 0, 0, 0, 0, 0, 0,
|
| 304 |
+
3, 0, 0, 3, 2, 0, 0, 0, 0, 0, 0, 10, 0, 0, 10, 3, 0, 0, 0, 0, 0, 0,
|
| 305 |
+
10, 0, 0, 10, 3, 0, 0, 0, 0, 0, 0, 2, 0, 0, 2, 5, 0, 0, 0, 0, 0, 0,
|
| 306 |
+
4, 0, 0, 4, 10]
|
| 307 |
+
|
| 308 |
+
assert gf_pow_mod(ZZ.map([1, 0, 0, 1, 8]), 0, ZZ.map([2, 0, 7]), 11, ZZ) == [1]
|
| 309 |
+
assert gf_pow_mod(ZZ.map([1, 0, 0, 1, 8]), 1, ZZ.map([2, 0, 7]), 11, ZZ) == [1, 1]
|
| 310 |
+
assert gf_pow_mod(ZZ.map([1, 0, 0, 1, 8]), 2, ZZ.map([2, 0, 7]), 11, ZZ) == [2, 3]
|
| 311 |
+
assert gf_pow_mod(ZZ.map([1, 0, 0, 1, 8]), 5, ZZ.map([2, 0, 7]), 11, ZZ) == [7, 8]
|
| 312 |
+
assert gf_pow_mod(ZZ.map([1, 0, 0, 1, 8]), 8, ZZ.map([2, 0, 7]), 11, ZZ) == [1, 5]
|
| 313 |
+
assert gf_pow_mod(ZZ.map([1, 0, 0, 1, 8]), 45, ZZ.map([2, 0, 7]), 11, ZZ) == [5, 4]
|
| 314 |
+
|
| 315 |
+
|
| 316 |
+
def test_gf_gcdex():
|
| 317 |
+
assert gf_gcdex(ZZ.map([]), ZZ.map([]), 11, ZZ) == ([1], [], [])
|
| 318 |
+
assert gf_gcdex(ZZ.map([2]), ZZ.map([]), 11, ZZ) == ([6], [], [1])
|
| 319 |
+
assert gf_gcdex(ZZ.map([]), ZZ.map([2]), 11, ZZ) == ([], [6], [1])
|
| 320 |
+
assert gf_gcdex(ZZ.map([2]), ZZ.map([2]), 11, ZZ) == ([], [6], [1])
|
| 321 |
+
|
| 322 |
+
assert gf_gcdex(ZZ.map([]), ZZ.map([3, 0]), 11, ZZ) == ([], [4], [1, 0])
|
| 323 |
+
assert gf_gcdex(ZZ.map([3, 0]), ZZ.map([]), 11, ZZ) == ([4], [], [1, 0])
|
| 324 |
+
|
| 325 |
+
assert gf_gcdex(ZZ.map([3, 0]), ZZ.map([3, 0]), 11, ZZ) == ([], [4], [1, 0])
|
| 326 |
+
|
| 327 |
+
assert gf_gcdex(ZZ.map([1, 8, 7]), ZZ.map([1, 7, 1, 7]), 11, ZZ) == ([5, 6], [6], [1, 7])
|
| 328 |
+
|
| 329 |
+
|
| 330 |
+
def test_gf_gcd():
|
| 331 |
+
assert gf_gcd(ZZ.map([]), ZZ.map([]), 11, ZZ) == []
|
| 332 |
+
assert gf_gcd(ZZ.map([2]), ZZ.map([]), 11, ZZ) == [1]
|
| 333 |
+
assert gf_gcd(ZZ.map([]), ZZ.map([2]), 11, ZZ) == [1]
|
| 334 |
+
assert gf_gcd(ZZ.map([2]), ZZ.map([2]), 11, ZZ) == [1]
|
| 335 |
+
|
| 336 |
+
assert gf_gcd(ZZ.map([]), ZZ.map([1, 0]), 11, ZZ) == [1, 0]
|
| 337 |
+
assert gf_gcd(ZZ.map([1, 0]), ZZ.map([]), 11, ZZ) == [1, 0]
|
| 338 |
+
|
| 339 |
+
assert gf_gcd(ZZ.map([3, 0]), ZZ.map([3, 0]), 11, ZZ) == [1, 0]
|
| 340 |
+
assert gf_gcd(ZZ.map([1, 8, 7]), ZZ.map([1, 7, 1, 7]), 11, ZZ) == [1, 7]
|
| 341 |
+
|
| 342 |
+
|
| 343 |
+
def test_gf_lcm():
|
| 344 |
+
assert gf_lcm(ZZ.map([]), ZZ.map([]), 11, ZZ) == []
|
| 345 |
+
assert gf_lcm(ZZ.map([2]), ZZ.map([]), 11, ZZ) == []
|
| 346 |
+
assert gf_lcm(ZZ.map([]), ZZ.map([2]), 11, ZZ) == []
|
| 347 |
+
assert gf_lcm(ZZ.map([2]), ZZ.map([2]), 11, ZZ) == [1]
|
| 348 |
+
|
| 349 |
+
assert gf_lcm(ZZ.map([]), ZZ.map([1, 0]), 11, ZZ) == []
|
| 350 |
+
assert gf_lcm(ZZ.map([1, 0]), ZZ.map([]), 11, ZZ) == []
|
| 351 |
+
|
| 352 |
+
assert gf_lcm(ZZ.map([3, 0]), ZZ.map([3, 0]), 11, ZZ) == [1, 0]
|
| 353 |
+
assert gf_lcm(ZZ.map([1, 8, 7]), ZZ.map([1, 7, 1, 7]), 11, ZZ) == [1, 8, 8, 8, 7]
|
| 354 |
+
|
| 355 |
+
|
| 356 |
+
def test_gf_cofactors():
|
| 357 |
+
assert gf_cofactors(ZZ.map([]), ZZ.map([]), 11, ZZ) == ([], [], [])
|
| 358 |
+
assert gf_cofactors(ZZ.map([2]), ZZ.map([]), 11, ZZ) == ([1], [2], [])
|
| 359 |
+
assert gf_cofactors(ZZ.map([]), ZZ.map([2]), 11, ZZ) == ([1], [], [2])
|
| 360 |
+
assert gf_cofactors(ZZ.map([2]), ZZ.map([2]), 11, ZZ) == ([1], [2], [2])
|
| 361 |
+
|
| 362 |
+
assert gf_cofactors(ZZ.map([]), ZZ.map([1, 0]), 11, ZZ) == ([1, 0], [], [1])
|
| 363 |
+
assert gf_cofactors(ZZ.map([1, 0]), ZZ.map([]), 11, ZZ) == ([1, 0], [1], [])
|
| 364 |
+
|
| 365 |
+
assert gf_cofactors(ZZ.map([3, 0]), ZZ.map([3, 0]), 11, ZZ) == (
|
| 366 |
+
[1, 0], [3], [3])
|
| 367 |
+
assert gf_cofactors(ZZ.map([1, 8, 7]), ZZ.map([1, 7, 1, 7]), 11, ZZ) == (
|
| 368 |
+
([1, 7], [1, 1], [1, 0, 1]))
|
| 369 |
+
|
| 370 |
+
|
| 371 |
+
def test_gf_diff():
|
| 372 |
+
assert gf_diff([], 11, ZZ) == []
|
| 373 |
+
assert gf_diff([7], 11, ZZ) == []
|
| 374 |
+
|
| 375 |
+
assert gf_diff([7, 3], 11, ZZ) == [7]
|
| 376 |
+
assert gf_diff([7, 3, 1], 11, ZZ) == [3, 3]
|
| 377 |
+
|
| 378 |
+
assert gf_diff([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], 11, ZZ) == []
|
| 379 |
+
|
| 380 |
+
|
| 381 |
+
def test_gf_eval():
|
| 382 |
+
assert gf_eval([], 4, 11, ZZ) == 0
|
| 383 |
+
assert gf_eval([], 27, 11, ZZ) == 0
|
| 384 |
+
assert gf_eval([7], 4, 11, ZZ) == 7
|
| 385 |
+
assert gf_eval([7], 27, 11, ZZ) == 7
|
| 386 |
+
|
| 387 |
+
assert gf_eval([1, 0, 3, 2, 4, 3, 1, 2, 0], 0, 11, ZZ) == 0
|
| 388 |
+
assert gf_eval([1, 0, 3, 2, 4, 3, 1, 2, 0], 4, 11, ZZ) == 9
|
| 389 |
+
assert gf_eval([1, 0, 3, 2, 4, 3, 1, 2, 0], 27, 11, ZZ) == 5
|
| 390 |
+
|
| 391 |
+
assert gf_eval([4, 0, 0, 4, 6, 0, 1, 3, 5], 0, 11, ZZ) == 5
|
| 392 |
+
assert gf_eval([4, 0, 0, 4, 6, 0, 1, 3, 5], 4, 11, ZZ) == 3
|
| 393 |
+
assert gf_eval([4, 0, 0, 4, 6, 0, 1, 3, 5], 27, 11, ZZ) == 9
|
| 394 |
+
|
| 395 |
+
assert gf_multi_eval([3, 2, 1], [0, 1, 2, 3], 11, ZZ) == [1, 6, 6, 1]
|
| 396 |
+
|
| 397 |
+
|
| 398 |
+
def test_gf_compose():
|
| 399 |
+
assert gf_compose([], [1, 0], 11, ZZ) == []
|
| 400 |
+
assert gf_compose_mod([], [1, 0], [1, 0], 11, ZZ) == []
|
| 401 |
+
|
| 402 |
+
assert gf_compose([1], [], 11, ZZ) == [1]
|
| 403 |
+
assert gf_compose([1, 0], [], 11, ZZ) == []
|
| 404 |
+
assert gf_compose([1, 0], [1, 0], 11, ZZ) == [1, 0]
|
| 405 |
+
|
| 406 |
+
f = ZZ.map([1, 1, 4, 9, 1])
|
| 407 |
+
g = ZZ.map([1, 1, 1])
|
| 408 |
+
h = ZZ.map([1, 0, 0, 2])
|
| 409 |
+
|
| 410 |
+
assert gf_compose(g, h, 11, ZZ) == [1, 0, 0, 5, 0, 0, 7]
|
| 411 |
+
assert gf_compose_mod(g, h, f, 11, ZZ) == [3, 9, 6, 10]
|
| 412 |
+
|
| 413 |
+
|
| 414 |
+
def test_gf_trace_map():
|
| 415 |
+
f = ZZ.map([1, 1, 4, 9, 1])
|
| 416 |
+
a = [1, 1, 1]
|
| 417 |
+
c = ZZ.map([1, 0])
|
| 418 |
+
b = gf_pow_mod(c, 11, f, 11, ZZ)
|
| 419 |
+
|
| 420 |
+
assert gf_trace_map(a, b, c, 0, f, 11, ZZ) == \
|
| 421 |
+
([1, 1, 1], [1, 1, 1])
|
| 422 |
+
assert gf_trace_map(a, b, c, 1, f, 11, ZZ) == \
|
| 423 |
+
([5, 2, 10, 3], [5, 3, 0, 4])
|
| 424 |
+
assert gf_trace_map(a, b, c, 2, f, 11, ZZ) == \
|
| 425 |
+
([5, 9, 5, 3], [10, 1, 5, 7])
|
| 426 |
+
assert gf_trace_map(a, b, c, 3, f, 11, ZZ) == \
|
| 427 |
+
([1, 10, 6, 0], [7])
|
| 428 |
+
assert gf_trace_map(a, b, c, 4, f, 11, ZZ) == \
|
| 429 |
+
([1, 1, 1], [1, 1, 8])
|
| 430 |
+
assert gf_trace_map(a, b, c, 5, f, 11, ZZ) == \
|
| 431 |
+
([5, 2, 10, 3], [5, 3, 0, 0])
|
| 432 |
+
assert gf_trace_map(a, b, c, 11, f, 11, ZZ) == \
|
| 433 |
+
([1, 10, 6, 0], [10])
|
| 434 |
+
|
| 435 |
+
|
| 436 |
+
def test_gf_irreducible():
|
| 437 |
+
assert gf_irreducible_p(gf_irreducible(1, 11, ZZ), 11, ZZ) is True
|
| 438 |
+
assert gf_irreducible_p(gf_irreducible(2, 11, ZZ), 11, ZZ) is True
|
| 439 |
+
assert gf_irreducible_p(gf_irreducible(3, 11, ZZ), 11, ZZ) is True
|
| 440 |
+
assert gf_irreducible_p(gf_irreducible(4, 11, ZZ), 11, ZZ) is True
|
| 441 |
+
assert gf_irreducible_p(gf_irreducible(5, 11, ZZ), 11, ZZ) is True
|
| 442 |
+
assert gf_irreducible_p(gf_irreducible(6, 11, ZZ), 11, ZZ) is True
|
| 443 |
+
assert gf_irreducible_p(gf_irreducible(7, 11, ZZ), 11, ZZ) is True
|
| 444 |
+
|
| 445 |
+
|
| 446 |
+
def test_gf_irreducible_p():
|
| 447 |
+
assert gf_irred_p_ben_or(ZZ.map([7]), 11, ZZ) is True
|
| 448 |
+
assert gf_irred_p_ben_or(ZZ.map([7, 3]), 11, ZZ) is True
|
| 449 |
+
assert gf_irred_p_ben_or(ZZ.map([7, 3, 1]), 11, ZZ) is False
|
| 450 |
+
|
| 451 |
+
assert gf_irred_p_rabin(ZZ.map([7]), 11, ZZ) is True
|
| 452 |
+
assert gf_irred_p_rabin(ZZ.map([7, 3]), 11, ZZ) is True
|
| 453 |
+
assert gf_irred_p_rabin(ZZ.map([7, 3, 1]), 11, ZZ) is False
|
| 454 |
+
|
| 455 |
+
config.setup('GF_IRRED_METHOD', 'ben-or')
|
| 456 |
+
|
| 457 |
+
assert gf_irreducible_p(ZZ.map([7]), 11, ZZ) is True
|
| 458 |
+
assert gf_irreducible_p(ZZ.map([7, 3]), 11, ZZ) is True
|
| 459 |
+
assert gf_irreducible_p(ZZ.map([7, 3, 1]), 11, ZZ) is False
|
| 460 |
+
|
| 461 |
+
config.setup('GF_IRRED_METHOD', 'rabin')
|
| 462 |
+
|
| 463 |
+
assert gf_irreducible_p(ZZ.map([7]), 11, ZZ) is True
|
| 464 |
+
assert gf_irreducible_p(ZZ.map([7, 3]), 11, ZZ) is True
|
| 465 |
+
assert gf_irreducible_p(ZZ.map([7, 3, 1]), 11, ZZ) is False
|
| 466 |
+
|
| 467 |
+
config.setup('GF_IRRED_METHOD', 'other')
|
| 468 |
+
raises(KeyError, lambda: gf_irreducible_p([7], 11, ZZ))
|
| 469 |
+
config.setup('GF_IRRED_METHOD')
|
| 470 |
+
|
| 471 |
+
f = ZZ.map([1, 9, 9, 13, 16, 15, 6, 7, 7, 7, 10])
|
| 472 |
+
g = ZZ.map([1, 7, 16, 7, 15, 13, 13, 11, 16, 10, 9])
|
| 473 |
+
|
| 474 |
+
h = gf_mul(f, g, 17, ZZ)
|
| 475 |
+
|
| 476 |
+
assert gf_irred_p_ben_or(f, 17, ZZ) is True
|
| 477 |
+
assert gf_irred_p_ben_or(g, 17, ZZ) is True
|
| 478 |
+
|
| 479 |
+
assert gf_irred_p_ben_or(h, 17, ZZ) is False
|
| 480 |
+
|
| 481 |
+
assert gf_irred_p_rabin(f, 17, ZZ) is True
|
| 482 |
+
assert gf_irred_p_rabin(g, 17, ZZ) is True
|
| 483 |
+
|
| 484 |
+
assert gf_irred_p_rabin(h, 17, ZZ) is False
|
| 485 |
+
|
| 486 |
+
|
| 487 |
+
def test_gf_squarefree():
|
| 488 |
+
assert gf_sqf_list([], 11, ZZ) == (0, [])
|
| 489 |
+
assert gf_sqf_list([1], 11, ZZ) == (1, [])
|
| 490 |
+
assert gf_sqf_list([1, 1], 11, ZZ) == (1, [([1, 1], 1)])
|
| 491 |
+
|
| 492 |
+
assert gf_sqf_p([], 11, ZZ) is True
|
| 493 |
+
assert gf_sqf_p([1], 11, ZZ) is True
|
| 494 |
+
assert gf_sqf_p([1, 1], 11, ZZ) is True
|
| 495 |
+
|
| 496 |
+
f = gf_from_dict({11: 1, 0: 1}, 11, ZZ)
|
| 497 |
+
|
| 498 |
+
assert gf_sqf_p(f, 11, ZZ) is False
|
| 499 |
+
|
| 500 |
+
assert gf_sqf_list(f, 11, ZZ) == \
|
| 501 |
+
(1, [([1, 1], 11)])
|
| 502 |
+
|
| 503 |
+
f = [1, 5, 8, 4]
|
| 504 |
+
|
| 505 |
+
assert gf_sqf_p(f, 11, ZZ) is False
|
| 506 |
+
|
| 507 |
+
assert gf_sqf_list(f, 11, ZZ) == \
|
| 508 |
+
(1, [([1, 1], 1),
|
| 509 |
+
([1, 2], 2)])
|
| 510 |
+
|
| 511 |
+
assert gf_sqf_part(f, 11, ZZ) == [1, 3, 2]
|
| 512 |
+
|
| 513 |
+
f = [1, 0, 0, 2, 0, 0, 2, 0, 0, 1, 0]
|
| 514 |
+
|
| 515 |
+
assert gf_sqf_list(f, 3, ZZ) == \
|
| 516 |
+
(1, [([1, 0], 1),
|
| 517 |
+
([1, 1], 3),
|
| 518 |
+
([1, 2], 6)])
|
| 519 |
+
|
| 520 |
+
def test_gf_frobenius_map():
|
| 521 |
+
f = ZZ.map([2, 0, 1, 0, 2, 2, 0, 2, 2, 2])
|
| 522 |
+
g = ZZ.map([1,1,0,2,0,1,0,2,0,1])
|
| 523 |
+
p = 3
|
| 524 |
+
b = gf_frobenius_monomial_base(g, p, ZZ)
|
| 525 |
+
h = gf_frobenius_map(f, g, b, p, ZZ)
|
| 526 |
+
h1 = gf_pow_mod(f, p, g, p, ZZ)
|
| 527 |
+
assert h == h1
|
| 528 |
+
|
| 529 |
+
|
| 530 |
+
def test_gf_berlekamp():
|
| 531 |
+
f = gf_from_int_poly([1, -3, 1, -3, -1, -3, 1], 11)
|
| 532 |
+
|
| 533 |
+
Q = [[1, 0, 0, 0, 0, 0],
|
| 534 |
+
[3, 5, 8, 8, 6, 5],
|
| 535 |
+
[3, 6, 6, 1, 10, 0],
|
| 536 |
+
[9, 4, 10, 3, 7, 9],
|
| 537 |
+
[7, 8, 10, 0, 0, 8],
|
| 538 |
+
[8, 10, 7, 8, 10, 8]]
|
| 539 |
+
|
| 540 |
+
V = [[1, 0, 0, 0, 0, 0],
|
| 541 |
+
[0, 1, 1, 1, 1, 0],
|
| 542 |
+
[0, 0, 7, 9, 0, 1]]
|
| 543 |
+
|
| 544 |
+
assert gf_Qmatrix(f, 11, ZZ) == Q
|
| 545 |
+
assert gf_Qbasis(Q, 11, ZZ) == V
|
| 546 |
+
|
| 547 |
+
assert gf_berlekamp(f, 11, ZZ) == \
|
| 548 |
+
[[1, 1], [1, 5, 3], [1, 2, 3, 4]]
|
| 549 |
+
|
| 550 |
+
f = ZZ.map([1, 0, 1, 0, 10, 10, 8, 2, 8])
|
| 551 |
+
|
| 552 |
+
Q = ZZ.map([[1, 0, 0, 0, 0, 0, 0, 0],
|
| 553 |
+
[2, 1, 7, 11, 10, 12, 5, 11],
|
| 554 |
+
[3, 6, 4, 3, 0, 4, 7, 2],
|
| 555 |
+
[4, 3, 6, 5, 1, 6, 2, 3],
|
| 556 |
+
[2, 11, 8, 8, 3, 1, 3, 11],
|
| 557 |
+
[6, 11, 8, 6, 2, 7, 10, 9],
|
| 558 |
+
[5, 11, 7, 10, 0, 11, 7, 12],
|
| 559 |
+
[3, 3, 12, 5, 0, 11, 9, 12]])
|
| 560 |
+
|
| 561 |
+
V = [[1, 0, 0, 0, 0, 0, 0, 0],
|
| 562 |
+
[0, 5, 5, 0, 9, 5, 1, 0],
|
| 563 |
+
[0, 9, 11, 9, 10, 12, 0, 1]]
|
| 564 |
+
|
| 565 |
+
assert gf_Qmatrix(f, 13, ZZ) == Q
|
| 566 |
+
assert gf_Qbasis(Q, 13, ZZ) == V
|
| 567 |
+
|
| 568 |
+
assert gf_berlekamp(f, 13, ZZ) == \
|
| 569 |
+
[[1, 3], [1, 8, 4, 12], [1, 2, 3, 4, 6]]
|
| 570 |
+
|
| 571 |
+
|
| 572 |
+
def test_gf_ddf():
|
| 573 |
+
f = gf_from_dict({15: ZZ(1), 0: ZZ(-1)}, 11, ZZ)
|
| 574 |
+
g = [([1, 0, 0, 0, 0, 10], 1),
|
| 575 |
+
([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2)]
|
| 576 |
+
|
| 577 |
+
assert gf_ddf_zassenhaus(f, 11, ZZ) == g
|
| 578 |
+
assert gf_ddf_shoup(f, 11, ZZ) == g
|
| 579 |
+
|
| 580 |
+
f = gf_from_dict({63: ZZ(1), 0: ZZ(1)}, 2, ZZ)
|
| 581 |
+
g = [([1, 1], 1),
|
| 582 |
+
([1, 1, 1], 2),
|
| 583 |
+
([1, 1, 1, 1, 1, 1, 1], 3),
|
| 584 |
+
([1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0,
|
| 585 |
+
0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0,
|
| 586 |
+
0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1], 6)]
|
| 587 |
+
|
| 588 |
+
assert gf_ddf_zassenhaus(f, 2, ZZ) == g
|
| 589 |
+
assert gf_ddf_shoup(f, 2, ZZ) == g
|
| 590 |
+
|
| 591 |
+
f = gf_from_dict({6: ZZ(1), 5: ZZ(-1), 4: ZZ(1), 3: ZZ(1), 1: ZZ(-1)}, 3, ZZ)
|
| 592 |
+
g = [([1, 1, 0], 1),
|
| 593 |
+
([1, 1, 0, 1, 2], 2)]
|
| 594 |
+
|
| 595 |
+
assert gf_ddf_zassenhaus(f, 3, ZZ) == g
|
| 596 |
+
assert gf_ddf_shoup(f, 3, ZZ) == g
|
| 597 |
+
|
| 598 |
+
f = ZZ.map([1, 2, 5, 26, 677, 436, 791, 325, 456, 24, 577])
|
| 599 |
+
g = [([1, 701], 1),
|
| 600 |
+
([1, 110, 559, 532, 694, 151, 110, 70, 735, 122], 9)]
|
| 601 |
+
|
| 602 |
+
assert gf_ddf_zassenhaus(f, 809, ZZ) == g
|
| 603 |
+
assert gf_ddf_shoup(f, 809, ZZ) == g
|
| 604 |
+
|
| 605 |
+
p = ZZ(nextprime(int((2**15 * pi).evalf())))
|
| 606 |
+
f = gf_from_dict({15: 1, 1: 1, 0: 1}, p, ZZ)
|
| 607 |
+
g = [([1, 22730, 68144], 2),
|
| 608 |
+
([1, 64876, 83977, 10787, 12561, 68608, 52650, 88001, 84356], 4),
|
| 609 |
+
([1, 15347, 95022, 84569, 94508, 92335], 5)]
|
| 610 |
+
|
| 611 |
+
assert gf_ddf_zassenhaus(f, p, ZZ) == g
|
| 612 |
+
assert gf_ddf_shoup(f, p, ZZ) == g
|
| 613 |
+
|
| 614 |
+
|
| 615 |
+
def test_gf_edf():
|
| 616 |
+
f = ZZ.map([1, 1, 0, 1, 2])
|
| 617 |
+
g = ZZ.map([[1, 0, 1], [1, 1, 2]])
|
| 618 |
+
|
| 619 |
+
assert gf_edf_zassenhaus(f, 2, 3, ZZ) == g
|
| 620 |
+
assert gf_edf_shoup(f, 2, 3, ZZ) == g
|
| 621 |
+
|
| 622 |
+
|
| 623 |
+
def test_issue_23174():
|
| 624 |
+
f = ZZ.map([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
|
| 625 |
+
g = ZZ.map([[1, 0, 0, 1, 1, 1, 0, 0, 1], [1, 1, 1, 0, 1, 0, 1, 1, 1]])
|
| 626 |
+
|
| 627 |
+
assert gf_edf_zassenhaus(f, 8, 2, ZZ) == g
|
| 628 |
+
|
| 629 |
+
|
| 630 |
+
def test_gf_factor():
|
| 631 |
+
assert gf_factor([], 11, ZZ) == (0, [])
|
| 632 |
+
assert gf_factor([1], 11, ZZ) == (1, [])
|
| 633 |
+
assert gf_factor([1, 1], 11, ZZ) == (1, [([1, 1], 1)])
|
| 634 |
+
|
| 635 |
+
assert gf_factor_sqf([], 11, ZZ) == (0, [])
|
| 636 |
+
assert gf_factor_sqf([1], 11, ZZ) == (1, [])
|
| 637 |
+
assert gf_factor_sqf([1, 1], 11, ZZ) == (1, [[1, 1]])
|
| 638 |
+
|
| 639 |
+
config.setup('GF_FACTOR_METHOD', 'berlekamp')
|
| 640 |
+
|
| 641 |
+
assert gf_factor_sqf([], 11, ZZ) == (0, [])
|
| 642 |
+
assert gf_factor_sqf([1], 11, ZZ) == (1, [])
|
| 643 |
+
assert gf_factor_sqf([1, 1], 11, ZZ) == (1, [[1, 1]])
|
| 644 |
+
|
| 645 |
+
config.setup('GF_FACTOR_METHOD', 'zassenhaus')
|
| 646 |
+
|
| 647 |
+
assert gf_factor_sqf([], 11, ZZ) == (0, [])
|
| 648 |
+
assert gf_factor_sqf([1], 11, ZZ) == (1, [])
|
| 649 |
+
assert gf_factor_sqf([1, 1], 11, ZZ) == (1, [[1, 1]])
|
| 650 |
+
|
| 651 |
+
config.setup('GF_FACTOR_METHOD', 'shoup')
|
| 652 |
+
|
| 653 |
+
assert gf_factor_sqf(ZZ.map([]), 11, ZZ) == (0, [])
|
| 654 |
+
assert gf_factor_sqf(ZZ.map([1]), 11, ZZ) == (1, [])
|
| 655 |
+
assert gf_factor_sqf(ZZ.map([1, 1]), 11, ZZ) == (1, [[1, 1]])
|
| 656 |
+
|
| 657 |
+
f, p = ZZ.map([1, 0, 0, 1, 0]), 2
|
| 658 |
+
|
| 659 |
+
g = (1, [([1, 0], 1),
|
| 660 |
+
([1, 1], 1),
|
| 661 |
+
([1, 1, 1], 1)])
|
| 662 |
+
|
| 663 |
+
config.setup('GF_FACTOR_METHOD', 'berlekamp')
|
| 664 |
+
assert gf_factor(f, p, ZZ) == g
|
| 665 |
+
|
| 666 |
+
config.setup('GF_FACTOR_METHOD', 'zassenhaus')
|
| 667 |
+
assert gf_factor(f, p, ZZ) == g
|
| 668 |
+
|
| 669 |
+
config.setup('GF_FACTOR_METHOD', 'shoup')
|
| 670 |
+
assert gf_factor(f, p, ZZ) == g
|
| 671 |
+
|
| 672 |
+
g = (1, [[1, 0],
|
| 673 |
+
[1, 1],
|
| 674 |
+
[1, 1, 1]])
|
| 675 |
+
|
| 676 |
+
config.setup('GF_FACTOR_METHOD', 'berlekamp')
|
| 677 |
+
assert gf_factor_sqf(f, p, ZZ) == g
|
| 678 |
+
|
| 679 |
+
config.setup('GF_FACTOR_METHOD', 'zassenhaus')
|
| 680 |
+
assert gf_factor_sqf(f, p, ZZ) == g
|
| 681 |
+
|
| 682 |
+
config.setup('GF_FACTOR_METHOD', 'shoup')
|
| 683 |
+
assert gf_factor_sqf(f, p, ZZ) == g
|
| 684 |
+
|
| 685 |
+
f, p = gf_from_int_poly([1, -3, 1, -3, -1, -3, 1], 11), 11
|
| 686 |
+
|
| 687 |
+
g = (1, [([1, 1], 1),
|
| 688 |
+
([1, 5, 3], 1),
|
| 689 |
+
([1, 2, 3, 4], 1)])
|
| 690 |
+
|
| 691 |
+
config.setup('GF_FACTOR_METHOD', 'berlekamp')
|
| 692 |
+
assert gf_factor(f, p, ZZ) == g
|
| 693 |
+
|
| 694 |
+
config.setup('GF_FACTOR_METHOD', 'zassenhaus')
|
| 695 |
+
assert gf_factor(f, p, ZZ) == g
|
| 696 |
+
|
| 697 |
+
config.setup('GF_FACTOR_METHOD', 'shoup')
|
| 698 |
+
assert gf_factor(f, p, ZZ) == g
|
| 699 |
+
|
| 700 |
+
f, p = [1, 5, 8, 4], 11
|
| 701 |
+
|
| 702 |
+
g = (1, [([1, 1], 1), ([1, 2], 2)])
|
| 703 |
+
|
| 704 |
+
config.setup('GF_FACTOR_METHOD', 'berlekamp')
|
| 705 |
+
assert gf_factor(f, p, ZZ) == g
|
| 706 |
+
|
| 707 |
+
config.setup('GF_FACTOR_METHOD', 'zassenhaus')
|
| 708 |
+
assert gf_factor(f, p, ZZ) == g
|
| 709 |
+
|
| 710 |
+
config.setup('GF_FACTOR_METHOD', 'shoup')
|
| 711 |
+
assert gf_factor(f, p, ZZ) == g
|
| 712 |
+
|
| 713 |
+
f, p = [1, 1, 10, 1, 0, 10, 10, 10, 0, 0], 11
|
| 714 |
+
|
| 715 |
+
g = (1, [([1, 0], 2), ([1, 9, 5], 1), ([1, 3, 0, 8, 5, 2], 1)])
|
| 716 |
+
|
| 717 |
+
config.setup('GF_FACTOR_METHOD', 'berlekamp')
|
| 718 |
+
assert gf_factor(f, p, ZZ) == g
|
| 719 |
+
|
| 720 |
+
config.setup('GF_FACTOR_METHOD', 'zassenhaus')
|
| 721 |
+
assert gf_factor(f, p, ZZ) == g
|
| 722 |
+
|
| 723 |
+
config.setup('GF_FACTOR_METHOD', 'shoup')
|
| 724 |
+
assert gf_factor(f, p, ZZ) == g
|
| 725 |
+
|
| 726 |
+
f, p = gf_from_dict({32: 1, 0: 1}, 11, ZZ), 11
|
| 727 |
+
|
| 728 |
+
g = (1, [([1, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 10], 1),
|
| 729 |
+
([1, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 10], 1)])
|
| 730 |
+
|
| 731 |
+
config.setup('GF_FACTOR_METHOD', 'berlekamp')
|
| 732 |
+
assert gf_factor(f, p, ZZ) == g
|
| 733 |
+
|
| 734 |
+
config.setup('GF_FACTOR_METHOD', 'zassenhaus')
|
| 735 |
+
assert gf_factor(f, p, ZZ) == g
|
| 736 |
+
|
| 737 |
+
config.setup('GF_FACTOR_METHOD', 'shoup')
|
| 738 |
+
assert gf_factor(f, p, ZZ) == g
|
| 739 |
+
|
| 740 |
+
f, p = gf_from_dict({32: ZZ(8), 0: ZZ(5)}, 11, ZZ), 11
|
| 741 |
+
|
| 742 |
+
g = (8, [([1, 3], 1),
|
| 743 |
+
([1, 8], 1),
|
| 744 |
+
([1, 0, 9], 1),
|
| 745 |
+
([1, 2, 2], 1),
|
| 746 |
+
([1, 9, 2], 1),
|
| 747 |
+
([1, 0, 5, 0, 7], 1),
|
| 748 |
+
([1, 0, 6, 0, 7], 1),
|
| 749 |
+
([1, 0, 0, 0, 1, 0, 0, 0, 6], 1),
|
| 750 |
+
([1, 0, 0, 0, 10, 0, 0, 0, 6], 1)])
|
| 751 |
+
|
| 752 |
+
config.setup('GF_FACTOR_METHOD', 'berlekamp')
|
| 753 |
+
assert gf_factor(f, p, ZZ) == g
|
| 754 |
+
|
| 755 |
+
config.setup('GF_FACTOR_METHOD', 'zassenhaus')
|
| 756 |
+
assert gf_factor(f, p, ZZ) == g
|
| 757 |
+
|
| 758 |
+
config.setup('GF_FACTOR_METHOD', 'shoup')
|
| 759 |
+
assert gf_factor(f, p, ZZ) == g
|
| 760 |
+
|
| 761 |
+
f, p = gf_from_dict({63: ZZ(8), 0: ZZ(5)}, 11, ZZ), 11
|
| 762 |
+
|
| 763 |
+
g = (8, [([1, 7], 1),
|
| 764 |
+
([1, 4, 5], 1),
|
| 765 |
+
([1, 6, 8, 2], 1),
|
| 766 |
+
([1, 9, 9, 2], 1),
|
| 767 |
+
([1, 0, 0, 9, 0, 0, 4], 1),
|
| 768 |
+
([1, 2, 0, 8, 4, 6, 4], 1),
|
| 769 |
+
([1, 2, 3, 8, 0, 6, 4], 1),
|
| 770 |
+
([1, 2, 6, 0, 8, 4, 4], 1),
|
| 771 |
+
([1, 3, 3, 1, 6, 8, 4], 1),
|
| 772 |
+
([1, 5, 6, 0, 8, 6, 4], 1),
|
| 773 |
+
([1, 6, 2, 7, 9, 8, 4], 1),
|
| 774 |
+
([1, 10, 4, 7, 10, 7, 4], 1),
|
| 775 |
+
([1, 10, 10, 1, 4, 9, 4], 1)])
|
| 776 |
+
|
| 777 |
+
config.setup('GF_FACTOR_METHOD', 'berlekamp')
|
| 778 |
+
assert gf_factor(f, p, ZZ) == g
|
| 779 |
+
|
| 780 |
+
config.setup('GF_FACTOR_METHOD', 'zassenhaus')
|
| 781 |
+
assert gf_factor(f, p, ZZ) == g
|
| 782 |
+
|
| 783 |
+
config.setup('GF_FACTOR_METHOD', 'shoup')
|
| 784 |
+
assert gf_factor(f, p, ZZ) == g
|
| 785 |
+
|
| 786 |
+
# Gathen polynomials: x**n + x + 1 (mod p > 2**n * pi)
|
| 787 |
+
|
| 788 |
+
p = ZZ(nextprime(int((2**15 * pi).evalf())))
|
| 789 |
+
f = gf_from_dict({15: 1, 1: 1, 0: 1}, p, ZZ)
|
| 790 |
+
|
| 791 |
+
assert gf_sqf_p(f, p, ZZ) is True
|
| 792 |
+
|
| 793 |
+
g = (1, [([1, 22730, 68144], 1),
|
| 794 |
+
([1, 81553, 77449, 86810, 4724], 1),
|
| 795 |
+
([1, 86276, 56779, 14859, 31575], 1),
|
| 796 |
+
([1, 15347, 95022, 84569, 94508, 92335], 1)])
|
| 797 |
+
|
| 798 |
+
config.setup('GF_FACTOR_METHOD', 'zassenhaus')
|
| 799 |
+
assert gf_factor(f, p, ZZ) == g
|
| 800 |
+
|
| 801 |
+
config.setup('GF_FACTOR_METHOD', 'shoup')
|
| 802 |
+
assert gf_factor(f, p, ZZ) == g
|
| 803 |
+
|
| 804 |
+
g = (1, [[1, 22730, 68144],
|
| 805 |
+
[1, 81553, 77449, 86810, 4724],
|
| 806 |
+
[1, 86276, 56779, 14859, 31575],
|
| 807 |
+
[1, 15347, 95022, 84569, 94508, 92335]])
|
| 808 |
+
|
| 809 |
+
config.setup('GF_FACTOR_METHOD', 'zassenhaus')
|
| 810 |
+
assert gf_factor_sqf(f, p, ZZ) == g
|
| 811 |
+
|
| 812 |
+
config.setup('GF_FACTOR_METHOD', 'shoup')
|
| 813 |
+
assert gf_factor_sqf(f, p, ZZ) == g
|
| 814 |
+
|
| 815 |
+
# Shoup polynomials: f = a_0 x**n + a_1 x**(n-1) + ... + a_n
|
| 816 |
+
# (mod p > 2**(n-2) * pi), where a_n = a_{n-1}**2 + 1, a_0 = 1
|
| 817 |
+
|
| 818 |
+
p = ZZ(nextprime(int((2**4 * pi).evalf())))
|
| 819 |
+
f = ZZ.map([1, 2, 5, 26, 41, 39, 38])
|
| 820 |
+
|
| 821 |
+
assert gf_sqf_p(f, p, ZZ) is True
|
| 822 |
+
|
| 823 |
+
g = (1, [([1, 44, 26], 1),
|
| 824 |
+
([1, 11, 25, 18, 30], 1)])
|
| 825 |
+
|
| 826 |
+
config.setup('GF_FACTOR_METHOD', 'zassenhaus')
|
| 827 |
+
assert gf_factor(f, p, ZZ) == g
|
| 828 |
+
|
| 829 |
+
config.setup('GF_FACTOR_METHOD', 'shoup')
|
| 830 |
+
assert gf_factor(f, p, ZZ) == g
|
| 831 |
+
|
| 832 |
+
g = (1, [[1, 44, 26],
|
| 833 |
+
[1, 11, 25, 18, 30]])
|
| 834 |
+
|
| 835 |
+
config.setup('GF_FACTOR_METHOD', 'zassenhaus')
|
| 836 |
+
assert gf_factor_sqf(f, p, ZZ) == g
|
| 837 |
+
|
| 838 |
+
config.setup('GF_FACTOR_METHOD', 'shoup')
|
| 839 |
+
assert gf_factor_sqf(f, p, ZZ) == g
|
| 840 |
+
|
| 841 |
+
config.setup('GF_FACTOR_METHOD', 'other')
|
| 842 |
+
raises(KeyError, lambda: gf_factor([1, 1], 11, ZZ))
|
| 843 |
+
config.setup('GF_FACTOR_METHOD')
|
| 844 |
+
|
| 845 |
+
|
| 846 |
+
def test_gf_csolve():
|
| 847 |
+
assert gf_value([1, 7, 2, 4], 11) == 2204
|
| 848 |
+
|
| 849 |
+
assert linear_congruence(4, 3, 5) == [2]
|
| 850 |
+
assert linear_congruence(0, 3, 5) == []
|
| 851 |
+
assert linear_congruence(6, 1, 4) == []
|
| 852 |
+
assert linear_congruence(0, 5, 5) == [0, 1, 2, 3, 4]
|
| 853 |
+
assert linear_congruence(3, 12, 15) == [4, 9, 14]
|
| 854 |
+
assert linear_congruence(6, 0, 18) == [0, 3, 6, 9, 12, 15]
|
| 855 |
+
# _csolve_prime_las_vegas
|
| 856 |
+
assert _csolve_prime_las_vegas([2, 3, 1], 5) == [2, 4]
|
| 857 |
+
assert _csolve_prime_las_vegas([2, 0, 1], 5) == []
|
| 858 |
+
from sympy.ntheory import primerange
|
| 859 |
+
for p in primerange(2, 100):
|
| 860 |
+
# f = x**(p-1) - 1
|
| 861 |
+
f = gf_sub_ground(gf_pow([1, 0], p - 1, p, ZZ), 1, p, ZZ)
|
| 862 |
+
assert _csolve_prime_las_vegas(f, p) == list(range(1, p))
|
| 863 |
+
# with power = 1
|
| 864 |
+
assert csolve_prime([1, 3, 2, 17], 7) == [3]
|
| 865 |
+
assert csolve_prime([1, 3, 1, 5], 5) == [0, 1]
|
| 866 |
+
assert csolve_prime([3, 6, 9, 3], 3) == [0, 1, 2]
|
| 867 |
+
# with power > 1
|
| 868 |
+
assert csolve_prime(
|
| 869 |
+
[1, 1, 223], 3, 4) == [4, 13, 22, 31, 40, 49, 58, 67, 76]
|
| 870 |
+
assert csolve_prime([3, 5, 2, 25], 5, 3) == [16, 50, 99]
|
| 871 |
+
assert csolve_prime([3, 2, 2, 49], 7, 3) == [147, 190, 234]
|
| 872 |
+
|
| 873 |
+
assert gf_csolve([1, 1, 7], 189) == [13, 49, 76, 112, 139, 175]
|
| 874 |
+
assert gf_csolve([1, 3, 4, 1, 30], 60) == [10, 30]
|
| 875 |
+
assert gf_csolve([1, 1, 7], 15) == []
|
pllava/lib/python3.10/site-packages/sympy/polys/tests/test_groebnertools.py
ADDED
|
@@ -0,0 +1,533 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for Groebner bases. """
|
| 2 |
+
|
| 3 |
+
from sympy.polys.groebnertools import (
|
| 4 |
+
groebner, sig, sig_key,
|
| 5 |
+
lbp, lbp_key, critical_pair,
|
| 6 |
+
cp_key, is_rewritable_or_comparable,
|
| 7 |
+
Sign, Polyn, Num, s_poly, f5_reduce,
|
| 8 |
+
groebner_lcm, groebner_gcd, is_groebner,
|
| 9 |
+
is_reduced
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
from sympy.polys.fglmtools import _representing_matrices
|
| 13 |
+
from sympy.polys.orderings import lex, grlex
|
| 14 |
+
|
| 15 |
+
from sympy.polys.rings import ring, xring
|
| 16 |
+
from sympy.polys.domains import ZZ, QQ
|
| 17 |
+
|
| 18 |
+
from sympy.testing.pytest import slow
|
| 19 |
+
from sympy.polys import polyconfig as config
|
| 20 |
+
|
| 21 |
+
def _do_test_groebner():
|
| 22 |
+
R, x,y = ring("x,y", QQ, lex)
|
| 23 |
+
f = x**2 + 2*x*y**2
|
| 24 |
+
g = x*y + 2*y**3 - 1
|
| 25 |
+
|
| 26 |
+
assert groebner([f, g], R) == [x, y**3 - QQ(1,2)]
|
| 27 |
+
|
| 28 |
+
R, y,x = ring("y,x", QQ, lex)
|
| 29 |
+
f = 2*x**2*y + y**2
|
| 30 |
+
g = 2*x**3 + x*y - 1
|
| 31 |
+
|
| 32 |
+
assert groebner([f, g], R) == [y, x**3 - QQ(1,2)]
|
| 33 |
+
|
| 34 |
+
R, x,y,z = ring("x,y,z", QQ, lex)
|
| 35 |
+
f = x - z**2
|
| 36 |
+
g = y - z**3
|
| 37 |
+
|
| 38 |
+
assert groebner([f, g], R) == [f, g]
|
| 39 |
+
|
| 40 |
+
R, x,y = ring("x,y", QQ, grlex)
|
| 41 |
+
f = x**3 - 2*x*y
|
| 42 |
+
g = x**2*y + x - 2*y**2
|
| 43 |
+
|
| 44 |
+
assert groebner([f, g], R) == [x**2, x*y, -QQ(1,2)*x + y**2]
|
| 45 |
+
|
| 46 |
+
R, x,y,z = ring("x,y,z", QQ, lex)
|
| 47 |
+
f = -x**2 + y
|
| 48 |
+
g = -x**3 + z
|
| 49 |
+
|
| 50 |
+
assert groebner([f, g], R) == [x**2 - y, x*y - z, x*z - y**2, y**3 - z**2]
|
| 51 |
+
|
| 52 |
+
R, x,y,z = ring("x,y,z", QQ, grlex)
|
| 53 |
+
f = -x**2 + y
|
| 54 |
+
g = -x**3 + z
|
| 55 |
+
|
| 56 |
+
assert groebner([f, g], R) == [y**3 - z**2, x**2 - y, x*y - z, x*z - y**2]
|
| 57 |
+
|
| 58 |
+
R, x,y,z = ring("x,y,z", QQ, lex)
|
| 59 |
+
f = -x**2 + z
|
| 60 |
+
g = -x**3 + y
|
| 61 |
+
|
| 62 |
+
assert groebner([f, g], R) == [x**2 - z, x*y - z**2, x*z - y, y**2 - z**3]
|
| 63 |
+
|
| 64 |
+
R, x,y,z = ring("x,y,z", QQ, grlex)
|
| 65 |
+
f = -x**2 + z
|
| 66 |
+
g = -x**3 + y
|
| 67 |
+
|
| 68 |
+
assert groebner([f, g], R) == [-y**2 + z**3, x**2 - z, x*y - z**2, x*z - y]
|
| 69 |
+
|
| 70 |
+
R, x,y,z = ring("x,y,z", QQ, lex)
|
| 71 |
+
f = x - y**2
|
| 72 |
+
g = -y**3 + z
|
| 73 |
+
|
| 74 |
+
assert groebner([f, g], R) == [x - y**2, y**3 - z]
|
| 75 |
+
|
| 76 |
+
R, x,y,z = ring("x,y,z", QQ, grlex)
|
| 77 |
+
f = x - y**2
|
| 78 |
+
g = -y**3 + z
|
| 79 |
+
|
| 80 |
+
assert groebner([f, g], R) == [x**2 - y*z, x*y - z, -x + y**2]
|
| 81 |
+
|
| 82 |
+
R, x,y,z = ring("x,y,z", QQ, lex)
|
| 83 |
+
f = x - z**2
|
| 84 |
+
g = y - z**3
|
| 85 |
+
|
| 86 |
+
assert groebner([f, g], R) == [x - z**2, y - z**3]
|
| 87 |
+
|
| 88 |
+
R, x,y,z = ring("x,y,z", QQ, grlex)
|
| 89 |
+
f = x - z**2
|
| 90 |
+
g = y - z**3
|
| 91 |
+
|
| 92 |
+
assert groebner([f, g], R) == [x**2 - y*z, x*z - y, -x + z**2]
|
| 93 |
+
|
| 94 |
+
R, x,y,z = ring("x,y,z", QQ, lex)
|
| 95 |
+
f = -y**2 + z
|
| 96 |
+
g = x - y**3
|
| 97 |
+
|
| 98 |
+
assert groebner([f, g], R) == [x - y*z, y**2 - z]
|
| 99 |
+
|
| 100 |
+
R, x,y,z = ring("x,y,z", QQ, grlex)
|
| 101 |
+
f = -y**2 + z
|
| 102 |
+
g = x - y**3
|
| 103 |
+
|
| 104 |
+
assert groebner([f, g], R) == [-x**2 + z**3, x*y - z**2, y**2 - z, -x + y*z]
|
| 105 |
+
|
| 106 |
+
R, x,y,z = ring("x,y,z", QQ, lex)
|
| 107 |
+
f = y - z**2
|
| 108 |
+
g = x - z**3
|
| 109 |
+
|
| 110 |
+
assert groebner([f, g], R) == [x - z**3, y - z**2]
|
| 111 |
+
|
| 112 |
+
R, x,y,z = ring("x,y,z", QQ, grlex)
|
| 113 |
+
f = y - z**2
|
| 114 |
+
g = x - z**3
|
| 115 |
+
|
| 116 |
+
assert groebner([f, g], R) == [-x**2 + y**3, x*z - y**2, -x + y*z, -y + z**2]
|
| 117 |
+
|
| 118 |
+
R, x,y,z = ring("x,y,z", QQ, lex)
|
| 119 |
+
f = 4*x**2*y**2 + 4*x*y + 1
|
| 120 |
+
g = x**2 + y**2 - 1
|
| 121 |
+
|
| 122 |
+
assert groebner([f, g], R) == [
|
| 123 |
+
x - 4*y**7 + 8*y**5 - 7*y**3 + 3*y,
|
| 124 |
+
y**8 - 2*y**6 + QQ(3,2)*y**4 - QQ(1,2)*y**2 + QQ(1,16),
|
| 125 |
+
]
|
| 126 |
+
|
| 127 |
+
def test_groebner_buchberger():
|
| 128 |
+
with config.using(groebner='buchberger'):
|
| 129 |
+
_do_test_groebner()
|
| 130 |
+
|
| 131 |
+
def test_groebner_f5b():
|
| 132 |
+
with config.using(groebner='f5b'):
|
| 133 |
+
_do_test_groebner()
|
| 134 |
+
|
| 135 |
+
def _do_test_benchmark_minpoly():
|
| 136 |
+
R, x,y,z = ring("x,y,z", QQ, lex)
|
| 137 |
+
|
| 138 |
+
F = [x**3 + x + 1, y**2 + y + 1, (x + y) * z - (x**2 + y)]
|
| 139 |
+
G = [x + QQ(155,2067)*z**5 - QQ(355,689)*z**4 + QQ(6062,2067)*z**3 - QQ(3687,689)*z**2 + QQ(6878,2067)*z - QQ(25,53),
|
| 140 |
+
y + QQ(4,53)*z**5 - QQ(91,159)*z**4 + QQ(523,159)*z**3 - QQ(387,53)*z**2 + QQ(1043,159)*z - QQ(308,159),
|
| 141 |
+
z**6 - 7*z**5 + 41*z**4 - 82*z**3 + 89*z**2 - 46*z + 13]
|
| 142 |
+
|
| 143 |
+
assert groebner(F, R) == G
|
| 144 |
+
|
| 145 |
+
def test_benchmark_minpoly_buchberger():
|
| 146 |
+
with config.using(groebner='buchberger'):
|
| 147 |
+
_do_test_benchmark_minpoly()
|
| 148 |
+
|
| 149 |
+
def test_benchmark_minpoly_f5b():
|
| 150 |
+
with config.using(groebner='f5b'):
|
| 151 |
+
_do_test_benchmark_minpoly()
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
def test_benchmark_coloring():
|
| 155 |
+
V = range(1, 12 + 1)
|
| 156 |
+
E = [(1, 2), (2, 3), (1, 4), (1, 6), (1, 12), (2, 5), (2, 7), (3, 8), (3, 10),
|
| 157 |
+
(4, 11), (4, 9), (5, 6), (6, 7), (7, 8), (8, 9), (9, 10), (10, 11),
|
| 158 |
+
(11, 12), (5, 12), (5, 9), (6, 10), (7, 11), (8, 12), (3, 4)]
|
| 159 |
+
|
| 160 |
+
R, V = xring([ "x%d" % v for v in V ], QQ, lex)
|
| 161 |
+
E = [(V[i - 1], V[j - 1]) for i, j in E]
|
| 162 |
+
|
| 163 |
+
x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12 = V
|
| 164 |
+
|
| 165 |
+
I3 = [x**3 - 1 for x in V]
|
| 166 |
+
Ig = [x**2 + x*y + y**2 for x, y in E]
|
| 167 |
+
|
| 168 |
+
I = I3 + Ig
|
| 169 |
+
|
| 170 |
+
assert groebner(I[:-1], R) == [
|
| 171 |
+
x1 + x11 + x12,
|
| 172 |
+
x2 - x11,
|
| 173 |
+
x3 - x12,
|
| 174 |
+
x4 - x12,
|
| 175 |
+
x5 + x11 + x12,
|
| 176 |
+
x6 - x11,
|
| 177 |
+
x7 - x12,
|
| 178 |
+
x8 + x11 + x12,
|
| 179 |
+
x9 - x11,
|
| 180 |
+
x10 + x11 + x12,
|
| 181 |
+
x11**2 + x11*x12 + x12**2,
|
| 182 |
+
x12**3 - 1,
|
| 183 |
+
]
|
| 184 |
+
|
| 185 |
+
assert groebner(I, R) == [1]
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
def _do_test_benchmark_katsura_3():
|
| 189 |
+
R, x0,x1,x2 = ring("x:3", ZZ, lex)
|
| 190 |
+
I = [x0 + 2*x1 + 2*x2 - 1,
|
| 191 |
+
x0**2 + 2*x1**2 + 2*x2**2 - x0,
|
| 192 |
+
2*x0*x1 + 2*x1*x2 - x1]
|
| 193 |
+
|
| 194 |
+
assert groebner(I, R) == [
|
| 195 |
+
-7 + 7*x0 + 8*x2 + 158*x2**2 - 420*x2**3,
|
| 196 |
+
7*x1 + 3*x2 - 79*x2**2 + 210*x2**3,
|
| 197 |
+
x2 + x2**2 - 40*x2**3 + 84*x2**4,
|
| 198 |
+
]
|
| 199 |
+
|
| 200 |
+
R, x0,x1,x2 = ring("x:3", ZZ, grlex)
|
| 201 |
+
I = [ i.set_ring(R) for i in I ]
|
| 202 |
+
|
| 203 |
+
assert groebner(I, R) == [
|
| 204 |
+
7*x1 + 3*x2 - 79*x2**2 + 210*x2**3,
|
| 205 |
+
-x1 + x2 - 3*x2**2 + 5*x1**2,
|
| 206 |
+
-x1 - 4*x2 + 10*x1*x2 + 12*x2**2,
|
| 207 |
+
-1 + x0 + 2*x1 + 2*x2,
|
| 208 |
+
]
|
| 209 |
+
|
| 210 |
+
def test_benchmark_katsura3_buchberger():
|
| 211 |
+
with config.using(groebner='buchberger'):
|
| 212 |
+
_do_test_benchmark_katsura_3()
|
| 213 |
+
|
| 214 |
+
def test_benchmark_katsura3_f5b():
|
| 215 |
+
with config.using(groebner='f5b'):
|
| 216 |
+
_do_test_benchmark_katsura_3()
|
| 217 |
+
|
| 218 |
+
def _do_test_benchmark_katsura_4():
|
| 219 |
+
R, x0,x1,x2,x3 = ring("x:4", ZZ, lex)
|
| 220 |
+
I = [x0 + 2*x1 + 2*x2 + 2*x3 - 1,
|
| 221 |
+
x0**2 + 2*x1**2 + 2*x2**2 + 2*x3**2 - x0,
|
| 222 |
+
2*x0*x1 + 2*x1*x2 + 2*x2*x3 - x1,
|
| 223 |
+
x1**2 + 2*x0*x2 + 2*x1*x3 - x2]
|
| 224 |
+
|
| 225 |
+
assert groebner(I, R) == [
|
| 226 |
+
5913075*x0 - 159690237696*x3**7 + 31246269696*x3**6 + 27439610544*x3**5 - 6475723368*x3**4 - 838935856*x3**3 + 275119624*x3**2 + 4884038*x3 - 5913075,
|
| 227 |
+
1971025*x1 - 97197721632*x3**7 + 73975630752*x3**6 - 12121915032*x3**5 - 2760941496*x3**4 + 814792828*x3**3 - 1678512*x3**2 - 9158924*x3,
|
| 228 |
+
5913075*x2 + 371438283744*x3**7 - 237550027104*x3**6 + 22645939824*x3**5 + 11520686172*x3**4 - 2024910556*x3**3 - 132524276*x3**2 + 30947828*x3,
|
| 229 |
+
128304*x3**8 - 93312*x3**7 + 15552*x3**6 + 3144*x3**5 -
|
| 230 |
+
1120*x3**4 + 36*x3**3 + 15*x3**2 - x3,
|
| 231 |
+
]
|
| 232 |
+
|
| 233 |
+
R, x0,x1,x2,x3 = ring("x:4", ZZ, grlex)
|
| 234 |
+
I = [ i.set_ring(R) for i in I ]
|
| 235 |
+
|
| 236 |
+
assert groebner(I, R) == [
|
| 237 |
+
393*x1 - 4662*x2**2 + 4462*x2*x3 - 59*x2 + 224532*x3**4 - 91224*x3**3 - 678*x3**2 + 2046*x3,
|
| 238 |
+
-x1 + 196*x2**3 - 21*x2**2 + 60*x2*x3 - 18*x2 - 168*x3**3 + 83*x3**2 - 9*x3,
|
| 239 |
+
-6*x1 + 1134*x2**2*x3 - 189*x2**2 - 466*x2*x3 + 32*x2 - 630*x3**3 + 57*x3**2 + 51*x3,
|
| 240 |
+
33*x1 + 63*x2**2 + 2268*x2*x3**2 - 188*x2*x3 + 34*x2 + 2520*x3**3 - 849*x3**2 + 3*x3,
|
| 241 |
+
7*x1**2 - x1 - 7*x2**2 - 24*x2*x3 + 3*x2 - 15*x3**2 + 5*x3,
|
| 242 |
+
14*x1*x2 - x1 + 14*x2**2 + 18*x2*x3 - 4*x2 + 6*x3**2 - 2*x3,
|
| 243 |
+
14*x1*x3 - x1 + 7*x2**2 + 32*x2*x3 - 4*x2 + 27*x3**2 - 9*x3,
|
| 244 |
+
x0 + 2*x1 + 2*x2 + 2*x3 - 1,
|
| 245 |
+
]
|
| 246 |
+
|
| 247 |
+
def test_benchmark_kastura_4_buchberger():
|
| 248 |
+
with config.using(groebner='buchberger'):
|
| 249 |
+
_do_test_benchmark_katsura_4()
|
| 250 |
+
|
| 251 |
+
def test_benchmark_kastura_4_f5b():
|
| 252 |
+
with config.using(groebner='f5b'):
|
| 253 |
+
_do_test_benchmark_katsura_4()
|
| 254 |
+
|
| 255 |
+
def _do_test_benchmark_czichowski():
|
| 256 |
+
R, x,t = ring("x,t", ZZ, lex)
|
| 257 |
+
I = [9*x**8 + 36*x**7 - 32*x**6 - 252*x**5 - 78*x**4 + 468*x**3 + 288*x**2 - 108*x + 9,
|
| 258 |
+
(-72 - 72*t)*x**7 + (-256 - 252*t)*x**6 + (192 + 192*t)*x**5 + (1280 + 1260*t)*x**4 + (312 + 312*t)*x**3 + (-404*t)*x**2 + (-576 - 576*t)*x + 96 + 108*t]
|
| 259 |
+
|
| 260 |
+
assert groebner(I, R) == [
|
| 261 |
+
3725588592068034903797967297424801242396746870413359539263038139343329273586196480000*x -
|
| 262 |
+
160420835591776763325581422211936558925462474417709511019228211783493866564923546661604487873*t**7 -
|
| 263 |
+
1406108495478033395547109582678806497509499966197028487131115097902188374051595011248311352864*t**6 -
|
| 264 |
+
5241326875850889518164640374668786338033653548841427557880599579174438246266263602956254030352*t**5 -
|
| 265 |
+
10758917262823299139373269714910672770004760114329943852726887632013485035262879510837043892416*t**4 -
|
| 266 |
+
13119383576444715672578819534846747735372132018341964647712009275306635391456880068261130581248*t**3 -
|
| 267 |
+
9491412317016197146080450036267011389660653495578680036574753839055748080962214787557853941760*t**2 -
|
| 268 |
+
3767520915562795326943800040277726397326609797172964377014046018280260848046603967211258368000*t -
|
| 269 |
+
632314652371226552085897259159210286886724229880266931574701654721512325555116066073245696000,
|
| 270 |
+
610733380717522355121*t**8 +
|
| 271 |
+
6243748742141230639968*t**7 +
|
| 272 |
+
27761407182086143225024*t**6 +
|
| 273 |
+
70066148869420956398592*t**5 +
|
| 274 |
+
109701225644313784229376*t**4 +
|
| 275 |
+
109009005495588442152960*t**3 +
|
| 276 |
+
67072101084384786432000*t**2 +
|
| 277 |
+
23339979742629593088000*t +
|
| 278 |
+
3513592776846090240000,
|
| 279 |
+
]
|
| 280 |
+
|
| 281 |
+
R, x,t = ring("x,t", ZZ, grlex)
|
| 282 |
+
I = [ i.set_ring(R) for i in I ]
|
| 283 |
+
|
| 284 |
+
assert groebner(I, R) == [
|
| 285 |
+
16996618586000601590732959134095643086442*t**3*x -
|
| 286 |
+
32936701459297092865176560282688198064839*t**3 +
|
| 287 |
+
78592411049800639484139414821529525782364*t**2*x -
|
| 288 |
+
120753953358671750165454009478961405619916*t**2 +
|
| 289 |
+
120988399875140799712152158915653654637280*t*x -
|
| 290 |
+
144576390266626470824138354942076045758736*t +
|
| 291 |
+
60017634054270480831259316163620768960*x**2 +
|
| 292 |
+
61976058033571109604821862786675242894400*x -
|
| 293 |
+
56266268491293858791834120380427754600960,
|
| 294 |
+
576689018321912327136790519059646508441672750656050290242749*t**4 +
|
| 295 |
+
2326673103677477425562248201573604572527893938459296513327336*t**3 +
|
| 296 |
+
110743790416688497407826310048520299245819959064297990236000*t**2*x +
|
| 297 |
+
3308669114229100853338245486174247752683277925010505284338016*t**2 +
|
| 298 |
+
323150205645687941261103426627818874426097912639158572428800*t*x +
|
| 299 |
+
1914335199925152083917206349978534224695445819017286960055680*t +
|
| 300 |
+
861662882561803377986838989464278045397192862768588480000*x**2 +
|
| 301 |
+
235296483281783440197069672204341465480107019878814196672000*x +
|
| 302 |
+
361850798943225141738895123621685122544503614946436727532800,
|
| 303 |
+
-117584925286448670474763406733005510014188341867*t**3 +
|
| 304 |
+
68566565876066068463853874568722190223721653044*t**2*x -
|
| 305 |
+
435970731348366266878180788833437896139920683940*t**2 +
|
| 306 |
+
196297602447033751918195568051376792491869233408*t*x -
|
| 307 |
+
525011527660010557871349062870980202067479780112*t +
|
| 308 |
+
517905853447200553360289634770487684447317120*x**3 +
|
| 309 |
+
569119014870778921949288951688799397569321920*x**2 +
|
| 310 |
+
138877356748142786670127389526667463202210102080*x -
|
| 311 |
+
205109210539096046121625447192779783475018619520,
|
| 312 |
+
-3725142681462373002731339445216700112264527*t**3 +
|
| 313 |
+
583711207282060457652784180668273817487940*t**2*x -
|
| 314 |
+
12381382393074485225164741437227437062814908*t**2 +
|
| 315 |
+
151081054097783125250959636747516827435040*t*x**2 +
|
| 316 |
+
1814103857455163948531448580501928933873280*t*x -
|
| 317 |
+
13353115629395094645843682074271212731433648*t +
|
| 318 |
+
236415091385250007660606958022544983766080*x**2 +
|
| 319 |
+
1390443278862804663728298060085399578417600*x -
|
| 320 |
+
4716885828494075789338754454248931750698880,
|
| 321 |
+
]
|
| 322 |
+
|
| 323 |
+
# NOTE: This is very slow (> 2 minutes on 3.4 GHz) without GMPY
|
| 324 |
+
@slow
|
| 325 |
+
def test_benchmark_czichowski_buchberger():
|
| 326 |
+
with config.using(groebner='buchberger'):
|
| 327 |
+
_do_test_benchmark_czichowski()
|
| 328 |
+
|
| 329 |
+
def test_benchmark_czichowski_f5b():
|
| 330 |
+
with config.using(groebner='f5b'):
|
| 331 |
+
_do_test_benchmark_czichowski()
|
| 332 |
+
|
| 333 |
+
def _do_test_benchmark_cyclic_4():
|
| 334 |
+
R, a,b,c,d = ring("a,b,c,d", ZZ, lex)
|
| 335 |
+
|
| 336 |
+
I = [a + b + c + d,
|
| 337 |
+
a*b + a*d + b*c + b*d,
|
| 338 |
+
a*b*c + a*b*d + a*c*d + b*c*d,
|
| 339 |
+
a*b*c*d - 1]
|
| 340 |
+
|
| 341 |
+
assert groebner(I, R) == [
|
| 342 |
+
4*a + 3*d**9 - 4*d**5 - 3*d,
|
| 343 |
+
4*b + 4*c - 3*d**9 + 4*d**5 + 7*d,
|
| 344 |
+
4*c**2 + 3*d**10 - 4*d**6 - 3*d**2,
|
| 345 |
+
4*c*d**4 + 4*c - d**9 + 4*d**5 + 5*d, d**12 - d**8 - d**4 + 1
|
| 346 |
+
]
|
| 347 |
+
|
| 348 |
+
R, a,b,c,d = ring("a,b,c,d", ZZ, grlex)
|
| 349 |
+
I = [ i.set_ring(R) for i in I ]
|
| 350 |
+
|
| 351 |
+
assert groebner(I, R) == [
|
| 352 |
+
3*b*c - c**2 + d**6 - 3*d**2,
|
| 353 |
+
-b + 3*c**2*d**3 - c - d**5 - 4*d,
|
| 354 |
+
-b + 3*c*d**4 + 2*c + 2*d**5 + 2*d,
|
| 355 |
+
c**4 + 2*c**2*d**2 - d**4 - 2,
|
| 356 |
+
c**3*d + c*d**3 + d**4 + 1,
|
| 357 |
+
b*c**2 - c**3 - c**2*d - 2*c*d**2 - d**3,
|
| 358 |
+
b**2 - c**2, b*d + c**2 + c*d + d**2,
|
| 359 |
+
a + b + c + d
|
| 360 |
+
]
|
| 361 |
+
|
| 362 |
+
def test_benchmark_cyclic_4_buchberger():
|
| 363 |
+
with config.using(groebner='buchberger'):
|
| 364 |
+
_do_test_benchmark_cyclic_4()
|
| 365 |
+
|
| 366 |
+
def test_benchmark_cyclic_4_f5b():
|
| 367 |
+
with config.using(groebner='f5b'):
|
| 368 |
+
_do_test_benchmark_cyclic_4()
|
| 369 |
+
|
| 370 |
+
def test_sig_key():
|
| 371 |
+
s1 = sig((0,) * 3, 2)
|
| 372 |
+
s2 = sig((1,) * 3, 4)
|
| 373 |
+
s3 = sig((2,) * 3, 2)
|
| 374 |
+
|
| 375 |
+
assert sig_key(s1, lex) > sig_key(s2, lex)
|
| 376 |
+
assert sig_key(s2, lex) < sig_key(s3, lex)
|
| 377 |
+
|
| 378 |
+
|
| 379 |
+
def test_lbp_key():
|
| 380 |
+
R, x,y,z,t = ring("x,y,z,t", ZZ, lex)
|
| 381 |
+
|
| 382 |
+
p1 = lbp(sig((0,) * 4, 3), R.zero, 12)
|
| 383 |
+
p2 = lbp(sig((0,) * 4, 4), R.zero, 13)
|
| 384 |
+
p3 = lbp(sig((0,) * 4, 4), R.zero, 12)
|
| 385 |
+
|
| 386 |
+
assert lbp_key(p1) > lbp_key(p2)
|
| 387 |
+
assert lbp_key(p2) < lbp_key(p3)
|
| 388 |
+
|
| 389 |
+
|
| 390 |
+
def test_critical_pair():
|
| 391 |
+
# from cyclic4 with grlex
|
| 392 |
+
R, x,y,z,t = ring("x,y,z,t", QQ, grlex)
|
| 393 |
+
|
| 394 |
+
p1 = (((0, 0, 0, 0), 4), y*z*t**2 + z**2*t**2 - t**4 - 1, 4)
|
| 395 |
+
q1 = (((0, 0, 0, 0), 2), -y**2 - y*t - z*t - t**2, 2)
|
| 396 |
+
|
| 397 |
+
p2 = (((0, 0, 0, 2), 3), z**3*t**2 + z**2*t**3 - z - t, 5)
|
| 398 |
+
q2 = (((0, 0, 2, 2), 2), y*z + z*t**5 + z*t + t**6, 13)
|
| 399 |
+
|
| 400 |
+
assert critical_pair(p1, q1, R) == (
|
| 401 |
+
((0, 0, 1, 2), 2), ((0, 0, 1, 2), QQ(-1, 1)), (((0, 0, 0, 0), 2), -y**2 - y*t - z*t - t**2, 2),
|
| 402 |
+
((0, 1, 0, 0), 4), ((0, 1, 0, 0), QQ(1, 1)), (((0, 0, 0, 0), 4), y*z*t**2 + z**2*t**2 - t**4 - 1, 4)
|
| 403 |
+
)
|
| 404 |
+
assert critical_pair(p2, q2, R) == (
|
| 405 |
+
((0, 0, 4, 2), 2), ((0, 0, 2, 0), QQ(1, 1)), (((0, 0, 2, 2), 2), y*z + z*t**5 + z*t + t**6, 13),
|
| 406 |
+
((0, 0, 0, 5), 3), ((0, 0, 0, 3), QQ(1, 1)), (((0, 0, 0, 2), 3), z**3*t**2 + z**2*t**3 - z - t, 5)
|
| 407 |
+
)
|
| 408 |
+
|
| 409 |
+
def test_cp_key():
|
| 410 |
+
# from cyclic4 with grlex
|
| 411 |
+
R, x,y,z,t = ring("x,y,z,t", QQ, grlex)
|
| 412 |
+
|
| 413 |
+
p1 = (((0, 0, 0, 0), 4), y*z*t**2 + z**2*t**2 - t**4 - 1, 4)
|
| 414 |
+
q1 = (((0, 0, 0, 0), 2), -y**2 - y*t - z*t - t**2, 2)
|
| 415 |
+
|
| 416 |
+
p2 = (((0, 0, 0, 2), 3), z**3*t**2 + z**2*t**3 - z - t, 5)
|
| 417 |
+
q2 = (((0, 0, 2, 2), 2), y*z + z*t**5 + z*t + t**6, 13)
|
| 418 |
+
|
| 419 |
+
cp1 = critical_pair(p1, q1, R)
|
| 420 |
+
cp2 = critical_pair(p2, q2, R)
|
| 421 |
+
|
| 422 |
+
assert cp_key(cp1, R) < cp_key(cp2, R)
|
| 423 |
+
|
| 424 |
+
cp1 = critical_pair(p1, p2, R)
|
| 425 |
+
cp2 = critical_pair(q1, q2, R)
|
| 426 |
+
|
| 427 |
+
assert cp_key(cp1, R) < cp_key(cp2, R)
|
| 428 |
+
|
| 429 |
+
|
| 430 |
+
def test_is_rewritable_or_comparable():
|
| 431 |
+
# from katsura4 with grlex
|
| 432 |
+
R, x,y,z,t = ring("x,y,z,t", QQ, grlex)
|
| 433 |
+
|
| 434 |
+
p = lbp(sig((0, 0, 2, 1), 2), R.zero, 2)
|
| 435 |
+
B = [lbp(sig((0, 0, 0, 1), 2), QQ(2,45)*y**2 + QQ(1,5)*y*z + QQ(5,63)*y*t + z**2*t + QQ(4,45)*z**2 + QQ(76,35)*z*t**2 - QQ(32,105)*z*t + QQ(13,7)*t**3 - QQ(13,21)*t**2, 6)]
|
| 436 |
+
|
| 437 |
+
# rewritable:
|
| 438 |
+
assert is_rewritable_or_comparable(Sign(p), Num(p), B) is True
|
| 439 |
+
|
| 440 |
+
p = lbp(sig((0, 1, 1, 0), 2), R.zero, 7)
|
| 441 |
+
B = [lbp(sig((0, 0, 0, 0), 3), QQ(10,3)*y*z + QQ(4,3)*y*t - QQ(1,3)*y + 4*z**2 + QQ(22,3)*z*t - QQ(4,3)*z + 4*t**2 - QQ(4,3)*t, 3)]
|
| 442 |
+
|
| 443 |
+
# comparable:
|
| 444 |
+
assert is_rewritable_or_comparable(Sign(p), Num(p), B) is True
|
| 445 |
+
|
| 446 |
+
|
| 447 |
+
def test_f5_reduce():
|
| 448 |
+
# katsura3 with lex
|
| 449 |
+
R, x,y,z = ring("x,y,z", QQ, lex)
|
| 450 |
+
|
| 451 |
+
F = [(((0, 0, 0), 1), x + 2*y + 2*z - 1, 1),
|
| 452 |
+
(((0, 0, 0), 2), 6*y**2 + 8*y*z - 2*y + 6*z**2 - 2*z, 2),
|
| 453 |
+
(((0, 0, 0), 3), QQ(10,3)*y*z - QQ(1,3)*y + 4*z**2 - QQ(4,3)*z, 3),
|
| 454 |
+
(((0, 0, 1), 2), y + 30*z**3 - QQ(79,7)*z**2 + QQ(3,7)*z, 4),
|
| 455 |
+
(((0, 0, 2), 2), z**4 - QQ(10,21)*z**3 + QQ(1,84)*z**2 + QQ(1,84)*z, 5)]
|
| 456 |
+
|
| 457 |
+
cp = critical_pair(F[0], F[1], R)
|
| 458 |
+
s = s_poly(cp)
|
| 459 |
+
|
| 460 |
+
assert f5_reduce(s, F) == (((0, 2, 0), 1), R.zero, 1)
|
| 461 |
+
|
| 462 |
+
s = lbp(sig(Sign(s)[0], 100), Polyn(s), Num(s))
|
| 463 |
+
assert f5_reduce(s, F) == s
|
| 464 |
+
|
| 465 |
+
|
| 466 |
+
def test_representing_matrices():
|
| 467 |
+
R, x,y = ring("x,y", QQ, grlex)
|
| 468 |
+
|
| 469 |
+
basis = [(0, 0), (0, 1), (1, 0), (1, 1)]
|
| 470 |
+
F = [x**2 - x - 3*y + 1, -2*x + y**2 + y - 1]
|
| 471 |
+
|
| 472 |
+
assert _representing_matrices(basis, F, R) == [
|
| 473 |
+
[[QQ(0, 1), QQ(0, 1),-QQ(1, 1), QQ(3, 1)],
|
| 474 |
+
[QQ(0, 1), QQ(0, 1), QQ(3, 1),-QQ(4, 1)],
|
| 475 |
+
[QQ(1, 1), QQ(0, 1), QQ(1, 1), QQ(6, 1)],
|
| 476 |
+
[QQ(0, 1), QQ(1, 1), QQ(0, 1), QQ(1, 1)]],
|
| 477 |
+
[[QQ(0, 1), QQ(1, 1), QQ(0, 1),-QQ(2, 1)],
|
| 478 |
+
[QQ(1, 1),-QQ(1, 1), QQ(0, 1), QQ(6, 1)],
|
| 479 |
+
[QQ(0, 1), QQ(2, 1), QQ(0, 1), QQ(3, 1)],
|
| 480 |
+
[QQ(0, 1), QQ(0, 1), QQ(1, 1),-QQ(1, 1)]]]
|
| 481 |
+
|
| 482 |
+
def test_groebner_lcm():
|
| 483 |
+
R, x,y,z = ring("x,y,z", ZZ)
|
| 484 |
+
|
| 485 |
+
assert groebner_lcm(x**2 - y**2, x - y) == x**2 - y**2
|
| 486 |
+
assert groebner_lcm(2*x**2 - 2*y**2, 2*x - 2*y) == 2*x**2 - 2*y**2
|
| 487 |
+
|
| 488 |
+
R, x,y,z = ring("x,y,z", QQ)
|
| 489 |
+
|
| 490 |
+
assert groebner_lcm(x**2 - y**2, x - y) == x**2 - y**2
|
| 491 |
+
assert groebner_lcm(2*x**2 - 2*y**2, 2*x - 2*y) == 2*x**2 - 2*y**2
|
| 492 |
+
|
| 493 |
+
R, x,y = ring("x,y", ZZ)
|
| 494 |
+
|
| 495 |
+
assert groebner_lcm(x**2*y, x*y**2) == x**2*y**2
|
| 496 |
+
|
| 497 |
+
f = 2*x*y**5 - 3*x*y**4 - 2*x*y**3 + 3*x*y**2
|
| 498 |
+
g = y**5 - 2*y**3 + y
|
| 499 |
+
h = 2*x*y**7 - 3*x*y**6 - 4*x*y**5 + 6*x*y**4 + 2*x*y**3 - 3*x*y**2
|
| 500 |
+
|
| 501 |
+
assert groebner_lcm(f, g) == h
|
| 502 |
+
|
| 503 |
+
f = x**3 - 3*x**2*y - 9*x*y**2 - 5*y**3
|
| 504 |
+
g = x**4 + 6*x**3*y + 12*x**2*y**2 + 10*x*y**3 + 3*y**4
|
| 505 |
+
h = x**5 + x**4*y - 18*x**3*y**2 - 50*x**2*y**3 - 47*x*y**4 - 15*y**5
|
| 506 |
+
|
| 507 |
+
assert groebner_lcm(f, g) == h
|
| 508 |
+
|
| 509 |
+
def test_groebner_gcd():
|
| 510 |
+
R, x,y,z = ring("x,y,z", ZZ)
|
| 511 |
+
|
| 512 |
+
assert groebner_gcd(x**2 - y**2, x - y) == x - y
|
| 513 |
+
assert groebner_gcd(2*x**2 - 2*y**2, 2*x - 2*y) == 2*x - 2*y
|
| 514 |
+
|
| 515 |
+
R, x,y,z = ring("x,y,z", QQ)
|
| 516 |
+
|
| 517 |
+
assert groebner_gcd(x**2 - y**2, x - y) == x - y
|
| 518 |
+
assert groebner_gcd(2*x**2 - 2*y**2, 2*x - 2*y) == x - y
|
| 519 |
+
|
| 520 |
+
def test_is_groebner():
|
| 521 |
+
R, x,y = ring("x,y", QQ, grlex)
|
| 522 |
+
valid_groebner = [x**2, x*y, -QQ(1,2)*x + y**2]
|
| 523 |
+
invalid_groebner = [x**3, x*y, -QQ(1,2)*x + y**2]
|
| 524 |
+
assert is_groebner(valid_groebner, R) is True
|
| 525 |
+
assert is_groebner(invalid_groebner, R) is False
|
| 526 |
+
|
| 527 |
+
def test_is_reduced():
|
| 528 |
+
R, x, y = ring("x,y", QQ, lex)
|
| 529 |
+
f = x**2 + 2*x*y**2
|
| 530 |
+
g = x*y + 2*y**3 - 1
|
| 531 |
+
assert is_reduced([f, g], R) == False
|
| 532 |
+
G = groebner([f, g], R)
|
| 533 |
+
assert is_reduced(G, R) == True
|
pllava/lib/python3.10/site-packages/sympy/polys/tests/test_heuristicgcd.py
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sympy.polys.rings import ring
|
| 2 |
+
from sympy.polys.domains import ZZ
|
| 3 |
+
from sympy.polys.heuristicgcd import heugcd
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def test_heugcd_univariate_integers():
|
| 7 |
+
R, x = ring("x", ZZ)
|
| 8 |
+
|
| 9 |
+
f = x**4 + 8*x**3 + 21*x**2 + 22*x + 8
|
| 10 |
+
g = x**3 + 6*x**2 + 11*x + 6
|
| 11 |
+
|
| 12 |
+
h = x**2 + 3*x + 2
|
| 13 |
+
|
| 14 |
+
cff = x**2 + 5*x + 4
|
| 15 |
+
cfg = x + 3
|
| 16 |
+
|
| 17 |
+
assert heugcd(f, g) == (h, cff, cfg)
|
| 18 |
+
|
| 19 |
+
f = x**4 - 4
|
| 20 |
+
g = x**4 + 4*x**2 + 4
|
| 21 |
+
|
| 22 |
+
h = x**2 + 2
|
| 23 |
+
|
| 24 |
+
cff = x**2 - 2
|
| 25 |
+
cfg = x**2 + 2
|
| 26 |
+
|
| 27 |
+
assert heugcd(f, g) == (h, cff, cfg)
|
| 28 |
+
|
| 29 |
+
f = x**8 + x**6 - 3*x**4 - 3*x**3 + 8*x**2 + 2*x - 5
|
| 30 |
+
g = 3*x**6 + 5*x**4 - 4*x**2 - 9*x + 21
|
| 31 |
+
|
| 32 |
+
h = 1
|
| 33 |
+
|
| 34 |
+
cff = f
|
| 35 |
+
cfg = g
|
| 36 |
+
|
| 37 |
+
assert heugcd(f, g) == (h, cff, cfg)
|
| 38 |
+
|
| 39 |
+
f = - 352518131239247345597970242177235495263669787845475025293906825864749649589178600387510272*x**49 \
|
| 40 |
+
+ 46818041807522713962450042363465092040687472354933295397472942006618953623327997952*x**42 \
|
| 41 |
+
+ 378182690892293941192071663536490788434899030680411695933646320291525827756032*x**35 \
|
| 42 |
+
+ 112806468807371824947796775491032386836656074179286744191026149539708928*x**28 \
|
| 43 |
+
- 12278371209708240950316872681744825481125965781519138077173235712*x**21 \
|
| 44 |
+
+ 289127344604779611146960547954288113529690984687482920704*x**14 \
|
| 45 |
+
+ 19007977035740498977629742919480623972236450681*x**7 \
|
| 46 |
+
+ 311973482284542371301330321821976049
|
| 47 |
+
|
| 48 |
+
g = 365431878023781158602430064717380211405897160759702125019136*x**21 \
|
| 49 |
+
+ 197599133478719444145775798221171663643171734081650688*x**14 \
|
| 50 |
+
- 9504116979659010018253915765478924103928886144*x**7 \
|
| 51 |
+
- 311973482284542371301330321821976049
|
| 52 |
+
|
| 53 |
+
# TODO: assert heugcd(f, f.diff(x))[0] == g
|
| 54 |
+
|
| 55 |
+
f = 1317378933230047068160*x + 2945748836994210856960
|
| 56 |
+
g = 120352542776360960*x + 269116466014453760
|
| 57 |
+
|
| 58 |
+
h = 120352542776360960*x + 269116466014453760
|
| 59 |
+
cff = 10946
|
| 60 |
+
cfg = 1
|
| 61 |
+
|
| 62 |
+
assert heugcd(f, g) == (h, cff, cfg)
|
| 63 |
+
|
| 64 |
+
def test_heugcd_multivariate_integers():
|
| 65 |
+
R, x, y = ring("x,y", ZZ)
|
| 66 |
+
|
| 67 |
+
f, g = 2*x**2 + 4*x + 2, x + 1
|
| 68 |
+
assert heugcd(f, g) == (x + 1, 2*x + 2, 1)
|
| 69 |
+
|
| 70 |
+
f, g = x + 1, 2*x**2 + 4*x + 2
|
| 71 |
+
assert heugcd(f, g) == (x + 1, 1, 2*x + 2)
|
| 72 |
+
|
| 73 |
+
R, x, y, z, u = ring("x,y,z,u", ZZ)
|
| 74 |
+
|
| 75 |
+
f, g = u**2 + 2*u + 1, 2*u + 2
|
| 76 |
+
assert heugcd(f, g) == (u + 1, u + 1, 2)
|
| 77 |
+
|
| 78 |
+
f, g = z**2*u**2 + 2*z**2*u + z**2 + z*u + z, u**2 + 2*u + 1
|
| 79 |
+
h, cff, cfg = u + 1, z**2*u + z**2 + z, u + 1
|
| 80 |
+
|
| 81 |
+
assert heugcd(f, g) == (h, cff, cfg)
|
| 82 |
+
assert heugcd(g, f) == (h, cfg, cff)
|
| 83 |
+
|
| 84 |
+
R, x, y, z = ring("x,y,z", ZZ)
|
| 85 |
+
|
| 86 |
+
f, g, h = R.fateman_poly_F_1()
|
| 87 |
+
H, cff, cfg = heugcd(f, g)
|
| 88 |
+
|
| 89 |
+
assert H == h and H*cff == f and H*cfg == g
|
| 90 |
+
|
| 91 |
+
R, x, y, z, u, v = ring("x,y,z,u,v", ZZ)
|
| 92 |
+
|
| 93 |
+
f, g, h = R.fateman_poly_F_1()
|
| 94 |
+
H, cff, cfg = heugcd(f, g)
|
| 95 |
+
|
| 96 |
+
assert H == h and H*cff == f and H*cfg == g
|
| 97 |
+
|
| 98 |
+
R, x, y, z, u, v, a, b = ring("x,y,z,u,v,a,b", ZZ)
|
| 99 |
+
|
| 100 |
+
f, g, h = R.fateman_poly_F_1()
|
| 101 |
+
H, cff, cfg = heugcd(f, g)
|
| 102 |
+
|
| 103 |
+
assert H == h and H*cff == f and H*cfg == g
|
| 104 |
+
|
| 105 |
+
R, x, y, z, u, v, a, b, c, d = ring("x,y,z,u,v,a,b,c,d", ZZ)
|
| 106 |
+
|
| 107 |
+
f, g, h = R.fateman_poly_F_1()
|
| 108 |
+
H, cff, cfg = heugcd(f, g)
|
| 109 |
+
|
| 110 |
+
assert H == h and H*cff == f and H*cfg == g
|
| 111 |
+
|
| 112 |
+
R, x, y, z = ring("x,y,z", ZZ)
|
| 113 |
+
|
| 114 |
+
f, g, h = R.fateman_poly_F_2()
|
| 115 |
+
H, cff, cfg = heugcd(f, g)
|
| 116 |
+
|
| 117 |
+
assert H == h and H*cff == f and H*cfg == g
|
| 118 |
+
|
| 119 |
+
f, g, h = R.fateman_poly_F_3()
|
| 120 |
+
H, cff, cfg = heugcd(f, g)
|
| 121 |
+
|
| 122 |
+
assert H == h and H*cff == f and H*cfg == g
|
| 123 |
+
|
| 124 |
+
R, x, y, z, t = ring("x,y,z,t", ZZ)
|
| 125 |
+
|
| 126 |
+
f, g, h = R.fateman_poly_F_3()
|
| 127 |
+
H, cff, cfg = heugcd(f, g)
|
| 128 |
+
|
| 129 |
+
assert H == h and H*cff == f and H*cfg == g
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
def test_issue_10996():
|
| 133 |
+
R, x, y, z = ring("x,y,z", ZZ)
|
| 134 |
+
|
| 135 |
+
f = 12*x**6*y**7*z**3 - 3*x**4*y**9*z**3 + 12*x**3*y**5*z**4
|
| 136 |
+
g = -48*x**7*y**8*z**3 + 12*x**5*y**10*z**3 - 48*x**5*y**7*z**2 + \
|
| 137 |
+
36*x**4*y**7*z - 48*x**4*y**6*z**4 + 12*x**3*y**9*z**2 - 48*x**3*y**4 \
|
| 138 |
+
- 9*x**2*y**9*z - 48*x**2*y**5*z**3 + 12*x*y**6 + 36*x*y**5*z**2 - 48*y**2*z
|
| 139 |
+
|
| 140 |
+
H, cff, cfg = heugcd(f, g)
|
| 141 |
+
|
| 142 |
+
assert H == 12*x**3*y**4 - 3*x*y**6 + 12*y**2*z
|
| 143 |
+
assert H*cff == f and H*cfg == g
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
def test_issue_25793():
|
| 147 |
+
R, x = ring("x", ZZ)
|
| 148 |
+
f = x - 4851 # failure starts for values more than 4850
|
| 149 |
+
g = f*(2*x + 1)
|
| 150 |
+
H, cff, cfg = R.dup_zz_heu_gcd(f, g)
|
| 151 |
+
assert H == f
|
| 152 |
+
# needs a test for dmp, too, that fails in master before this change
|