ZTWHHH commited on
Commit
f7bd521
·
verified ·
1 Parent(s): e85c74e

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +1 -0
  2. valley/lib/python3.10/site-packages/sympy/core/__pycache__/expr.cpython-310.pyc +3 -0
  3. valley/lib/python3.10/site-packages/sympy/polys/tests/test_appellseqs.py +91 -0
  4. valley/lib/python3.10/site-packages/sympy/polys/tests/test_constructor.py +208 -0
  5. valley/lib/python3.10/site-packages/sympy/polys/tests/test_densebasic.py +730 -0
  6. valley/lib/python3.10/site-packages/sympy/polys/tests/test_dispersion.py +95 -0
  7. valley/lib/python3.10/site-packages/sympy/polys/tests/test_distributedmodules.py +208 -0
  8. valley/lib/python3.10/site-packages/sympy/polys/tests/test_euclidtools.py +712 -0
  9. valley/lib/python3.10/site-packages/sympy/polys/tests/test_fields.py +362 -0
  10. valley/lib/python3.10/site-packages/sympy/polys/tests/test_galoistools.py +875 -0
  11. valley/lib/python3.10/site-packages/sympy/polys/tests/test_groebnertools.py +533 -0
  12. valley/lib/python3.10/site-packages/sympy/polys/tests/test_heuristicgcd.py +152 -0
  13. valley/lib/python3.10/site-packages/sympy/polys/tests/test_hypothesis.py +36 -0
  14. valley/lib/python3.10/site-packages/sympy/polys/tests/test_injections.py +39 -0
  15. valley/lib/python3.10/site-packages/sympy/polys/tests/test_multivariate_resultants.py +294 -0
  16. valley/lib/python3.10/site-packages/sympy/polys/tests/test_orderings.py +124 -0
  17. valley/lib/python3.10/site-packages/sympy/polys/tests/test_partfrac.py +249 -0
  18. valley/lib/python3.10/site-packages/sympy/polys/tests/test_polyclasses.py +588 -0
  19. valley/lib/python3.10/site-packages/sympy/polys/tests/test_polyroots.py +758 -0
  20. valley/lib/python3.10/site-packages/sympy/polys/tests/test_polytools.py +0 -0
  21. valley/lib/python3.10/site-packages/sympy/polys/tests/test_polyutils.py +300 -0
  22. valley/lib/python3.10/site-packages/sympy/polys/tests/test_pythonrational.py +139 -0
  23. valley/lib/python3.10/site-packages/sympy/polys/tests/test_rootoftools.py +653 -0
  24. valley/lib/python3.10/site-packages/sympy/polys/tests/test_specialpolys.py +152 -0
  25. wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/CheckIPOSupported/CMakeLists-Fortran.txt.in +8 -0
  26. wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/CheckIPOSupported/foo.c +4 -0
  27. wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/CheckIPOSupported/foo.cpp +4 -0
  28. wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/CheckIPOSupported/foo.f +2 -0
  29. wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/CheckIPOSupported/main.c +6 -0
  30. wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/CheckIPOSupported/main.f +3 -0
  31. wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/CompilerId/GHS_default.gpj.in +8 -0
  32. wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/CompilerId/GHS_lib.gpj.in +3 -0
  33. wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/CompilerId/VS-10.csproj.in +58 -0
  34. wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/CompilerId/VS-Intel.vfproj.in +42 -0
  35. wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/CompilerId/main.swift.in +1 -0
  36. wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/ExternalProject/PatchInfo.txt.in +6 -0
  37. wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/ExternalProject/RepositoryInfo.txt.in +9 -0
  38. wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/ExternalProject/UpdateInfo.txt.in +7 -0
  39. wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/ExternalProject/cfgcmd.txt.in +1 -0
  40. wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/ExternalProject/extractfile.cmake.in +65 -0
  41. wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/ExternalProject/gitupdate.cmake.in +317 -0
  42. wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/ExternalProject/hgclone.cmake.in +62 -0
  43. wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/ExternalProject/shared_internal_commands.cmake +1982 -0
  44. wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/ExternalProject/stepscript.cmake.in +9 -0
  45. wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/ExternalProject/verify.cmake.in +37 -0
  46. wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/FetchContent/package-config-version.cmake.in +8 -0
  47. wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/FortranCInterface/Detect.cmake +196 -0
  48. wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/FortranCInterface/call_sub.f +4 -0
  49. wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/Platform/Android/Determine-Compiler-NDK.cmake +276 -0
  50. wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/Platform/Android/VCXProjInspect.vcxproj.in +39 -0
.gitattributes CHANGED
@@ -597,3 +597,4 @@ valley/lib/python3.10/site-packages/idna/__pycache__/uts46data.cpython-310.pyc f
597
  wemm/lib/libtinfow.so.6.4 filter=lfs diff=lfs merge=lfs -text
598
  valley/lib/python3.10/site-packages/triton/backends/nvidia/bin/nvdisasm filter=lfs diff=lfs merge=lfs -text
599
  valley/lib/python3.10/site-packages/triton/_C/libproton.so filter=lfs diff=lfs merge=lfs -text
 
 
597
  wemm/lib/libtinfow.so.6.4 filter=lfs diff=lfs merge=lfs -text
598
  valley/lib/python3.10/site-packages/triton/backends/nvidia/bin/nvdisasm filter=lfs diff=lfs merge=lfs -text
599
  valley/lib/python3.10/site-packages/triton/_C/libproton.so filter=lfs diff=lfs merge=lfs -text
600
+ valley/lib/python3.10/site-packages/sympy/core/__pycache__/expr.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
valley/lib/python3.10/site-packages/sympy/core/__pycache__/expr.cpython-310.pyc ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:40c19bd2fb1a3ca3f66df799fe6dcbf980142bc875bde7ab5ec0359e57f50d49
3
+ size 114993
valley/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)
valley/lib/python3.10/site-packages/sympy/polys/tests/test_constructor.py ADDED
@@ -0,0 +1,208 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
valley/lib/python3.10/site-packages/sympy/polys/tests/test_densebasic.py ADDED
@@ -0,0 +1,730 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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)
valley/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
valley/lib/python3.10/site-packages/sympy/polys/tests/test_distributedmodules.py ADDED
@@ -0,0 +1,208 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Tests for sparse distributed modules. """
2
+
3
+ from sympy.polys.distributedmodules import (
4
+ sdm_monomial_mul, sdm_monomial_deg, sdm_monomial_divides,
5
+ sdm_add, sdm_LM, 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
valley/lib/python3.10/site-packages/sympy/polys/tests/test_euclidtools.py ADDED
@@ -0,0 +1,712 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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)
712
+ assert R.dmp_cancel(0, y, include=False) == (1, 1, 0, 1)
valley/lib/python3.10/site-packages/sympy/polys/tests/test_fields.py ADDED
@@ -0,0 +1,362 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Test sparse rational functions. """
2
+
3
+ from sympy.polys.fields import field, sfield, FracField, FracElement
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
valley/lib/python3.10/site-packages/sympy/polys/tests/test_galoistools.py ADDED
@@ -0,0 +1,875 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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) == []
valley/lib/python3.10/site-packages/sympy/polys/tests/test_groebnertools.py ADDED
@@ -0,0 +1,533 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
valley/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
valley/lib/python3.10/site-packages/sympy/polys/tests/test_hypothesis.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from hypothesis import given
2
+ from hypothesis import strategies as st
3
+ from sympy.abc import x
4
+ from sympy.polys.polytools import Poly
5
+
6
+
7
+ def polys(*, nonzero=False, domain="ZZ"):
8
+ # This is a simple strategy, but sufficient the tests below
9
+ elems = {"ZZ": st.integers(), "QQ": st.fractions()}
10
+ coeff_st = st.lists(elems[domain])
11
+ if nonzero:
12
+ coeff_st = coeff_st.filter(any)
13
+ return st.builds(Poly, coeff_st, st.just(x), domain=st.just(domain))
14
+
15
+
16
+ @given(f=polys(), g=polys(), r=polys())
17
+ def test_gcd_hypothesis(f, g, r):
18
+ gcd_1 = f.gcd(g)
19
+ gcd_2 = g.gcd(f)
20
+ assert gcd_1 == gcd_2
21
+
22
+ # multiply by r
23
+ gcd_3 = g.gcd(f + r * g)
24
+ assert gcd_1 == gcd_3
25
+
26
+
27
+ @given(f_z=polys(), g_z=polys(nonzero=True))
28
+ def test_poly_hypothesis_integers(f_z, g_z):
29
+ remainder_z = f_z.rem(g_z)
30
+ assert g_z.degree() >= remainder_z.degree() or remainder_z.degree() == 0
31
+
32
+
33
+ @given(f_q=polys(domain="QQ"), g_q=polys(nonzero=True, domain="QQ"))
34
+ def test_poly_hypothesis_rationals(f_q, g_q):
35
+ remainder_q = f_q.rem(g_q)
36
+ assert g_q.degree() >= remainder_q.degree() or remainder_q.degree() == 0
valley/lib/python3.10/site-packages/sympy/polys/tests/test_injections.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Tests for functions that inject symbols into the global namespace. """
2
+
3
+ from sympy.polys.rings import vring
4
+ from sympy.polys.fields import vfield
5
+ from sympy.polys.domains import QQ
6
+
7
+ def test_vring():
8
+ ns = {'vring':vring, 'QQ':QQ}
9
+ exec('R = vring("r", QQ)', ns)
10
+ exec('assert r == R.gens[0]', ns)
11
+
12
+ exec('R = vring("rb rbb rcc rzz _rx", QQ)', ns)
13
+ exec('assert rb == R.gens[0]', ns)
14
+ exec('assert rbb == R.gens[1]', ns)
15
+ exec('assert rcc == R.gens[2]', ns)
16
+ exec('assert rzz == R.gens[3]', ns)
17
+ exec('assert _rx == R.gens[4]', ns)
18
+
19
+ exec('R = vring(["rd", "re", "rfg"], QQ)', ns)
20
+ exec('assert rd == R.gens[0]', ns)
21
+ exec('assert re == R.gens[1]', ns)
22
+ exec('assert rfg == R.gens[2]', ns)
23
+
24
+ def test_vfield():
25
+ ns = {'vfield':vfield, 'QQ':QQ}
26
+ exec('F = vfield("f", QQ)', ns)
27
+ exec('assert f == F.gens[0]', ns)
28
+
29
+ exec('F = vfield("fb fbb fcc fzz _fx", QQ)', ns)
30
+ exec('assert fb == F.gens[0]', ns)
31
+ exec('assert fbb == F.gens[1]', ns)
32
+ exec('assert fcc == F.gens[2]', ns)
33
+ exec('assert fzz == F.gens[3]', ns)
34
+ exec('assert _fx == F.gens[4]', ns)
35
+
36
+ exec('F = vfield(["fd", "fe", "ffg"], QQ)', ns)
37
+ exec('assert fd == F.gens[0]', ns)
38
+ exec('assert fe == F.gens[1]', ns)
39
+ exec('assert ffg == F.gens[2]', ns)
valley/lib/python3.10/site-packages/sympy/polys/tests/test_multivariate_resultants.py ADDED
@@ -0,0 +1,294 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Tests for Dixon's and Macaulay's classes. """
2
+
3
+ from sympy.matrices.dense import Matrix
4
+ from sympy.polys.polytools import factor
5
+ from sympy.core import symbols
6
+ from sympy.tensor.indexed import IndexedBase
7
+
8
+ from sympy.polys.multivariate_resultants import (DixonResultant,
9
+ MacaulayResultant)
10
+
11
+ c, d = symbols("a, b")
12
+ x, y = symbols("x, y")
13
+
14
+ p = c * x + y
15
+ q = x + d * y
16
+
17
+ dixon = DixonResultant(polynomials=[p, q], variables=[x, y])
18
+ macaulay = MacaulayResultant(polynomials=[p, q], variables=[x, y])
19
+
20
+ def test_dixon_resultant_init():
21
+ """Test init method of DixonResultant."""
22
+ a = IndexedBase("alpha")
23
+
24
+ assert dixon.polynomials == [p, q]
25
+ assert dixon.variables == [x, y]
26
+ assert dixon.n == 2
27
+ assert dixon.m == 2
28
+ assert dixon.dummy_variables == [a[0], a[1]]
29
+
30
+ def test_get_dixon_polynomial_numerical():
31
+ """Test Dixon's polynomial for a numerical example."""
32
+ a = IndexedBase("alpha")
33
+
34
+ p = x + y
35
+ q = x ** 2 + y **3
36
+ h = x ** 2 + y
37
+
38
+ dixon = DixonResultant([p, q, h], [x, y])
39
+ polynomial = -x * y ** 2 * a[0] - x * y ** 2 * a[1] - x * y * a[0] \
40
+ * a[1] - x * y * a[1] ** 2 - x * a[0] * a[1] ** 2 + x * a[0] - \
41
+ y ** 2 * a[0] * a[1] + y ** 2 * a[1] - y * a[0] * a[1] ** 2 + y * \
42
+ a[1] ** 2
43
+
44
+ assert dixon.get_dixon_polynomial().as_expr().expand() == polynomial
45
+
46
+ def test_get_max_degrees():
47
+ """Tests max degrees function."""
48
+
49
+ p = x + y
50
+ q = x ** 2 + y **3
51
+ h = x ** 2 + y
52
+
53
+ dixon = DixonResultant(polynomials=[p, q, h], variables=[x, y])
54
+ dixon_polynomial = dixon.get_dixon_polynomial()
55
+
56
+ assert dixon.get_max_degrees(dixon_polynomial) == [1, 2]
57
+
58
+ def test_get_dixon_matrix():
59
+ """Test Dixon's resultant for a numerical example."""
60
+
61
+ x, y = symbols('x, y')
62
+
63
+ p = x + y
64
+ q = x ** 2 + y ** 3
65
+ h = x ** 2 + y
66
+
67
+ dixon = DixonResultant([p, q, h], [x, y])
68
+ polynomial = dixon.get_dixon_polynomial()
69
+
70
+ assert dixon.get_dixon_matrix(polynomial).det() == 0
71
+
72
+ def test_get_dixon_matrix_example_two():
73
+ """Test Dixon's matrix for example from [Palancz08]_."""
74
+ x, y, z = symbols('x, y, z')
75
+
76
+ f = x ** 2 + y ** 2 - 1 + z * 0
77
+ g = x ** 2 + z ** 2 - 1 + y * 0
78
+ h = y ** 2 + z ** 2 - 1
79
+
80
+ example_two = DixonResultant([f, g, h], [y, z])
81
+ poly = example_two.get_dixon_polynomial()
82
+ matrix = example_two.get_dixon_matrix(poly)
83
+
84
+ expr = 1 - 8 * x ** 2 + 24 * x ** 4 - 32 * x ** 6 + 16 * x ** 8
85
+ assert (matrix.det() - expr).expand() == 0
86
+
87
+ def test_KSY_precondition():
88
+ """Tests precondition for KSY Resultant."""
89
+ A, B, C = symbols('A, B, C')
90
+
91
+ m1 = Matrix([[1, 2, 3],
92
+ [4, 5, 12],
93
+ [6, 7, 18]])
94
+
95
+ m2 = Matrix([[0, C**2],
96
+ [-2 * C, -C ** 2]])
97
+
98
+ m3 = Matrix([[1, 0],
99
+ [0, 1]])
100
+
101
+ m4 = Matrix([[A**2, 0, 1],
102
+ [A, 1, 1 / A]])
103
+
104
+ m5 = Matrix([[5, 1],
105
+ [2, B],
106
+ [0, 1],
107
+ [0, 0]])
108
+
109
+ assert dixon.KSY_precondition(m1) == False
110
+ assert dixon.KSY_precondition(m2) == True
111
+ assert dixon.KSY_precondition(m3) == True
112
+ assert dixon.KSY_precondition(m4) == False
113
+ assert dixon.KSY_precondition(m5) == True
114
+
115
+ def test_delete_zero_rows_and_columns():
116
+ """Tests method for deleting rows and columns containing only zeros."""
117
+ A, B, C = symbols('A, B, C')
118
+
119
+ m1 = Matrix([[0, 0],
120
+ [0, 0],
121
+ [1, 2]])
122
+
123
+ m2 = Matrix([[0, 1, 2],
124
+ [0, 3, 4],
125
+ [0, 5, 6]])
126
+
127
+ m3 = Matrix([[0, 0, 0, 0],
128
+ [0, 1, 2, 0],
129
+ [0, 3, 4, 0],
130
+ [0, 0, 0, 0]])
131
+
132
+ m4 = Matrix([[1, 0, 2],
133
+ [0, 0, 0],
134
+ [3, 0, 4]])
135
+
136
+ m5 = Matrix([[0, 0, 0, 1],
137
+ [0, 0, 0, 2],
138
+ [0, 0, 0, 3],
139
+ [0, 0, 0, 4]])
140
+
141
+ m6 = Matrix([[0, 0, A],
142
+ [B, 0, 0],
143
+ [0, 0, C]])
144
+
145
+ assert dixon.delete_zero_rows_and_columns(m1) == Matrix([[1, 2]])
146
+
147
+ assert dixon.delete_zero_rows_and_columns(m2) == Matrix([[1, 2],
148
+ [3, 4],
149
+ [5, 6]])
150
+
151
+ assert dixon.delete_zero_rows_and_columns(m3) == Matrix([[1, 2],
152
+ [3, 4]])
153
+
154
+ assert dixon.delete_zero_rows_and_columns(m4) == Matrix([[1, 2],
155
+ [3, 4]])
156
+
157
+ assert dixon.delete_zero_rows_and_columns(m5) == Matrix([[1],
158
+ [2],
159
+ [3],
160
+ [4]])
161
+
162
+ assert dixon.delete_zero_rows_and_columns(m6) == Matrix([[0, A],
163
+ [B, 0],
164
+ [0, C]])
165
+
166
+ def test_product_leading_entries():
167
+ """Tests product of leading entries method."""
168
+ A, B = symbols('A, B')
169
+
170
+ m1 = Matrix([[1, 2, 3],
171
+ [0, 4, 5],
172
+ [0, 0, 6]])
173
+
174
+ m2 = Matrix([[0, 0, 1],
175
+ [2, 0, 3]])
176
+
177
+ m3 = Matrix([[0, 0, 0],
178
+ [1, 2, 3],
179
+ [0, 0, 0]])
180
+
181
+ m4 = Matrix([[0, 0, A],
182
+ [1, 2, 3],
183
+ [B, 0, 0]])
184
+
185
+ assert dixon.product_leading_entries(m1) == 24
186
+ assert dixon.product_leading_entries(m2) == 2
187
+ assert dixon.product_leading_entries(m3) == 1
188
+ assert dixon.product_leading_entries(m4) == A * B
189
+
190
+ def test_get_KSY_Dixon_resultant_example_one():
191
+ """Tests the KSY Dixon resultant for example one"""
192
+ x, y, z = symbols('x, y, z')
193
+
194
+ p = x * y * z
195
+ q = x**2 - z**2
196
+ h = x + y + z
197
+ dixon = DixonResultant([p, q, h], [x, y])
198
+ dixon_poly = dixon.get_dixon_polynomial()
199
+ dixon_matrix = dixon.get_dixon_matrix(dixon_poly)
200
+ D = dixon.get_KSY_Dixon_resultant(dixon_matrix)
201
+
202
+ assert D == -z**3
203
+
204
+ def test_get_KSY_Dixon_resultant_example_two():
205
+ """Tests the KSY Dixon resultant for example two"""
206
+ x, y, A = symbols('x, y, A')
207
+
208
+ p = x * y + x * A + x - A**2 - A + y**2 + y
209
+ q = x**2 + x * A - x + x * y + y * A - y
210
+ h = x**2 + x * y + 2 * x - x * A - y * A - 2 * A
211
+
212
+ dixon = DixonResultant([p, q, h], [x, y])
213
+ dixon_poly = dixon.get_dixon_polynomial()
214
+ dixon_matrix = dixon.get_dixon_matrix(dixon_poly)
215
+ D = factor(dixon.get_KSY_Dixon_resultant(dixon_matrix))
216
+
217
+ assert D == -8*A*(A - 1)*(A + 2)*(2*A - 1)**2
218
+
219
+ def test_macaulay_resultant_init():
220
+ """Test init method of MacaulayResultant."""
221
+
222
+ assert macaulay.polynomials == [p, q]
223
+ assert macaulay.variables == [x, y]
224
+ assert macaulay.n == 2
225
+ assert macaulay.degrees == [1, 1]
226
+ assert macaulay.degree_m == 1
227
+ assert macaulay.monomials_size == 2
228
+
229
+ def test_get_degree_m():
230
+ assert macaulay._get_degree_m() == 1
231
+
232
+ def test_get_size():
233
+ assert macaulay.get_size() == 2
234
+
235
+ def test_macaulay_example_one():
236
+ """Tests the Macaulay for example from [Bruce97]_"""
237
+
238
+ x, y, z = symbols('x, y, z')
239
+ a_1_1, a_1_2, a_1_3 = symbols('a_1_1, a_1_2, a_1_3')
240
+ a_2_2, a_2_3, a_3_3 = symbols('a_2_2, a_2_3, a_3_3')
241
+ b_1_1, b_1_2, b_1_3 = symbols('b_1_1, b_1_2, b_1_3')
242
+ b_2_2, b_2_3, b_3_3 = symbols('b_2_2, b_2_3, b_3_3')
243
+ c_1, c_2, c_3 = symbols('c_1, c_2, c_3')
244
+
245
+ f_1 = a_1_1 * x ** 2 + a_1_2 * x * y + a_1_3 * x * z + \
246
+ a_2_2 * y ** 2 + a_2_3 * y * z + a_3_3 * z ** 2
247
+ f_2 = b_1_1 * x ** 2 + b_1_2 * x * y + b_1_3 * x * z + \
248
+ b_2_2 * y ** 2 + b_2_3 * y * z + b_3_3 * z ** 2
249
+ f_3 = c_1 * x + c_2 * y + c_3 * z
250
+
251
+ mac = MacaulayResultant([f_1, f_2, f_3], [x, y, z])
252
+
253
+ assert mac.degrees == [2, 2, 1]
254
+ assert mac.degree_m == 3
255
+
256
+ assert mac.monomial_set == [x ** 3, x ** 2 * y, x ** 2 * z,
257
+ x * y ** 2,
258
+ x * y * z, x * z ** 2, y ** 3,
259
+ y ** 2 *z, y * z ** 2, z ** 3]
260
+ assert mac.monomials_size == 10
261
+ assert mac.get_row_coefficients() == [[x, y, z], [x, y, z],
262
+ [x * y, x * z, y * z, z ** 2]]
263
+
264
+ matrix = mac.get_matrix()
265
+ assert matrix.shape == (mac.monomials_size, mac.monomials_size)
266
+ assert mac.get_submatrix(matrix) == Matrix([[a_1_1, a_2_2],
267
+ [b_1_1, b_2_2]])
268
+
269
+ def test_macaulay_example_two():
270
+ """Tests the Macaulay formulation for example from [Stiller96]_."""
271
+
272
+ x, y, z = symbols('x, y, z')
273
+ a_0, a_1, a_2 = symbols('a_0, a_1, a_2')
274
+ b_0, b_1, b_2 = symbols('b_0, b_1, b_2')
275
+ c_0, c_1, c_2, c_3, c_4 = symbols('c_0, c_1, c_2, c_3, c_4')
276
+
277
+ f = a_0 * y - a_1 * x + a_2 * z
278
+ g = b_1 * x ** 2 + b_0 * y ** 2 - b_2 * z ** 2
279
+ h = c_0 * y - c_1 * x ** 3 + c_2 * x ** 2 * z - c_3 * x * z ** 2 + \
280
+ c_4 * z ** 3
281
+
282
+ mac = MacaulayResultant([f, g, h], [x, y, z])
283
+
284
+ assert mac.degrees == [1, 2, 3]
285
+ assert mac.degree_m == 4
286
+ assert mac.monomials_size == 15
287
+ assert len(mac.get_row_coefficients()) == mac.n
288
+
289
+ matrix = mac.get_matrix()
290
+ assert matrix.shape == (mac.monomials_size, mac.monomials_size)
291
+ assert mac.get_submatrix(matrix) == Matrix([[-a_1, a_0, a_2, 0],
292
+ [0, -a_1, 0, 0],
293
+ [0, 0, -a_1, 0],
294
+ [0, 0, 0, -a_1]])
valley/lib/python3.10/site-packages/sympy/polys/tests/test_orderings.py ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Tests of monomial orderings. """
2
+
3
+ from sympy.polys.orderings import (
4
+ monomial_key, lex, grlex, grevlex, ilex, igrlex,
5
+ LexOrder, InverseOrder, ProductOrder, build_product_order,
6
+ )
7
+
8
+ from sympy.abc import x, y, z, t
9
+ from sympy.core import S
10
+ from sympy.testing.pytest import raises
11
+
12
+ def test_lex_order():
13
+ assert lex((1, 2, 3)) == (1, 2, 3)
14
+ assert str(lex) == 'lex'
15
+
16
+ assert lex((1, 2, 3)) == lex((1, 2, 3))
17
+
18
+ assert lex((2, 2, 3)) > lex((1, 2, 3))
19
+ assert lex((1, 3, 3)) > lex((1, 2, 3))
20
+ assert lex((1, 2, 4)) > lex((1, 2, 3))
21
+
22
+ assert lex((0, 2, 3)) < lex((1, 2, 3))
23
+ assert lex((1, 1, 3)) < lex((1, 2, 3))
24
+ assert lex((1, 2, 2)) < lex((1, 2, 3))
25
+
26
+ assert lex.is_global is True
27
+ assert lex == LexOrder()
28
+ assert lex != grlex
29
+
30
+ def test_grlex_order():
31
+ assert grlex((1, 2, 3)) == (6, (1, 2, 3))
32
+ assert str(grlex) == 'grlex'
33
+
34
+ assert grlex((1, 2, 3)) == grlex((1, 2, 3))
35
+
36
+ assert grlex((2, 2, 3)) > grlex((1, 2, 3))
37
+ assert grlex((1, 3, 3)) > grlex((1, 2, 3))
38
+ assert grlex((1, 2, 4)) > grlex((1, 2, 3))
39
+
40
+ assert grlex((0, 2, 3)) < grlex((1, 2, 3))
41
+ assert grlex((1, 1, 3)) < grlex((1, 2, 3))
42
+ assert grlex((1, 2, 2)) < grlex((1, 2, 3))
43
+
44
+ assert grlex((2, 2, 3)) > grlex((1, 2, 4))
45
+ assert grlex((1, 3, 3)) > grlex((1, 2, 4))
46
+
47
+ assert grlex((0, 2, 3)) < grlex((1, 2, 2))
48
+ assert grlex((1, 1, 3)) < grlex((1, 2, 2))
49
+
50
+ assert grlex((0, 1, 1)) > grlex((0, 0, 2))
51
+ assert grlex((0, 3, 1)) < grlex((2, 2, 1))
52
+
53
+ assert grlex.is_global is True
54
+
55
+ def test_grevlex_order():
56
+ assert grevlex((1, 2, 3)) == (6, (-3, -2, -1))
57
+ assert str(grevlex) == 'grevlex'
58
+
59
+ assert grevlex((1, 2, 3)) == grevlex((1, 2, 3))
60
+
61
+ assert grevlex((2, 2, 3)) > grevlex((1, 2, 3))
62
+ assert grevlex((1, 3, 3)) > grevlex((1, 2, 3))
63
+ assert grevlex((1, 2, 4)) > grevlex((1, 2, 3))
64
+
65
+ assert grevlex((0, 2, 3)) < grevlex((1, 2, 3))
66
+ assert grevlex((1, 1, 3)) < grevlex((1, 2, 3))
67
+ assert grevlex((1, 2, 2)) < grevlex((1, 2, 3))
68
+
69
+ assert grevlex((2, 2, 3)) > grevlex((1, 2, 4))
70
+ assert grevlex((1, 3, 3)) > grevlex((1, 2, 4))
71
+
72
+ assert grevlex((0, 2, 3)) < grevlex((1, 2, 2))
73
+ assert grevlex((1, 1, 3)) < grevlex((1, 2, 2))
74
+
75
+ assert grevlex((0, 1, 1)) > grevlex((0, 0, 2))
76
+ assert grevlex((0, 3, 1)) < grevlex((2, 2, 1))
77
+
78
+ assert grevlex.is_global is True
79
+
80
+ def test_InverseOrder():
81
+ ilex = InverseOrder(lex)
82
+ igrlex = InverseOrder(grlex)
83
+
84
+ assert ilex((1, 2, 3)) > ilex((2, 0, 3))
85
+ assert igrlex((1, 2, 3)) < igrlex((0, 2, 3))
86
+ assert str(ilex) == "ilex"
87
+ assert str(igrlex) == "igrlex"
88
+ assert ilex.is_global is False
89
+ assert igrlex.is_global is False
90
+ assert ilex != igrlex
91
+ assert ilex == InverseOrder(LexOrder())
92
+
93
+ def test_ProductOrder():
94
+ P = ProductOrder((grlex, lambda m: m[:2]), (grlex, lambda m: m[2:]))
95
+ assert P((1, 3, 3, 4, 5)) > P((2, 1, 5, 5, 5))
96
+ assert str(P) == "ProductOrder(grlex, grlex)"
97
+ assert P.is_global is True
98
+ assert ProductOrder((grlex, None), (ilex, None)).is_global is None
99
+ assert ProductOrder((igrlex, None), (ilex, None)).is_global is False
100
+
101
+ def test_monomial_key():
102
+ assert monomial_key() == lex
103
+
104
+ assert monomial_key('lex') == lex
105
+ assert monomial_key('grlex') == grlex
106
+ assert monomial_key('grevlex') == grevlex
107
+
108
+ raises(ValueError, lambda: monomial_key('foo'))
109
+ raises(ValueError, lambda: monomial_key(1))
110
+
111
+ M = [x, x**2*z**2, x*y, x**2, S.One, y**2, x**3, y, z, x*y**2*z, x**2*y**2]
112
+ assert sorted(M, key=monomial_key('lex', [z, y, x])) == \
113
+ [S.One, x, x**2, x**3, y, x*y, y**2, x**2*y**2, z, x*y**2*z, x**2*z**2]
114
+ assert sorted(M, key=monomial_key('grlex', [z, y, x])) == \
115
+ [S.One, x, y, z, x**2, x*y, y**2, x**3, x**2*y**2, x*y**2*z, x**2*z**2]
116
+ assert sorted(M, key=monomial_key('grevlex', [z, y, x])) == \
117
+ [S.One, x, y, z, x**2, x*y, y**2, x**3, x**2*y**2, x**2*z**2, x*y**2*z]
118
+
119
+ def test_build_product_order():
120
+ assert build_product_order((("grlex", x, y), ("grlex", z, t)), [x, y, z, t])((4, 5, 6, 7)) == \
121
+ ((9, (4, 5)), (13, (6, 7)))
122
+
123
+ assert build_product_order((("grlex", x, y), ("grlex", z, t)), [x, y, z, t]) == \
124
+ build_product_order((("grlex", x, y), ("grlex", z, t)), [x, y, z, t])
valley/lib/python3.10/site-packages/sympy/polys/tests/test_partfrac.py ADDED
@@ -0,0 +1,249 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Tests for algorithms for partial fraction decomposition of rational
2
+ functions. """
3
+
4
+ from sympy.polys.partfrac import (
5
+ apart_undetermined_coeffs,
6
+ apart,
7
+ apart_list, assemble_partfrac_list
8
+ )
9
+
10
+ from sympy.core.expr import Expr
11
+ from sympy.core.function import Lambda
12
+ from sympy.core.numbers import (E, I, Rational, pi, all_close)
13
+ from sympy.core.relational import Eq
14
+ from sympy.core.singleton import S
15
+ from sympy.core.symbol import (Dummy, Symbol)
16
+ from sympy.functions.elementary.miscellaneous import sqrt
17
+ from sympy.matrices.dense import Matrix
18
+ from sympy.polys.polytools import (Poly, factor)
19
+ from sympy.polys.rationaltools import together
20
+ from sympy.polys.rootoftools import RootSum
21
+ from sympy.testing.pytest import raises, XFAIL
22
+ from sympy.abc import x, y, a, b, c
23
+
24
+
25
+ def test_apart():
26
+ assert apart(1) == 1
27
+ assert apart(1, x) == 1
28
+
29
+ f, g = (x**2 + 1)/(x + 1), 2/(x + 1) + x - 1
30
+
31
+ assert apart(f, full=False) == g
32
+ assert apart(f, full=True) == g
33
+
34
+ f, g = 1/(x + 2)/(x + 1), 1/(1 + x) - 1/(2 + x)
35
+
36
+ assert apart(f, full=False) == g
37
+ assert apart(f, full=True) == g
38
+
39
+ f, g = 1/(x + 1)/(x + 5), -1/(5 + x)/4 + 1/(1 + x)/4
40
+
41
+ assert apart(f, full=False) == g
42
+ assert apart(f, full=True) == g
43
+
44
+ assert apart((E*x + 2)/(x - pi)*(x - 1), x) == \
45
+ 2 - E + E*pi + E*x + (E*pi + 2)*(pi - 1)/(x - pi)
46
+
47
+ assert apart(Eq((x**2 + 1)/(x + 1), x), x) == Eq(x - 1 + 2/(x + 1), x)
48
+
49
+ assert apart(x/2, y) == x/2
50
+
51
+ f, g = (x+y)/(2*x - y), Rational(3, 2)*y/(2*x - y) + S.Half
52
+
53
+ assert apart(f, x, full=False) == g
54
+ assert apart(f, x, full=True) == g
55
+
56
+ f, g = (x+y)/(2*x - y), 3*x/(2*x - y) - 1
57
+
58
+ assert apart(f, y, full=False) == g
59
+ assert apart(f, y, full=True) == g
60
+
61
+ raises(NotImplementedError, lambda: apart(1/(x + 1)/(y + 2)))
62
+
63
+
64
+ def test_apart_matrix():
65
+ M = Matrix(2, 2, lambda i, j: 1/(x + i + 1)/(x + j))
66
+
67
+ assert apart(M) == Matrix([
68
+ [1/x - 1/(x + 1), (x + 1)**(-2)],
69
+ [1/(2*x) - (S.Half)/(x + 2), 1/(x + 1) - 1/(x + 2)],
70
+ ])
71
+
72
+
73
+ def test_apart_symbolic():
74
+ f = a*x**4 + (2*b + 2*a*c)*x**3 + (4*b*c - a**2 + a*c**2)*x**2 + \
75
+ (-2*a*b + 2*b*c**2)*x - b**2
76
+ g = a**2*x**4 + (2*a*b + 2*c*a**2)*x**3 + (4*a*b*c + b**2 +
77
+ a**2*c**2)*x**2 + (2*c*b**2 + 2*a*b*c**2)*x + b**2*c**2
78
+
79
+ assert apart(f/g, x) == 1/a - 1/(x + c)**2 - b**2/(a*(a*x + b)**2)
80
+
81
+ assert apart(1/((x + a)*(x + b)*(x + c)), x) == \
82
+ 1/((a - c)*(b - c)*(c + x)) - 1/((a - b)*(b - c)*(b + x)) + \
83
+ 1/((a - b)*(a - c)*(a + x))
84
+
85
+
86
+ def _make_extension_example():
87
+ # https://github.com/sympy/sympy/issues/18531
88
+ from sympy.core import Mul
89
+ def mul2(expr):
90
+ # 2-arg mul hack...
91
+ return Mul(2, expr, evaluate=False)
92
+
93
+ f = ((x**2 + 1)**3/((x - 1)**2*(x + 1)**2*(-x**2 + 2*x + 1)*(x**2 + 2*x - 1)))
94
+ g = (1/mul2(x - sqrt(2) + 1)
95
+ - 1/mul2(x - sqrt(2) - 1)
96
+ + 1/mul2(x + 1 + sqrt(2))
97
+ - 1/mul2(x - 1 + sqrt(2))
98
+ + 1/mul2((x + 1)**2)
99
+ + 1/mul2((x - 1)**2))
100
+ return f, g
101
+
102
+
103
+ def test_apart_extension():
104
+ f = 2/(x**2 + 1)
105
+ g = I/(x + I) - I/(x - I)
106
+
107
+ assert apart(f, extension=I) == g
108
+ assert apart(f, gaussian=True) == g
109
+
110
+ f = x/((x - 2)*(x + I))
111
+
112
+ assert factor(together(apart(f)).expand()) == f
113
+
114
+ f, g = _make_extension_example()
115
+
116
+ # XXX: Only works with dotprodsimp. See test_apart_extension_xfail below
117
+ from sympy.matrices import dotprodsimp
118
+ with dotprodsimp(True):
119
+ assert apart(f, x, extension={sqrt(2)}) == g
120
+
121
+
122
+ def test_apart_extension_xfail():
123
+ f, g = _make_extension_example()
124
+ assert apart(f, x, extension={sqrt(2)}) == g
125
+
126
+
127
+ def test_apart_full():
128
+ f = 1/(x**2 + 1)
129
+
130
+ assert apart(f, full=False) == f
131
+ assert apart(f, full=True).dummy_eq(
132
+ -RootSum(x**2 + 1, Lambda(a, a/(x - a)), auto=False)/2)
133
+
134
+ f = 1/(x**3 + x + 1)
135
+
136
+ assert apart(f, full=False) == f
137
+ assert apart(f, full=True).dummy_eq(
138
+ RootSum(x**3 + x + 1,
139
+ Lambda(a, (a**2*Rational(6, 31) - a*Rational(9, 31) + Rational(4, 31))/(x - a)), auto=False))
140
+
141
+ f = 1/(x**5 + 1)
142
+
143
+ assert apart(f, full=False) == \
144
+ (Rational(-1, 5))*((x**3 - 2*x**2 + 3*x - 4)/(x**4 - x**3 + x**2 -
145
+ x + 1)) + (Rational(1, 5))/(x + 1)
146
+ assert apart(f, full=True).dummy_eq(
147
+ -RootSum(x**4 - x**3 + x**2 - x + 1,
148
+ Lambda(a, a/(x - a)), auto=False)/5 + (Rational(1, 5))/(x + 1))
149
+
150
+
151
+ def test_apart_full_floats():
152
+ # https://github.com/sympy/sympy/issues/26648
153
+ f = (
154
+ 6.43369157032015e-9*x**3 + 1.35203404799555e-5*x**2
155
+ + 0.00357538393743079*x + 0.085
156
+ )/(
157
+ 4.74334912634438e-11*x**4 + 4.09576274286244e-6*x**3
158
+ + 0.00334241812250921*x**2 + 0.15406018058983*x + 1.0
159
+ )
160
+
161
+ expected = (
162
+ 133.599202650992/(x + 85524.0054884464)
163
+ + 1.07757928431867/(x + 774.88576677949)
164
+ + 0.395006955518971/(x + 40.7977016133126)
165
+ + 0.564264854137341/(x + 7.79746609204661)
166
+ )
167
+
168
+ f_apart = apart(f, full=True).evalf()
169
+
170
+ # There is a significant floating point error in this operation.
171
+ assert all_close(f_apart, expected, rtol=1e-3, atol=1e-5)
172
+
173
+
174
+ def test_apart_undetermined_coeffs():
175
+ p = Poly(2*x - 3)
176
+ q = Poly(x**9 - x**8 - x**6 + x**5 - 2*x**2 + 3*x - 1)
177
+ r = (-x**7 - x**6 - x**5 + 4)/(x**8 - x**5 - 2*x + 1) + 1/(x - 1)
178
+
179
+ assert apart_undetermined_coeffs(p, q) == r
180
+
181
+ p = Poly(1, x, domain='ZZ[a,b]')
182
+ q = Poly((x + a)*(x + b), x, domain='ZZ[a,b]')
183
+ r = 1/((a - b)*(b + x)) - 1/((a - b)*(a + x))
184
+
185
+ assert apart_undetermined_coeffs(p, q) == r
186
+
187
+
188
+ def test_apart_list():
189
+ from sympy.utilities.iterables import numbered_symbols
190
+ def dummy_eq(i, j):
191
+ if type(i) in (list, tuple):
192
+ return all(dummy_eq(i, j) for i, j in zip(i, j))
193
+ return i == j or i.dummy_eq(j)
194
+
195
+ w0, w1, w2 = Symbol("w0"), Symbol("w1"), Symbol("w2")
196
+ _a = Dummy("a")
197
+
198
+ f = (-2*x - 2*x**2) / (3*x**2 - 6*x)
199
+ got = apart_list(f, x, dummies=numbered_symbols("w"))
200
+ ans = (-1, Poly(Rational(2, 3), x, domain='QQ'),
201
+ [(Poly(w0 - 2, w0, domain='ZZ'), Lambda(_a, 2), Lambda(_a, -_a + x), 1)])
202
+ assert dummy_eq(got, ans)
203
+
204
+ got = apart_list(2/(x**2-2), x, dummies=numbered_symbols("w"))
205
+ ans = (1, Poly(0, x, domain='ZZ'), [(Poly(w0**2 - 2, w0, domain='ZZ'),
206
+ Lambda(_a, _a/2),
207
+ Lambda(_a, -_a + x), 1)])
208
+ assert dummy_eq(got, ans)
209
+
210
+ f = 36 / (x**5 - 2*x**4 - 2*x**3 + 4*x**2 + x - 2)
211
+ got = apart_list(f, x, dummies=numbered_symbols("w"))
212
+ ans = (1, Poly(0, x, domain='ZZ'),
213
+ [(Poly(w0 - 2, w0, domain='ZZ'), Lambda(_a, 4), Lambda(_a, -_a + x), 1),
214
+ (Poly(w1**2 - 1, w1, domain='ZZ'), Lambda(_a, -3*_a - 6), Lambda(_a, -_a + x), 2),
215
+ (Poly(w2 + 1, w2, domain='ZZ'), Lambda(_a, -4), Lambda(_a, -_a + x), 1)])
216
+ assert dummy_eq(got, ans)
217
+
218
+
219
+ def test_assemble_partfrac_list():
220
+ f = 36 / (x**5 - 2*x**4 - 2*x**3 + 4*x**2 + x - 2)
221
+ pfd = apart_list(f)
222
+ assert assemble_partfrac_list(pfd) == -4/(x + 1) - 3/(x + 1)**2 - 9/(x - 1)**2 + 4/(x - 2)
223
+
224
+ a = Dummy("a")
225
+ pfd = (1, Poly(0, x, domain='ZZ'), [([sqrt(2),-sqrt(2)], Lambda(a, a/2), Lambda(a, -a + x), 1)])
226
+ assert assemble_partfrac_list(pfd) == -1/(sqrt(2)*(x + sqrt(2))) + 1/(sqrt(2)*(x - sqrt(2)))
227
+
228
+
229
+ @XFAIL
230
+ def test_noncommutative_pseudomultivariate():
231
+ # apart doesn't go inside noncommutative expressions
232
+ class foo(Expr):
233
+ is_commutative=False
234
+ e = x/(x + x*y)
235
+ c = 1/(1 + y)
236
+ assert apart(e + foo(e)) == c + foo(c)
237
+ assert apart(e*foo(e)) == c*foo(c)
238
+
239
+ def test_noncommutative():
240
+ class foo(Expr):
241
+ is_commutative=False
242
+ e = x/(x + x*y)
243
+ c = 1/(1 + y)
244
+ assert apart(e + foo()) == c + foo()
245
+
246
+ def test_issue_5798():
247
+ assert apart(
248
+ 2*x/(x**2 + 1) - (x - 1)/(2*(x**2 + 1)) + 1/(2*(x + 1)) - 2/x) == \
249
+ (3*x + 1)/(x**2 + 1)/2 + 1/(x + 1)/2 - 2/x
valley/lib/python3.10/site-packages/sympy/polys/tests/test_polyclasses.py ADDED
@@ -0,0 +1,588 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Tests for OO layer of several polynomial representations. """
2
+
3
+ from sympy.functions.elementary.miscellaneous import sqrt
4
+ from sympy.polys.domains import ZZ, QQ
5
+ from sympy.polys.polyclasses import DMP, DMF, ANP
6
+ from sympy.polys.polyerrors import (CoercionFailed, ExactQuotientFailed,
7
+ NotInvertible)
8
+ from sympy.polys.specialpolys import f_polys
9
+ from sympy.testing.pytest import raises, warns_deprecated_sympy
10
+
11
+ f_0, f_1, f_2, f_3, f_4, f_5, f_6 = [ f.to_dense() for f in f_polys() ]
12
+
13
+ def test_DMP___init__():
14
+ f = DMP([[ZZ(0)], [], [ZZ(0), ZZ(1), ZZ(2)], [ZZ(3)]], ZZ)
15
+
16
+ assert f._rep == [[1, 2], [3]]
17
+ assert f.dom == ZZ
18
+ assert f.lev == 1
19
+
20
+ f = DMP([[ZZ(1), ZZ(2)], [ZZ(3)]], ZZ, 1)
21
+
22
+ assert f._rep == [[1, 2], [3]]
23
+ assert f.dom == ZZ
24
+ assert f.lev == 1
25
+
26
+ f = DMP.from_dict({(1, 1): ZZ(1), (0, 0): ZZ(2)}, 1, ZZ)
27
+
28
+ assert f._rep == [[1, 0], [2]]
29
+ assert f.dom == ZZ
30
+ assert f.lev == 1
31
+
32
+
33
+ def test_DMP_rep_deprecation():
34
+ f = DMP([1, 2, 3], ZZ)
35
+
36
+ with warns_deprecated_sympy():
37
+ assert f.rep == [1, 2, 3]
38
+
39
+
40
+ def test_DMP___eq__():
41
+ assert DMP([[ZZ(1), ZZ(2)], [ZZ(3)]], ZZ) == \
42
+ DMP([[ZZ(1), ZZ(2)], [ZZ(3)]], ZZ)
43
+
44
+ assert DMP([[ZZ(1), ZZ(2)], [ZZ(3)]], ZZ) == \
45
+ DMP([[QQ(1), QQ(2)], [QQ(3)]], QQ)
46
+ assert DMP([[QQ(1), QQ(2)], [QQ(3)]], QQ) == \
47
+ DMP([[ZZ(1), ZZ(2)], [ZZ(3)]], ZZ)
48
+
49
+ assert DMP([[[ZZ(1)]]], ZZ) != DMP([[ZZ(1)]], ZZ)
50
+ assert DMP([[ZZ(1)]], ZZ) != DMP([[[ZZ(1)]]], ZZ)
51
+
52
+
53
+ def test_DMP___bool__():
54
+ assert bool(DMP([[]], ZZ)) is False
55
+ assert bool(DMP([[ZZ(1)]], ZZ)) is True
56
+
57
+
58
+ def test_DMP_to_dict():
59
+ f = DMP([[ZZ(3)], [], [ZZ(2)], [], [ZZ(8)]], ZZ)
60
+
61
+ assert f.to_dict() == \
62
+ {(4, 0): 3, (2, 0): 2, (0, 0): 8}
63
+ assert f.to_sympy_dict() == \
64
+ {(4, 0): ZZ.to_sympy(3), (2, 0): ZZ.to_sympy(2), (0, 0):
65
+ ZZ.to_sympy(8)}
66
+
67
+
68
+ def test_DMP_properties():
69
+ assert DMP([[]], ZZ).is_zero is True
70
+ assert DMP([[ZZ(1)]], ZZ).is_zero is False
71
+
72
+ assert DMP([[ZZ(1)]], ZZ).is_one is True
73
+ assert DMP([[ZZ(2)]], ZZ).is_one is False
74
+
75
+ assert DMP([[ZZ(1)]], ZZ).is_ground is True
76
+ assert DMP([[ZZ(1)], [ZZ(2)], [ZZ(1)]], ZZ).is_ground is False
77
+
78
+ assert DMP([[ZZ(1)], [ZZ(2), ZZ(0)], [ZZ(1), ZZ(0)]], ZZ).is_sqf is True
79
+ assert DMP([[ZZ(1)], [ZZ(2), ZZ(0)], [ZZ(1), ZZ(0), ZZ(0)]], ZZ).is_sqf is False
80
+
81
+ assert DMP([[ZZ(1), ZZ(2)], [ZZ(3)]], ZZ).is_monic is True
82
+ assert DMP([[ZZ(2), ZZ(2)], [ZZ(3)]], ZZ).is_monic is False
83
+
84
+ assert DMP([[ZZ(1), ZZ(2)], [ZZ(3)]], ZZ).is_primitive is True
85
+ assert DMP([[ZZ(2), ZZ(4)], [ZZ(6)]], ZZ).is_primitive is False
86
+
87
+
88
+ def test_DMP_arithmetics():
89
+ f = DMP([[ZZ(2)], [ZZ(2), ZZ(0)]], ZZ)
90
+
91
+ assert f.mul_ground(2) == DMP([[ZZ(4)], [ZZ(4), ZZ(0)]], ZZ)
92
+ assert f.quo_ground(2) == DMP([[ZZ(1)], [ZZ(1), ZZ(0)]], ZZ)
93
+
94
+ raises(ExactQuotientFailed, lambda: f.exquo_ground(3))
95
+
96
+ f = DMP([[ZZ(-5)]], ZZ)
97
+ g = DMP([[ZZ(5)]], ZZ)
98
+
99
+ assert f.abs() == g
100
+ assert abs(f) == g
101
+
102
+ assert g.neg() == f
103
+ assert -g == f
104
+
105
+ h = DMP([[]], ZZ)
106
+
107
+ assert f.add(g) == h
108
+ assert f + g == h
109
+ assert g + f == h
110
+ assert f + 5 == h
111
+ assert 5 + f == h
112
+
113
+ h = DMP([[ZZ(-10)]], ZZ)
114
+
115
+ assert f.sub(g) == h
116
+ assert f - g == h
117
+ assert g - f == -h
118
+ assert f - 5 == h
119
+ assert 5 - f == -h
120
+
121
+ h = DMP([[ZZ(-25)]], ZZ)
122
+
123
+ assert f.mul(g) == h
124
+ assert f * g == h
125
+ assert g * f == h
126
+ assert f * 5 == h
127
+ assert 5 * f == h
128
+
129
+ h = DMP([[ZZ(25)]], ZZ)
130
+
131
+ assert f.sqr() == h
132
+ assert f.pow(2) == h
133
+ assert f**2 == h
134
+
135
+ raises(TypeError, lambda: f.pow('x'))
136
+
137
+ f = DMP([[ZZ(1)], [], [ZZ(1), ZZ(0), ZZ(0)]], ZZ)
138
+ g = DMP([[ZZ(2)], [ZZ(-2), ZZ(0)]], ZZ)
139
+
140
+ q = DMP([[ZZ(2)], [ZZ(2), ZZ(0)]], ZZ)
141
+ r = DMP([[ZZ(8), ZZ(0), ZZ(0)]], ZZ)
142
+
143
+ assert f.pdiv(g) == (q, r)
144
+ assert f.pquo(g) == q
145
+ assert f.prem(g) == r
146
+
147
+ raises(ExactQuotientFailed, lambda: f.pexquo(g))
148
+
149
+ f = DMP([[ZZ(1)], [], [ZZ(1), ZZ(0), ZZ(0)]], ZZ)
150
+ g = DMP([[ZZ(1)], [ZZ(-1), ZZ(0)]], ZZ)
151
+
152
+ q = DMP([[ZZ(1)], [ZZ(1), ZZ(0)]], ZZ)
153
+ r = DMP([[ZZ(2), ZZ(0), ZZ(0)]], ZZ)
154
+
155
+ assert f.div(g) == (q, r)
156
+ assert f.quo(g) == q
157
+ assert f.rem(g) == r
158
+
159
+ assert divmod(f, g) == (q, r)
160
+ assert f // g == q
161
+ assert f % g == r
162
+
163
+ raises(ExactQuotientFailed, lambda: f.exquo(g))
164
+
165
+ f = DMP([ZZ(1), ZZ(0), ZZ(-1)], ZZ)
166
+ g = DMP([ZZ(2), ZZ(-2)], ZZ)
167
+
168
+ q = DMP([], ZZ)
169
+ r = f
170
+
171
+ pq = DMP([ZZ(2), ZZ(2)], ZZ)
172
+ pr = DMP([], ZZ)
173
+
174
+ assert f.div(g) == (q, r)
175
+ assert f.quo(g) == q
176
+ assert f.rem(g) == r
177
+
178
+ assert divmod(f, g) == (q, r)
179
+ assert f // g == q
180
+ assert f % g == r
181
+
182
+ raises(ExactQuotientFailed, lambda: f.exquo(g))
183
+
184
+ assert f.pdiv(g) == (pq, pr)
185
+ assert f.pquo(g) == pq
186
+ assert f.prem(g) == pr
187
+ assert f.pexquo(g) == pq
188
+
189
+
190
+ def test_DMP_functionality():
191
+ f = DMP([[ZZ(1)], [ZZ(2), ZZ(0)], [ZZ(1), ZZ(0), ZZ(0)]], ZZ)
192
+ g = DMP([[ZZ(1)], [ZZ(1), ZZ(0)]], ZZ)
193
+ h = DMP([[ZZ(1)]], ZZ)
194
+
195
+ assert f.degree() == 2
196
+ assert f.degree_list() == (2, 2)
197
+ assert f.total_degree() == 2
198
+
199
+ assert f.LC() == ZZ(1)
200
+ assert f.TC() == ZZ(0)
201
+ assert f.nth(1, 1) == ZZ(2)
202
+
203
+ raises(TypeError, lambda: f.nth(0, 'x'))
204
+
205
+ assert f.max_norm() == 2
206
+ assert f.l1_norm() == 4
207
+
208
+ u = DMP([[ZZ(2)], [ZZ(2), ZZ(0)]], ZZ)
209
+
210
+ assert f.diff(m=1, j=0) == u
211
+ assert f.diff(m=1, j=1) == u
212
+
213
+ raises(TypeError, lambda: f.diff(m='x', j=0))
214
+
215
+ u = DMP([ZZ(1), ZZ(2), ZZ(1)], ZZ)
216
+ v = DMP([ZZ(1), ZZ(2), ZZ(1)], ZZ)
217
+
218
+ assert f.eval(a=1, j=0) == u
219
+ assert f.eval(a=1, j=1) == v
220
+
221
+ assert f.eval(1).eval(1) == ZZ(4)
222
+
223
+ assert f.cofactors(g) == (g, g, h)
224
+ assert f.gcd(g) == g
225
+ assert f.lcm(g) == f
226
+
227
+ u = DMP([[QQ(45), QQ(30), QQ(5)]], QQ)
228
+ v = DMP([[QQ(1), QQ(2, 3), QQ(1, 9)]], QQ)
229
+
230
+ assert u.monic() == v
231
+
232
+ assert (4*f).content() == ZZ(4)
233
+ assert (4*f).primitive() == (ZZ(4), f)
234
+
235
+ f = DMP([QQ(1,3), QQ(1)], QQ)
236
+ g = DMP([QQ(1,7), QQ(1)], QQ)
237
+
238
+ assert f.cancel(g) == f.cancel(g, include=True) == (
239
+ DMP([QQ(7), QQ(21)], QQ),
240
+ DMP([QQ(3), QQ(21)], QQ)
241
+ )
242
+ assert f.cancel(g, include=False) == (
243
+ QQ(7),
244
+ QQ(3),
245
+ DMP([QQ(1), QQ(3)], QQ),
246
+ DMP([QQ(1), QQ(7)], QQ)
247
+ )
248
+
249
+ f = DMP([[ZZ(1)], [ZZ(2)], [ZZ(3)], [ZZ(4)], [ZZ(5)], [ZZ(6)]], ZZ)
250
+
251
+ assert f.trunc(3) == DMP([[ZZ(1)], [ZZ(-1)], [], [ZZ(1)], [ZZ(-1)], []], ZZ)
252
+
253
+ f = DMP(f_4, ZZ)
254
+
255
+ assert f.sqf_part() == -f
256
+ assert f.sqf_list() == (ZZ(-1), [(-f, 1)])
257
+
258
+ f = DMP([[ZZ(-1)], [], [], [ZZ(5)]], ZZ)
259
+ g = DMP([[ZZ(3), ZZ(1)], [], []], ZZ)
260
+ h = DMP([[ZZ(45), ZZ(30), ZZ(5)]], ZZ)
261
+
262
+ r = DMP([ZZ(675), ZZ(675), ZZ(225), ZZ(25)], ZZ)
263
+
264
+ assert f.subresultants(g) == [f, g, h]
265
+ assert f.resultant(g) == r
266
+
267
+ f = DMP([ZZ(1), ZZ(3), ZZ(9), ZZ(-13)], ZZ)
268
+
269
+ assert f.discriminant() == -11664
270
+
271
+ f = DMP([QQ(2), QQ(0)], QQ)
272
+ g = DMP([QQ(1), QQ(0), QQ(-16)], QQ)
273
+
274
+ s = DMP([QQ(1, 32), QQ(0)], QQ)
275
+ t = DMP([QQ(-1, 16)], QQ)
276
+ h = DMP([QQ(1)], QQ)
277
+
278
+ assert f.half_gcdex(g) == (s, h)
279
+ assert f.gcdex(g) == (s, t, h)
280
+
281
+ assert f.invert(g) == s
282
+
283
+ f = DMP([[QQ(1)], [QQ(2)], [QQ(3)]], QQ)
284
+
285
+ raises(ValueError, lambda: f.half_gcdex(f))
286
+ raises(ValueError, lambda: f.gcdex(f))
287
+
288
+ raises(ValueError, lambda: f.invert(f))
289
+
290
+ f = DMP(ZZ.map([1, 0, 20, 0, 150, 0, 500, 0, 625, -2, 0, -10, 9]), ZZ)
291
+ g = DMP([ZZ(1), ZZ(0), ZZ(0), ZZ(-2), ZZ(9)], ZZ)
292
+ h = DMP([ZZ(1), ZZ(0), ZZ(5), ZZ(0)], ZZ)
293
+
294
+ assert g.compose(h) == f
295
+ assert f.decompose() == [g, h]
296
+
297
+ f = DMP([[QQ(1)], [QQ(2)], [QQ(3)]], QQ)
298
+
299
+ raises(ValueError, lambda: f.decompose())
300
+ raises(ValueError, lambda: f.sturm())
301
+
302
+
303
+ def test_DMP_exclude():
304
+ f = [[[[[[[[[[[[[[[[[[[[[[[[[[ZZ(1)]], [[]]]]]]]]]]]]]]]]]]]]]]]]]]
305
+ J = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
306
+ 18, 19, 20, 21, 22, 24, 25]
307
+
308
+ assert DMP(f, ZZ).exclude() == (J, DMP([ZZ(1), ZZ(0)], ZZ))
309
+ assert DMP([[ZZ(1)], [ZZ(1), ZZ(0)]], ZZ).exclude() ==\
310
+ ([], DMP([[ZZ(1)], [ZZ(1), ZZ(0)]], ZZ))
311
+
312
+
313
+ def test_DMF__init__():
314
+ f = DMF(([[0], [], [0, 1, 2], [3]], [[1, 2, 3]]), ZZ)
315
+
316
+ assert f.num == [[1, 2], [3]]
317
+ assert f.den == [[1, 2, 3]]
318
+ assert f.lev == 1
319
+ assert f.dom == ZZ
320
+
321
+ f = DMF(([[1, 2], [3]], [[1, 2, 3]]), ZZ, 1)
322
+
323
+ assert f.num == [[1, 2], [3]]
324
+ assert f.den == [[1, 2, 3]]
325
+ assert f.lev == 1
326
+ assert f.dom == ZZ
327
+
328
+ f = DMF(([[-1], [-2]], [[3], [-4]]), ZZ)
329
+
330
+ assert f.num == [[-1], [-2]]
331
+ assert f.den == [[3], [-4]]
332
+ assert f.lev == 1
333
+ assert f.dom == ZZ
334
+
335
+ f = DMF(([[1], [2]], [[-3], [4]]), ZZ)
336
+
337
+ assert f.num == [[-1], [-2]]
338
+ assert f.den == [[3], [-4]]
339
+ assert f.lev == 1
340
+ assert f.dom == ZZ
341
+
342
+ f = DMF(([[1], [2]], [[-3], [4]]), ZZ)
343
+
344
+ assert f.num == [[-1], [-2]]
345
+ assert f.den == [[3], [-4]]
346
+ assert f.lev == 1
347
+ assert f.dom == ZZ
348
+
349
+ f = DMF(([[]], [[-3], [4]]), ZZ)
350
+
351
+ assert f.num == [[]]
352
+ assert f.den == [[1]]
353
+ assert f.lev == 1
354
+ assert f.dom == ZZ
355
+
356
+ f = DMF(17, ZZ, 1)
357
+
358
+ assert f.num == [[17]]
359
+ assert f.den == [[1]]
360
+ assert f.lev == 1
361
+ assert f.dom == ZZ
362
+
363
+ f = DMF(([[1], [2]]), ZZ)
364
+
365
+ assert f.num == [[1], [2]]
366
+ assert f.den == [[1]]
367
+ assert f.lev == 1
368
+ assert f.dom == ZZ
369
+
370
+ f = DMF([[0], [], [0, 1, 2], [3]], ZZ)
371
+
372
+ assert f.num == [[1, 2], [3]]
373
+ assert f.den == [[1]]
374
+ assert f.lev == 1
375
+ assert f.dom == ZZ
376
+
377
+ f = DMF({(1, 1): 1, (0, 0): 2}, ZZ, 1)
378
+
379
+ assert f.num == [[1, 0], [2]]
380
+ assert f.den == [[1]]
381
+ assert f.lev == 1
382
+ assert f.dom == ZZ
383
+
384
+ f = DMF(([[QQ(1)], [QQ(2)]], [[-QQ(3)], [QQ(4)]]), QQ)
385
+
386
+ assert f.num == [[-QQ(1)], [-QQ(2)]]
387
+ assert f.den == [[QQ(3)], [-QQ(4)]]
388
+ assert f.lev == 1
389
+ assert f.dom == QQ
390
+
391
+ f = DMF(([[QQ(1, 5)], [QQ(2, 5)]], [[-QQ(3, 7)], [QQ(4, 7)]]), QQ)
392
+
393
+ assert f.num == [[-QQ(7)], [-QQ(14)]]
394
+ assert f.den == [[QQ(15)], [-QQ(20)]]
395
+ assert f.lev == 1
396
+ assert f.dom == QQ
397
+
398
+ raises(ValueError, lambda: DMF(([1], [[1]]), ZZ))
399
+ raises(ZeroDivisionError, lambda: DMF(([1], []), ZZ))
400
+
401
+
402
+ def test_DMF__bool__():
403
+ assert bool(DMF([[]], ZZ)) is False
404
+ assert bool(DMF([[1]], ZZ)) is True
405
+
406
+
407
+ def test_DMF_properties():
408
+ assert DMF([[]], ZZ).is_zero is True
409
+ assert DMF([[]], ZZ).is_one is False
410
+
411
+ assert DMF([[1]], ZZ).is_zero is False
412
+ assert DMF([[1]], ZZ).is_one is True
413
+
414
+ assert DMF(([[1]], [[2]]), ZZ).is_one is False
415
+
416
+
417
+ def test_DMF_arithmetics():
418
+ f = DMF([[7], [-9]], ZZ)
419
+ g = DMF([[-7], [9]], ZZ)
420
+
421
+ assert f.neg() == -f == g
422
+
423
+ f = DMF(([[1]], [[1], []]), ZZ)
424
+ g = DMF(([[1]], [[1, 0]]), ZZ)
425
+
426
+ h = DMF(([[1], [1, 0]], [[1, 0], []]), ZZ)
427
+
428
+ assert f.add(g) == f + g == h
429
+ assert g.add(f) == g + f == h
430
+
431
+ h = DMF(([[-1], [1, 0]], [[1, 0], []]), ZZ)
432
+
433
+ assert f.sub(g) == f - g == h
434
+
435
+ h = DMF(([[1]], [[1, 0], []]), ZZ)
436
+
437
+ assert f.mul(g) == f*g == h
438
+ assert g.mul(f) == g*f == h
439
+
440
+ h = DMF(([[1, 0]], [[1], []]), ZZ)
441
+
442
+ assert f.quo(g) == f/g == h
443
+
444
+ h = DMF(([[1]], [[1], [], [], []]), ZZ)
445
+
446
+ assert f.pow(3) == f**3 == h
447
+
448
+ h = DMF(([[1]], [[1, 0, 0, 0]]), ZZ)
449
+
450
+ assert g.pow(3) == g**3 == h
451
+
452
+ h = DMF(([[1, 0]], [[1]]), ZZ)
453
+
454
+ assert g.pow(-1) == g**-1 == h
455
+
456
+
457
+ def test_ANP___init__():
458
+ rep = [QQ(1), QQ(1)]
459
+ mod = [QQ(1), QQ(0), QQ(1)]
460
+
461
+ f = ANP(rep, mod, QQ)
462
+
463
+ assert f.to_list() == [QQ(1), QQ(1)]
464
+ assert f.mod_to_list() == [QQ(1), QQ(0), QQ(1)]
465
+ assert f.dom == QQ
466
+
467
+ rep = {1: QQ(1), 0: QQ(1)}
468
+ mod = {2: QQ(1), 0: QQ(1)}
469
+
470
+ f = ANP(rep, mod, QQ)
471
+
472
+ assert f.to_list() == [QQ(1), QQ(1)]
473
+ assert f.mod_to_list() == [QQ(1), QQ(0), QQ(1)]
474
+ assert f.dom == QQ
475
+
476
+ f = ANP(1, mod, QQ)
477
+
478
+ assert f.to_list() == [QQ(1)]
479
+ assert f.mod_to_list() == [QQ(1), QQ(0), QQ(1)]
480
+ assert f.dom == QQ
481
+
482
+ f = ANP([1, 0.5], mod, QQ)
483
+
484
+ assert all(QQ.of_type(a) for a in f.to_list())
485
+
486
+ raises(CoercionFailed, lambda: ANP([sqrt(2)], mod, QQ))
487
+
488
+
489
+ def test_ANP___eq__():
490
+ a = ANP([QQ(1), QQ(1)], [QQ(1), QQ(0), QQ(1)], QQ)
491
+ b = ANP([QQ(1), QQ(1)], [QQ(1), QQ(0), QQ(2)], QQ)
492
+
493
+ assert (a == a) is True
494
+ assert (a != a) is False
495
+
496
+ assert (a == b) is False
497
+ assert (a != b) is True
498
+
499
+ b = ANP([QQ(1), QQ(2)], [QQ(1), QQ(0), QQ(1)], QQ)
500
+
501
+ assert (a == b) is False
502
+ assert (a != b) is True
503
+
504
+
505
+ def test_ANP___bool__():
506
+ assert bool(ANP([], [QQ(1), QQ(0), QQ(1)], QQ)) is False
507
+ assert bool(ANP([QQ(1)], [QQ(1), QQ(0), QQ(1)], QQ)) is True
508
+
509
+
510
+ def test_ANP_properties():
511
+ mod = [QQ(1), QQ(0), QQ(1)]
512
+
513
+ assert ANP([QQ(0)], mod, QQ).is_zero is True
514
+ assert ANP([QQ(1)], mod, QQ).is_zero is False
515
+
516
+ assert ANP([QQ(1)], mod, QQ).is_one is True
517
+ assert ANP([QQ(2)], mod, QQ).is_one is False
518
+
519
+
520
+ def test_ANP_arithmetics():
521
+ mod = [QQ(1), QQ(0), QQ(0), QQ(-2)]
522
+
523
+ a = ANP([QQ(2), QQ(-1), QQ(1)], mod, QQ)
524
+ b = ANP([QQ(1), QQ(2)], mod, QQ)
525
+
526
+ c = ANP([QQ(-2), QQ(1), QQ(-1)], mod, QQ)
527
+
528
+ assert a.neg() == -a == c
529
+
530
+ c = ANP([QQ(2), QQ(0), QQ(3)], mod, QQ)
531
+
532
+ assert a.add(b) == a + b == c
533
+ assert b.add(a) == b + a == c
534
+
535
+ c = ANP([QQ(2), QQ(-2), QQ(-1)], mod, QQ)
536
+
537
+ assert a.sub(b) == a - b == c
538
+
539
+ c = ANP([QQ(-2), QQ(2), QQ(1)], mod, QQ)
540
+
541
+ assert b.sub(a) == b - a == c
542
+
543
+ c = ANP([QQ(3), QQ(-1), QQ(6)], mod, QQ)
544
+
545
+ assert a.mul(b) == a*b == c
546
+ assert b.mul(a) == b*a == c
547
+
548
+ c = ANP([QQ(-1, 43), QQ(9, 43), QQ(5, 43)], mod, QQ)
549
+
550
+ assert a.pow(0) == a**(0) == ANP(1, mod, QQ)
551
+ assert a.pow(1) == a**(1) == a
552
+
553
+ assert a.pow(-1) == a**(-1) == c
554
+
555
+ assert a.quo(a) == a.mul(a.pow(-1)) == a*a**(-1) == ANP(1, mod, QQ)
556
+
557
+ c = ANP([], [1, 0, 0, -2], QQ)
558
+ r1 = a.rem(b)
559
+
560
+ (q, r2) = a.div(b)
561
+
562
+ assert r1 == r2 == c == a % b
563
+
564
+ raises(NotInvertible, lambda: a.div(c))
565
+ raises(NotInvertible, lambda: a.rem(c))
566
+
567
+ # Comparison with "hard-coded" value fails despite looking identical
568
+ # from sympy import Rational
569
+ # c = ANP([Rational(11, 10), Rational(-1, 5), Rational(-3, 5)], [1, 0, 0, -2], QQ)
570
+
571
+ assert q == a/b # == c
572
+
573
+ def test_ANP_unify():
574
+ mod_z = [ZZ(1), ZZ(0), ZZ(-2)]
575
+ mod_q = [QQ(1), QQ(0), QQ(-2)]
576
+
577
+ a = ANP([QQ(1)], mod_q, QQ)
578
+ b = ANP([ZZ(1)], mod_z, ZZ)
579
+
580
+ assert a.unify(b)[0] == QQ
581
+ assert b.unify(a)[0] == QQ
582
+ assert a.unify(a)[0] == QQ
583
+ assert b.unify(b)[0] == ZZ
584
+
585
+ assert a.unify_ANP(b)[-1] == QQ
586
+ assert b.unify_ANP(a)[-1] == QQ
587
+ assert a.unify_ANP(a)[-1] == QQ
588
+ assert b.unify_ANP(b)[-1] == ZZ
valley/lib/python3.10/site-packages/sympy/polys/tests/test_polyroots.py ADDED
@@ -0,0 +1,758 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Tests for algorithms for computing symbolic roots of polynomials. """
2
+
3
+ from sympy.core.numbers import (I, Rational, pi)
4
+ from sympy.core.singleton import S
5
+ from sympy.core.symbol import (Symbol, Wild, symbols)
6
+ from sympy.functions.elementary.complexes import (conjugate, im, re)
7
+ from sympy.functions.elementary.exponential import exp
8
+ from sympy.functions.elementary.miscellaneous import (root, sqrt)
9
+ from sympy.functions.elementary.piecewise import Piecewise
10
+ from sympy.functions.elementary.trigonometric import (acos, cos, sin)
11
+ from sympy.polys.domains.integerring import ZZ
12
+ from sympy.sets.sets import Interval
13
+ from sympy.simplify.powsimp import powsimp
14
+
15
+ from sympy.polys import Poly, cyclotomic_poly, intervals, nroots, rootof
16
+
17
+ from sympy.polys.polyroots import (root_factors, roots_linear,
18
+ roots_quadratic, roots_cubic, roots_quartic, roots_quintic,
19
+ roots_cyclotomic, roots_binomial, preprocess_roots, roots)
20
+
21
+ from sympy.polys.orthopolys import legendre_poly
22
+ from sympy.polys.polyerrors import PolynomialError, \
23
+ UnsolvableFactorError
24
+ from sympy.polys.polyutils import _nsort
25
+
26
+ from sympy.testing.pytest import raises, slow
27
+ from sympy.core.random import verify_numerically
28
+ import mpmath
29
+ from itertools import product
30
+
31
+
32
+
33
+ a, b, c, d, e, q, t, x, y, z = symbols('a,b,c,d,e,q,t,x,y,z')
34
+
35
+
36
+ def _check(roots):
37
+ # this is the desired invariant for roots returned
38
+ # by all_roots. It is trivially true for linear
39
+ # polynomials.
40
+ nreal = sum(1 if i.is_real else 0 for i in roots)
41
+ assert sorted(roots[:nreal]) == list(roots[:nreal])
42
+ for ix in range(nreal, len(roots), 2):
43
+ if not (
44
+ roots[ix + 1] == roots[ix] or
45
+ roots[ix + 1] == conjugate(roots[ix])):
46
+ return False
47
+ return True
48
+
49
+
50
+ def test_roots_linear():
51
+ assert roots_linear(Poly(2*x + 1, x)) == [Rational(-1, 2)]
52
+
53
+
54
+ def test_roots_quadratic():
55
+ assert roots_quadratic(Poly(2*x**2, x)) == [0, 0]
56
+ assert roots_quadratic(Poly(2*x**2 + 3*x, x)) == [Rational(-3, 2), 0]
57
+ assert roots_quadratic(Poly(2*x**2 + 3, x)) == [-I*sqrt(6)/2, I*sqrt(6)/2]
58
+ assert roots_quadratic(Poly(2*x**2 + 4*x + 3, x)) == [-1 - I*sqrt(2)/2, -1 + I*sqrt(2)/2]
59
+ _check(Poly(2*x**2 + 4*x + 3, x).all_roots())
60
+
61
+ f = x**2 + (2*a*e + 2*c*e)/(a - c)*x + (d - b + a*e**2 - c*e**2)/(a - c)
62
+ assert roots_quadratic(Poly(f, x)) == \
63
+ [-e*(a + c)/(a - c) - sqrt(a*b + c*d - a*d - b*c + 4*a*c*e**2)/(a - c),
64
+ -e*(a + c)/(a - c) + sqrt(a*b + c*d - a*d - b*c + 4*a*c*e**2)/(a - c)]
65
+
66
+ # check for simplification
67
+ f = Poly(y*x**2 - 2*x - 2*y, x)
68
+ assert roots_quadratic(f) == \
69
+ [-sqrt(2*y**2 + 1)/y + 1/y, sqrt(2*y**2 + 1)/y + 1/y]
70
+ f = Poly(x**2 + (-y**2 - 2)*x + y**2 + 1, x)
71
+ assert roots_quadratic(f) == \
72
+ [1,y**2 + 1]
73
+
74
+ f = Poly(sqrt(2)*x**2 - 1, x)
75
+ r = roots_quadratic(f)
76
+ assert r == _nsort(r)
77
+
78
+ # issue 8255
79
+ f = Poly(-24*x**2 - 180*x + 264)
80
+ assert [w.n(2) for w in f.all_roots(radicals=True)] == \
81
+ [w.n(2) for w in f.all_roots(radicals=False)]
82
+ for _a, _b, _c in product((-2, 2), (-2, 2), (0, -1)):
83
+ f = Poly(_a*x**2 + _b*x + _c)
84
+ roots = roots_quadratic(f)
85
+ assert roots == _nsort(roots)
86
+
87
+
88
+ def test_issue_7724():
89
+ eq = Poly(x**4*I + x**2 + I, x)
90
+ assert roots(eq) == {
91
+ sqrt(I/2 + sqrt(5)*I/2): 1,
92
+ sqrt(-sqrt(5)*I/2 + I/2): 1,
93
+ -sqrt(I/2 + sqrt(5)*I/2): 1,
94
+ -sqrt(-sqrt(5)*I/2 + I/2): 1}
95
+
96
+
97
+ def test_issue_8438():
98
+ p = Poly([1, y, -2, -3], x).as_expr()
99
+ roots = roots_cubic(Poly(p, x), x)
100
+ z = Rational(-3, 2) - I*7/2 # this will fail in code given in commit msg
101
+ post = [r.subs(y, z) for r in roots]
102
+ assert set(post) == \
103
+ set(roots_cubic(Poly(p.subs(y, z), x)))
104
+ # /!\ if p is not made an expression, this is *very* slow
105
+ assert all(p.subs({y: z, x: i}).n(2, chop=True) == 0 for i in post)
106
+
107
+
108
+ def test_issue_8285():
109
+ roots = (Poly(4*x**8 - 1, x)*Poly(x**2 + 1)).all_roots()
110
+ assert _check(roots)
111
+ f = Poly(x**4 + 5*x**2 + 6, x)
112
+ ro = [rootof(f, i) for i in range(4)]
113
+ roots = Poly(x**4 + 5*x**2 + 6, x).all_roots()
114
+ assert roots == ro
115
+ assert _check(roots)
116
+ # more than 2 complex roots from which to identify the
117
+ # imaginary ones
118
+ roots = Poly(2*x**8 - 1).all_roots()
119
+ assert _check(roots)
120
+ assert len(Poly(2*x**10 - 1).all_roots()) == 10 # doesn't fail
121
+
122
+
123
+ def test_issue_8289():
124
+ roots = (Poly(x**2 + 2)*Poly(x**4 + 2)).all_roots()
125
+ assert _check(roots)
126
+ roots = Poly(x**6 + 3*x**3 + 2, x).all_roots()
127
+ assert _check(roots)
128
+ roots = Poly(x**6 - x + 1).all_roots()
129
+ assert _check(roots)
130
+ # all imaginary roots with multiplicity of 2
131
+ roots = Poly(x**4 + 4*x**2 + 4, x).all_roots()
132
+ assert _check(roots)
133
+
134
+
135
+ def test_issue_14291():
136
+ assert Poly(((x - 1)**2 + 1)*((x - 1)**2 + 2)*(x - 1)
137
+ ).all_roots() == [1, 1 - I, 1 + I, 1 - sqrt(2)*I, 1 + sqrt(2)*I]
138
+ p = x**4 + 10*x**2 + 1
139
+ ans = [rootof(p, i) for i in range(4)]
140
+ assert Poly(p).all_roots() == ans
141
+ _check(ans)
142
+
143
+
144
+ def test_issue_13340():
145
+ eq = Poly(y**3 + exp(x)*y + x, y, domain='EX')
146
+ roots_d = roots(eq)
147
+ assert len(roots_d) == 3
148
+
149
+
150
+ def test_issue_14522():
151
+ eq = Poly(x**4 + x**3*(16 + 32*I) + x**2*(-285 + 386*I) + x*(-2824 - 448*I) - 2058 - 6053*I, x)
152
+ roots_eq = roots(eq)
153
+ assert all(eq(r) == 0 for r in roots_eq)
154
+
155
+
156
+ def test_issue_15076():
157
+ sol = roots_quartic(Poly(t**4 - 6*t**2 + t/x - 3, t))
158
+ assert sol[0].has(x)
159
+
160
+
161
+ def test_issue_16589():
162
+ eq = Poly(x**4 - 8*sqrt(2)*x**3 + 4*x**3 - 64*sqrt(2)*x**2 + 1024*x, x)
163
+ roots_eq = roots(eq)
164
+ assert 0 in roots_eq
165
+
166
+
167
+ def test_roots_cubic():
168
+ assert roots_cubic(Poly(2*x**3, x)) == [0, 0, 0]
169
+ assert roots_cubic(Poly(x**3 - 3*x**2 + 3*x - 1, x)) == [1, 1, 1]
170
+
171
+ # valid for arbitrary y (issue 21263)
172
+ r = root(y, 3)
173
+ assert roots_cubic(Poly(x**3 - y, x)) == [r,
174
+ r*(-S.Half + sqrt(3)*I/2),
175
+ r*(-S.Half - sqrt(3)*I/2)]
176
+ # simpler form when y is negative
177
+ assert roots_cubic(Poly(x**3 - -1, x)) == \
178
+ [-1, S.Half - I*sqrt(3)/2, S.Half + I*sqrt(3)/2]
179
+ assert roots_cubic(Poly(2*x**3 - 3*x**2 - 3*x - 1, x))[0] == \
180
+ S.Half + 3**Rational(1, 3)/2 + 3**Rational(2, 3)/2
181
+ eq = -x**3 + 2*x**2 + 3*x - 2
182
+ assert roots(eq, trig=True, multiple=True) == \
183
+ roots_cubic(Poly(eq, x), trig=True) == [
184
+ Rational(2, 3) + 2*sqrt(13)*cos(acos(8*sqrt(13)/169)/3)/3,
185
+ -2*sqrt(13)*sin(-acos(8*sqrt(13)/169)/3 + pi/6)/3 + Rational(2, 3),
186
+ -2*sqrt(13)*cos(-acos(8*sqrt(13)/169)/3 + pi/3)/3 + Rational(2, 3),
187
+ ]
188
+
189
+
190
+ def test_roots_quartic():
191
+ assert roots_quartic(Poly(x**4, x)) == [0, 0, 0, 0]
192
+ assert roots_quartic(Poly(x**4 + x**3, x)) in [
193
+ [-1, 0, 0, 0],
194
+ [0, -1, 0, 0],
195
+ [0, 0, -1, 0],
196
+ [0, 0, 0, -1]
197
+ ]
198
+ assert roots_quartic(Poly(x**4 - x**3, x)) in [
199
+ [1, 0, 0, 0],
200
+ [0, 1, 0, 0],
201
+ [0, 0, 1, 0],
202
+ [0, 0, 0, 1]
203
+ ]
204
+
205
+ lhs = roots_quartic(Poly(x**4 + x, x))
206
+ rhs = [S.Half + I*sqrt(3)/2, S.Half - I*sqrt(3)/2, S.Zero, -S.One]
207
+
208
+ assert sorted(lhs, key=hash) == sorted(rhs, key=hash)
209
+
210
+ # test of all branches of roots quartic
211
+ for i, (a, b, c, d) in enumerate([(1, 2, 3, 0),
212
+ (3, -7, -9, 9),
213
+ (1, 2, 3, 4),
214
+ (1, 2, 3, 4),
215
+ (-7, -3, 3, -6),
216
+ (-3, 5, -6, -4),
217
+ (6, -5, -10, -3)]):
218
+ if i == 2:
219
+ c = -a*(a**2/S(8) - b/S(2))
220
+ elif i == 3:
221
+ d = a*(a*(a**2*Rational(3, 256) - b/S(16)) + c/S(4))
222
+ eq = x**4 + a*x**3 + b*x**2 + c*x + d
223
+ ans = roots_quartic(Poly(eq, x))
224
+ assert all(eq.subs(x, ai).n(chop=True) == 0 for ai in ans)
225
+
226
+ # not all symbolic quartics are unresolvable
227
+ eq = Poly(q*x + q/4 + x**4 + x**3 + 2*x**2 - Rational(1, 3), x)
228
+ sol = roots_quartic(eq)
229
+ assert all(verify_numerically(eq.subs(x, i), 0) for i in sol)
230
+ z = symbols('z', negative=True)
231
+ eq = x**4 + 2*x**3 + 3*x**2 + x*(z + 11) + 5
232
+ zans = roots_quartic(Poly(eq, x))
233
+ assert all(verify_numerically(eq.subs(((x, i), (z, -1))), 0) for i in zans)
234
+ # but some are (see also issue 4989)
235
+ # it's ok if the solution is not Piecewise, but the tests below should pass
236
+ eq = Poly(y*x**4 + x**3 - x + z, x)
237
+ ans = roots_quartic(eq)
238
+ assert all(type(i) == Piecewise for i in ans)
239
+ reps = (
240
+ {"y": Rational(-1, 3), "z": Rational(-1, 4)}, # 4 real
241
+ {"y": Rational(-1, 3), "z": Rational(-1, 2)}, # 2 real
242
+ {"y": Rational(-1, 3), "z": -2}) # 0 real
243
+ for rep in reps:
244
+ sol = roots_quartic(Poly(eq.subs(rep), x))
245
+ assert all(verify_numerically(w.subs(rep) - s, 0) for w, s in zip(ans, sol))
246
+
247
+
248
+ def test_issue_21287():
249
+ assert not any(isinstance(i, Piecewise) for i in roots_quartic(
250
+ Poly(x**4 - x**2*(3 + 5*I) + 2*x*(-1 + I) - 1 + 3*I, x)))
251
+
252
+
253
+ def test_roots_quintic():
254
+ eqs = (x**5 - 2,
255
+ (x/2 + 1)**5 - 5*(x/2 + 1) + 12,
256
+ x**5 - 110*x**3 - 55*x**2 + 2310*x + 979)
257
+ for eq in eqs:
258
+ roots = roots_quintic(Poly(eq))
259
+ assert len(roots) == 5
260
+ assert all(eq.subs(x, r.n(10)).n(chop = 1e-5) == 0 for r in roots)
261
+
262
+
263
+ def test_roots_cyclotomic():
264
+ assert roots_cyclotomic(cyclotomic_poly(1, x, polys=True)) == [1]
265
+ assert roots_cyclotomic(cyclotomic_poly(2, x, polys=True)) == [-1]
266
+ assert roots_cyclotomic(cyclotomic_poly(
267
+ 3, x, polys=True)) == [Rational(-1, 2) - I*sqrt(3)/2, Rational(-1, 2) + I*sqrt(3)/2]
268
+ assert roots_cyclotomic(cyclotomic_poly(4, x, polys=True)) == [-I, I]
269
+ assert roots_cyclotomic(cyclotomic_poly(
270
+ 6, x, polys=True)) == [S.Half - I*sqrt(3)/2, S.Half + I*sqrt(3)/2]
271
+
272
+ assert roots_cyclotomic(cyclotomic_poly(7, x, polys=True)) == [
273
+ -cos(pi/7) - I*sin(pi/7),
274
+ -cos(pi/7) + I*sin(pi/7),
275
+ -cos(pi*Rational(3, 7)) - I*sin(pi*Rational(3, 7)),
276
+ -cos(pi*Rational(3, 7)) + I*sin(pi*Rational(3, 7)),
277
+ cos(pi*Rational(2, 7)) - I*sin(pi*Rational(2, 7)),
278
+ cos(pi*Rational(2, 7)) + I*sin(pi*Rational(2, 7)),
279
+ ]
280
+
281
+ assert roots_cyclotomic(cyclotomic_poly(8, x, polys=True)) == [
282
+ -sqrt(2)/2 - I*sqrt(2)/2,
283
+ -sqrt(2)/2 + I*sqrt(2)/2,
284
+ sqrt(2)/2 - I*sqrt(2)/2,
285
+ sqrt(2)/2 + I*sqrt(2)/2,
286
+ ]
287
+
288
+ assert roots_cyclotomic(cyclotomic_poly(12, x, polys=True)) == [
289
+ -sqrt(3)/2 - I/2,
290
+ -sqrt(3)/2 + I/2,
291
+ sqrt(3)/2 - I/2,
292
+ sqrt(3)/2 + I/2,
293
+ ]
294
+
295
+ assert roots_cyclotomic(
296
+ cyclotomic_poly(1, x, polys=True), factor=True) == [1]
297
+ assert roots_cyclotomic(
298
+ cyclotomic_poly(2, x, polys=True), factor=True) == [-1]
299
+
300
+ assert roots_cyclotomic(cyclotomic_poly(3, x, polys=True), factor=True) == \
301
+ [-root(-1, 3), -1 + root(-1, 3)]
302
+ assert roots_cyclotomic(cyclotomic_poly(4, x, polys=True), factor=True) == \
303
+ [-I, I]
304
+ assert roots_cyclotomic(cyclotomic_poly(5, x, polys=True), factor=True) == \
305
+ [-root(-1, 5), -root(-1, 5)**3, root(-1, 5)**2, -1 - root(-1, 5)**2 + root(-1, 5) + root(-1, 5)**3]
306
+
307
+ assert roots_cyclotomic(cyclotomic_poly(6, x, polys=True), factor=True) == \
308
+ [1 - root(-1, 3), root(-1, 3)]
309
+
310
+
311
+ def test_roots_binomial():
312
+ assert roots_binomial(Poly(5*x, x)) == [0]
313
+ assert roots_binomial(Poly(5*x**4, x)) == [0, 0, 0, 0]
314
+ assert roots_binomial(Poly(5*x + 2, x)) == [Rational(-2, 5)]
315
+
316
+ A = 10**Rational(3, 4)/10
317
+
318
+ assert roots_binomial(Poly(5*x**4 + 2, x)) == \
319
+ [-A - A*I, -A + A*I, A - A*I, A + A*I]
320
+ _check(roots_binomial(Poly(x**8 - 2)))
321
+
322
+ a1 = Symbol('a1', nonnegative=True)
323
+ b1 = Symbol('b1', nonnegative=True)
324
+
325
+ r0 = roots_quadratic(Poly(a1*x**2 + b1, x))
326
+ r1 = roots_binomial(Poly(a1*x**2 + b1, x))
327
+
328
+ assert powsimp(r0[0]) == powsimp(r1[0])
329
+ assert powsimp(r0[1]) == powsimp(r1[1])
330
+ for a, b, s, n in product((1, 2), (1, 2), (-1, 1), (2, 3, 4, 5)):
331
+ if a == b and a != 1: # a == b == 1 is sufficient
332
+ continue
333
+ p = Poly(a*x**n + s*b)
334
+ ans = roots_binomial(p)
335
+ assert ans == _nsort(ans)
336
+
337
+ # issue 8813
338
+ assert roots(Poly(2*x**3 - 16*y**3, x)) == {
339
+ 2*y*(Rational(-1, 2) - sqrt(3)*I/2): 1,
340
+ 2*y: 1,
341
+ 2*y*(Rational(-1, 2) + sqrt(3)*I/2): 1}
342
+
343
+
344
+ def test_roots_preprocessing():
345
+ f = a*y*x**2 + y - b
346
+
347
+ coeff, poly = preprocess_roots(Poly(f, x))
348
+
349
+ assert coeff == 1
350
+ assert poly == Poly(a*y*x**2 + y - b, x)
351
+
352
+ f = c**3*x**3 + c**2*x**2 + c*x + a
353
+
354
+ coeff, poly = preprocess_roots(Poly(f, x))
355
+
356
+ assert coeff == 1/c
357
+ assert poly == Poly(x**3 + x**2 + x + a, x)
358
+
359
+ f = c**3*x**3 + c**2*x**2 + a
360
+
361
+ coeff, poly = preprocess_roots(Poly(f, x))
362
+
363
+ assert coeff == 1/c
364
+ assert poly == Poly(x**3 + x**2 + a, x)
365
+
366
+ f = c**3*x**3 + c*x + a
367
+
368
+ coeff, poly = preprocess_roots(Poly(f, x))
369
+
370
+ assert coeff == 1/c
371
+ assert poly == Poly(x**3 + x + a, x)
372
+
373
+ f = c**3*x**3 + a
374
+
375
+ coeff, poly = preprocess_roots(Poly(f, x))
376
+
377
+ assert coeff == 1/c
378
+ assert poly == Poly(x**3 + a, x)
379
+
380
+ E, F, J, L = symbols("E,F,J,L")
381
+
382
+ f = -21601054687500000000*E**8*J**8/L**16 + \
383
+ 508232812500000000*F*x*E**7*J**7/L**14 - \
384
+ 4269543750000000*E**6*F**2*J**6*x**2/L**12 + \
385
+ 16194716250000*E**5*F**3*J**5*x**3/L**10 - \
386
+ 27633173750*E**4*F**4*J**4*x**4/L**8 + \
387
+ 14840215*E**3*F**5*J**3*x**5/L**6 + \
388
+ 54794*E**2*F**6*J**2*x**6/(5*L**4) - \
389
+ 1153*E*J*F**7*x**7/(80*L**2) + \
390
+ 633*F**8*x**8/160000
391
+
392
+ coeff, poly = preprocess_roots(Poly(f, x))
393
+
394
+ assert coeff == 20*E*J/(F*L**2)
395
+ assert poly == 633*x**8 - 115300*x**7 + 4383520*x**6 + 296804300*x**5 - 27633173750*x**4 + \
396
+ 809735812500*x**3 - 10673859375000*x**2 + 63529101562500*x - 135006591796875
397
+
398
+ f = Poly(-y**2 + x**2*exp(x), y, domain=ZZ[x, exp(x)])
399
+ g = Poly(-y**2 + exp(x), y, domain=ZZ[exp(x)])
400
+
401
+ assert preprocess_roots(f) == (x, g)
402
+
403
+
404
+ def test_roots0():
405
+ assert roots(1, x) == {}
406
+ assert roots(x, x) == {S.Zero: 1}
407
+ assert roots(x**9, x) == {S.Zero: 9}
408
+ assert roots(((x - 2)*(x + 3)*(x - 4)).expand(), x) == {-S(3): 1, S(2): 1, S(4): 1}
409
+
410
+ assert roots(2*x + 1, x) == {Rational(-1, 2): 1}
411
+ assert roots((2*x + 1)**2, x) == {Rational(-1, 2): 2}
412
+ assert roots((2*x + 1)**5, x) == {Rational(-1, 2): 5}
413
+ assert roots((2*x + 1)**10, x) == {Rational(-1, 2): 10}
414
+
415
+ assert roots(x**4 - 1, x) == {I: 1, S.One: 1, -S.One: 1, -I: 1}
416
+ assert roots((x**4 - 1)**2, x) == {I: 2, S.One: 2, -S.One: 2, -I: 2}
417
+
418
+ assert roots(((2*x - 3)**2).expand(), x) == {Rational( 3, 2): 2}
419
+ assert roots(((2*x + 3)**2).expand(), x) == {Rational(-3, 2): 2}
420
+
421
+ assert roots(((2*x - 3)**3).expand(), x) == {Rational( 3, 2): 3}
422
+ assert roots(((2*x + 3)**3).expand(), x) == {Rational(-3, 2): 3}
423
+
424
+ assert roots(((2*x - 3)**5).expand(), x) == {Rational( 3, 2): 5}
425
+ assert roots(((2*x + 3)**5).expand(), x) == {Rational(-3, 2): 5}
426
+
427
+ assert roots(((a*x - b)**5).expand(), x) == { b/a: 5}
428
+ assert roots(((a*x + b)**5).expand(), x) == {-b/a: 5}
429
+
430
+ assert roots(x**2 + (-a - 1)*x + a, x) == {a: 1, S.One: 1}
431
+
432
+ assert roots(x**4 - 2*x**2 + 1, x) == {S.One: 2, S.NegativeOne: 2}
433
+
434
+ assert roots(x**6 - 4*x**4 + 4*x**3 - x**2, x) == \
435
+ {S.One: 2, -1 - sqrt(2): 1, S.Zero: 2, -1 + sqrt(2): 1}
436
+
437
+ assert roots(x**8 - 1, x) == {
438
+ sqrt(2)/2 + I*sqrt(2)/2: 1,
439
+ sqrt(2)/2 - I*sqrt(2)/2: 1,
440
+ -sqrt(2)/2 + I*sqrt(2)/2: 1,
441
+ -sqrt(2)/2 - I*sqrt(2)/2: 1,
442
+ S.One: 1, -S.One: 1, I: 1, -I: 1
443
+ }
444
+
445
+ f = -2016*x**2 - 5616*x**3 - 2056*x**4 + 3324*x**5 + 2176*x**6 - \
446
+ 224*x**7 - 384*x**8 - 64*x**9
447
+
448
+ assert roots(f) == {S.Zero: 2, -S(2): 2, S(2): 1, Rational(-7, 2): 1,
449
+ Rational(-3, 2): 1, Rational(-1, 2): 1, Rational(3, 2): 1}
450
+
451
+ assert roots((a + b + c)*x - (a + b + c + d), x) == {(a + b + c + d)/(a + b + c): 1}
452
+
453
+ assert roots(x**3 + x**2 - x + 1, x, cubics=False) == {}
454
+ assert roots(((x - 2)*(
455
+ x + 3)*(x - 4)).expand(), x, cubics=False) == {-S(3): 1, S(2): 1, S(4): 1}
456
+ assert roots(((x - 2)*(x + 3)*(x - 4)*(x - 5)).expand(), x, cubics=False) == \
457
+ {-S(3): 1, S(2): 1, S(4): 1, S(5): 1}
458
+ assert roots(x**3 + 2*x**2 + 4*x + 8, x) == {-S(2): 1, -2*I: 1, 2*I: 1}
459
+ assert roots(x**3 + 2*x**2 + 4*x + 8, x, cubics=True) == \
460
+ {-2*I: 1, 2*I: 1, -S(2): 1}
461
+ assert roots((x**2 - x)*(x**3 + 2*x**2 + 4*x + 8), x ) == \
462
+ {S.One: 1, S.Zero: 1, -S(2): 1, -2*I: 1, 2*I: 1}
463
+
464
+ r1_2, r1_3 = S.Half, Rational(1, 3)
465
+
466
+ x0 = (3*sqrt(33) + 19)**r1_3
467
+ x1 = 4/x0/3
468
+ x2 = x0/3
469
+ x3 = sqrt(3)*I/2
470
+ x4 = x3 - r1_2
471
+ x5 = -x3 - r1_2
472
+ assert roots(x**3 + x**2 - x + 1, x, cubics=True) == {
473
+ -x1 - x2 - r1_3: 1,
474
+ -x1/x4 - x2*x4 - r1_3: 1,
475
+ -x1/x5 - x2*x5 - r1_3: 1,
476
+ }
477
+
478
+ f = (x**2 + 2*x + 3).subs(x, 2*x**2 + 3*x).subs(x, 5*x - 4)
479
+
480
+ r13_20, r1_20 = [ Rational(*r)
481
+ for r in ((13, 20), (1, 20)) ]
482
+
483
+ s2 = sqrt(2)
484
+ assert roots(f, x) == {
485
+ r13_20 + r1_20*sqrt(1 - 8*I*s2): 1,
486
+ r13_20 - r1_20*sqrt(1 - 8*I*s2): 1,
487
+ r13_20 + r1_20*sqrt(1 + 8*I*s2): 1,
488
+ r13_20 - r1_20*sqrt(1 + 8*I*s2): 1,
489
+ }
490
+
491
+ f = x**4 + x**3 + x**2 + x + 1
492
+
493
+ r1_4, r1_8, r5_8 = [ Rational(*r) for r in ((1, 4), (1, 8), (5, 8)) ]
494
+
495
+ assert roots(f, x) == {
496
+ -r1_4 + r1_4*5**r1_2 + I*(r5_8 + r1_8*5**r1_2)**r1_2: 1,
497
+ -r1_4 + r1_4*5**r1_2 - I*(r5_8 + r1_8*5**r1_2)**r1_2: 1,
498
+ -r1_4 - r1_4*5**r1_2 + I*(r5_8 - r1_8*5**r1_2)**r1_2: 1,
499
+ -r1_4 - r1_4*5**r1_2 - I*(r5_8 - r1_8*5**r1_2)**r1_2: 1,
500
+ }
501
+
502
+ f = z**3 + (-2 - y)*z**2 + (1 + 2*y - 2*x**2)*z - y + 2*x**2
503
+
504
+ assert roots(f, z) == {
505
+ S.One: 1,
506
+ S.Half + S.Half*y + S.Half*sqrt(1 - 2*y + y**2 + 8*x**2): 1,
507
+ S.Half + S.Half*y - S.Half*sqrt(1 - 2*y + y**2 + 8*x**2): 1,
508
+ }
509
+
510
+ assert roots(a*b*c*x**3 + 2*x**2 + 4*x + 8, x, cubics=False) == {}
511
+ assert roots(a*b*c*x**3 + 2*x**2 + 4*x + 8, x, cubics=True) != {}
512
+
513
+ assert roots(x**4 - 1, x, filter='Z') == {S.One: 1, -S.One: 1}
514
+ assert roots(x**4 - 1, x, filter='I') == {I: 1, -I: 1}
515
+
516
+ assert roots((x - 1)*(x + 1), x) == {S.One: 1, -S.One: 1}
517
+ assert roots(
518
+ (x - 1)*(x + 1), x, predicate=lambda r: r.is_positive) == {S.One: 1}
519
+
520
+ assert roots(x**4 - 1, x, filter='Z', multiple=True) == [-S.One, S.One]
521
+ assert roots(x**4 - 1, x, filter='I', multiple=True) == [I, -I]
522
+
523
+ ar, br = symbols('a, b', real=True)
524
+ p = x**2*(ar-br)**2 + 2*x*(br-ar) + 1
525
+ assert roots(p, x, filter='R') == {1/(ar - br): 2}
526
+
527
+ assert roots(x**3, x, multiple=True) == [S.Zero, S.Zero, S.Zero]
528
+ assert roots(1234, x, multiple=True) == []
529
+
530
+ f = x**6 - x**5 + x**4 - x**3 + x**2 - x + 1
531
+
532
+ assert roots(f) == {
533
+ -I*sin(pi/7) + cos(pi/7): 1,
534
+ -I*sin(pi*Rational(2, 7)) - cos(pi*Rational(2, 7)): 1,
535
+ -I*sin(pi*Rational(3, 7)) + cos(pi*Rational(3, 7)): 1,
536
+ I*sin(pi/7) + cos(pi/7): 1,
537
+ I*sin(pi*Rational(2, 7)) - cos(pi*Rational(2, 7)): 1,
538
+ I*sin(pi*Rational(3, 7)) + cos(pi*Rational(3, 7)): 1,
539
+ }
540
+
541
+ g = ((x**2 + 1)*f**2).expand()
542
+
543
+ assert roots(g) == {
544
+ -I*sin(pi/7) + cos(pi/7): 2,
545
+ -I*sin(pi*Rational(2, 7)) - cos(pi*Rational(2, 7)): 2,
546
+ -I*sin(pi*Rational(3, 7)) + cos(pi*Rational(3, 7)): 2,
547
+ I*sin(pi/7) + cos(pi/7): 2,
548
+ I*sin(pi*Rational(2, 7)) - cos(pi*Rational(2, 7)): 2,
549
+ I*sin(pi*Rational(3, 7)) + cos(pi*Rational(3, 7)): 2,
550
+ -I: 1, I: 1,
551
+ }
552
+
553
+ r = roots(x**3 + 40*x + 64)
554
+ real_root = [rx for rx in r if rx.is_real][0]
555
+ cr = 108 + 6*sqrt(1074)
556
+ assert real_root == -2*root(cr, 3)/3 + 20/root(cr, 3)
557
+
558
+ eq = Poly((7 + 5*sqrt(2))*x**3 + (-6 - 4*sqrt(2))*x**2 + (-sqrt(2) - 1)*x + 2, x, domain='EX')
559
+ assert roots(eq) == {-1 + sqrt(2): 1, -2 + 2*sqrt(2): 1, -sqrt(2) + 1: 1}
560
+
561
+ eq = Poly(41*x**5 + 29*sqrt(2)*x**5 - 153*x**4 - 108*sqrt(2)*x**4 +
562
+ 175*x**3 + 125*sqrt(2)*x**3 - 45*x**2 - 30*sqrt(2)*x**2 - 26*sqrt(2)*x -
563
+ 26*x + 24, x, domain='EX')
564
+ assert roots(eq) == {-sqrt(2) + 1: 1, -2 + 2*sqrt(2): 1, -1 + sqrt(2): 1,
565
+ -4 + 4*sqrt(2): 1, -3 + 3*sqrt(2): 1}
566
+
567
+ eq = Poly(x**3 - 2*x**2 + 6*sqrt(2)*x**2 - 8*sqrt(2)*x + 23*x - 14 +
568
+ 14*sqrt(2), x, domain='EX')
569
+ assert roots(eq) == {-2*sqrt(2) + 2: 1, -2*sqrt(2) + 1: 1, -2*sqrt(2) - 1: 1}
570
+
571
+ assert roots(Poly((x + sqrt(2))**3 - 7, x, domain='EX')) == \
572
+ {-sqrt(2) + root(7, 3)*(-S.Half - sqrt(3)*I/2): 1,
573
+ -sqrt(2) + root(7, 3)*(-S.Half + sqrt(3)*I/2): 1,
574
+ -sqrt(2) + root(7, 3): 1}
575
+
576
+ def test_roots_slow():
577
+ """Just test that calculating these roots does not hang. """
578
+ a, b, c, d, x = symbols("a,b,c,d,x")
579
+
580
+ f1 = x**2*c + (a/b) + x*c*d - a
581
+ f2 = x**2*(a + b*(c - d)*a) + x*a*b*c/(b*d - d) + (a*d - c/d)
582
+
583
+ assert list(roots(f1, x).values()) == [1, 1]
584
+ assert list(roots(f2, x).values()) == [1, 1]
585
+
586
+ (zz, yy, xx, zy, zx, yx, k) = symbols("zz,yy,xx,zy,zx,yx,k")
587
+
588
+ e1 = (zz - k)*(yy - k)*(xx - k) + zy*yx*zx + zx - zy - yx
589
+ e2 = (zz - k)*yx*yx + zx*(yy - k)*zx + zy*zy*(xx - k)
590
+
591
+ assert list(roots(e1 - e2, k).values()) == [1, 1, 1]
592
+
593
+ f = x**3 + 2*x**2 + 8
594
+ R = list(roots(f).keys())
595
+
596
+ assert not any(i for i in [f.subs(x, ri).n(chop=True) for ri in R])
597
+
598
+
599
+ def test_roots_inexact():
600
+ R1 = roots(x**2 + x + 1, x, multiple=True)
601
+ R2 = roots(x**2 + x + 1.0, x, multiple=True)
602
+
603
+ for r1, r2 in zip(R1, R2):
604
+ assert abs(r1 - r2) < 1e-12
605
+
606
+ f = x**4 + 3.0*sqrt(2.0)*x**3 - (78.0 + 24.0*sqrt(3.0))*x**2 \
607
+ + 144.0*(2*sqrt(3.0) + 9.0)
608
+
609
+ R1 = roots(f, multiple=True)
610
+ R2 = (-12.7530479110482, -3.85012393732929,
611
+ 4.89897948556636, 7.46155167569183)
612
+
613
+ for r1, r2 in zip(R1, R2):
614
+ assert abs(r1 - r2) < 1e-10
615
+
616
+
617
+ def test_roots_preprocessed():
618
+ E, F, J, L = symbols("E,F,J,L")
619
+
620
+ f = -21601054687500000000*E**8*J**8/L**16 + \
621
+ 508232812500000000*F*x*E**7*J**7/L**14 - \
622
+ 4269543750000000*E**6*F**2*J**6*x**2/L**12 + \
623
+ 16194716250000*E**5*F**3*J**5*x**3/L**10 - \
624
+ 27633173750*E**4*F**4*J**4*x**4/L**8 + \
625
+ 14840215*E**3*F**5*J**3*x**5/L**6 + \
626
+ 54794*E**2*F**6*J**2*x**6/(5*L**4) - \
627
+ 1153*E*J*F**7*x**7/(80*L**2) + \
628
+ 633*F**8*x**8/160000
629
+
630
+ assert roots(f, x) == {}
631
+
632
+ R1 = roots(f.evalf(), x, multiple=True)
633
+ R2 = [-1304.88375606366, 97.1168816800648, 186.946430171876, 245.526792947065,
634
+ 503.441004174773, 791.549343830097, 1273.16678129348, 1850.10650616851]
635
+
636
+ w = Wild('w')
637
+ p = w*E*J/(F*L**2)
638
+
639
+ assert len(R1) == len(R2)
640
+
641
+ for r1, r2 in zip(R1, R2):
642
+ match = r1.match(p)
643
+ assert match is not None and abs(match[w] - r2) < 1e-10
644
+
645
+
646
+ def test_roots_strict():
647
+ assert roots(x**2 - 2*x + 1, strict=False) == {1: 2}
648
+ assert roots(x**2 - 2*x + 1, strict=True) == {1: 2}
649
+
650
+ assert roots(x**6 - 2*x**5 - x**2 + 3*x - 2, strict=False) == {2: 1}
651
+ raises(UnsolvableFactorError, lambda: roots(x**6 - 2*x**5 - x**2 + 3*x - 2, strict=True))
652
+
653
+
654
+ def test_roots_mixed():
655
+ f = -1936 - 5056*x - 7592*x**2 + 2704*x**3 - 49*x**4
656
+
657
+ _re, _im = intervals(f, all=True)
658
+ _nroots = nroots(f)
659
+ _sroots = roots(f, multiple=True)
660
+
661
+ _re = [ Interval(a, b) for (a, b), _ in _re ]
662
+ _im = [ Interval(re(a), re(b))*Interval(im(a), im(b)) for (a, b),
663
+ _ in _im ]
664
+
665
+ _intervals = _re + _im
666
+ _sroots = [ r.evalf() for r in _sroots ]
667
+
668
+ _nroots = sorted(_nroots, key=lambda x: x.sort_key())
669
+ _sroots = sorted(_sroots, key=lambda x: x.sort_key())
670
+
671
+ for _roots in (_nroots, _sroots):
672
+ for i, r in zip(_intervals, _roots):
673
+ if r.is_real:
674
+ assert r in i
675
+ else:
676
+ assert (re(r), im(r)) in i
677
+
678
+
679
+ def test_root_factors():
680
+ assert root_factors(Poly(1, x)) == [Poly(1, x)]
681
+ assert root_factors(Poly(x, x)) == [Poly(x, x)]
682
+
683
+ assert root_factors(x**2 - 1, x) == [x + 1, x - 1]
684
+ assert root_factors(x**2 - y, x) == [x - sqrt(y), x + sqrt(y)]
685
+
686
+ assert root_factors((x**4 - 1)**2) == \
687
+ [x + 1, x + 1, x - 1, x - 1, x - I, x - I, x + I, x + I]
688
+
689
+ assert root_factors(Poly(x**4 - 1, x), filter='Z') == \
690
+ [Poly(x + 1, x), Poly(x - 1, x), Poly(x**2 + 1, x)]
691
+ assert root_factors(8*x**2 + 12*x**4 + 6*x**6 + x**8, x, filter='Q') == \
692
+ [x, x, x**6 + 6*x**4 + 12*x**2 + 8]
693
+
694
+
695
+ @slow
696
+ def test_nroots1():
697
+ n = 64
698
+ p = legendre_poly(n, x, polys=True)
699
+
700
+ raises(mpmath.mp.NoConvergence, lambda: p.nroots(n=3, maxsteps=5))
701
+
702
+ roots = p.nroots(n=3)
703
+ # The order of roots matters. They are ordered from smallest to the
704
+ # largest.
705
+ assert [str(r) for r in roots] == \
706
+ ['-0.999', '-0.996', '-0.991', '-0.983', '-0.973', '-0.961',
707
+ '-0.946', '-0.930', '-0.911', '-0.889', '-0.866', '-0.841',
708
+ '-0.813', '-0.784', '-0.753', '-0.720', '-0.685', '-0.649',
709
+ '-0.611', '-0.572', '-0.531', '-0.489', '-0.446', '-0.402',
710
+ '-0.357', '-0.311', '-0.265', '-0.217', '-0.170', '-0.121',
711
+ '-0.0730', '-0.0243', '0.0243', '0.0730', '0.121', '0.170',
712
+ '0.217', '0.265', '0.311', '0.357', '0.402', '0.446', '0.489',
713
+ '0.531', '0.572', '0.611', '0.649', '0.685', '0.720', '0.753',
714
+ '0.784', '0.813', '0.841', '0.866', '0.889', '0.911', '0.930',
715
+ '0.946', '0.961', '0.973', '0.983', '0.991', '0.996', '0.999']
716
+
717
+ def test_nroots2():
718
+ p = Poly(x**5 + 3*x + 1, x)
719
+
720
+ roots = p.nroots(n=3)
721
+ # The order of roots matters. The roots are ordered by their real
722
+ # components (if they agree, then by their imaginary components),
723
+ # with real roots appearing first.
724
+ assert [str(r) for r in roots] == \
725
+ ['-0.332', '-0.839 - 0.944*I', '-0.839 + 0.944*I',
726
+ '1.01 - 0.937*I', '1.01 + 0.937*I']
727
+
728
+ roots = p.nroots(n=5)
729
+ assert [str(r) for r in roots] == \
730
+ ['-0.33199', '-0.83907 - 0.94385*I', '-0.83907 + 0.94385*I',
731
+ '1.0051 - 0.93726*I', '1.0051 + 0.93726*I']
732
+
733
+
734
+ def test_roots_composite():
735
+ assert len(roots(Poly(y**3 + y**2*sqrt(x) + y + x, y, composite=True))) == 3
736
+
737
+
738
+ def test_issue_19113():
739
+ eq = cos(x)**3 - cos(x) + 1
740
+ raises(PolynomialError, lambda: roots(eq))
741
+
742
+
743
+ def test_issue_17454():
744
+ assert roots([1, -3*(-4 - 4*I)**2/8 + 12*I, 0], multiple=True) == [0, 0]
745
+
746
+
747
+ def test_issue_20913():
748
+ assert Poly(x + 9671406556917067856609794, x).real_roots() == [-9671406556917067856609794]
749
+ assert Poly(x**3 + 4, x).real_roots() == [-2**(S(2)/3)]
750
+
751
+
752
+ def test_issue_22768():
753
+ e = Rational(1, 3)
754
+ r = (-1/a)**e*(a + 1)**(5*e)
755
+ assert roots(Poly(a*x**3 + (a + 1)**5, x)) == {
756
+ r: 1,
757
+ -r*(1 + sqrt(3)*I)/2: 1,
758
+ r*(-1 + sqrt(3)*I)/2: 1}
valley/lib/python3.10/site-packages/sympy/polys/tests/test_polytools.py ADDED
The diff for this file is too large to render. See raw diff
 
valley/lib/python3.10/site-packages/sympy/polys/tests/test_polyutils.py ADDED
@@ -0,0 +1,300 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Tests for useful utilities for higher level polynomial classes. """
2
+
3
+ from sympy.core.mul import Mul
4
+ from sympy.core.numbers import (Integer, pi)
5
+ from sympy.core.relational import Eq
6
+ from sympy.core.singleton import S
7
+ from sympy.core.symbol import (Symbol, symbols)
8
+ from sympy.functions.elementary.exponential import exp
9
+ from sympy.functions.elementary.miscellaneous import sqrt
10
+ from sympy.functions.elementary.trigonometric import (cos, sin)
11
+ from sympy.integrals.integrals import Integral
12
+ from sympy.testing.pytest import raises
13
+
14
+ from sympy.polys.polyutils import (
15
+ _nsort,
16
+ _sort_gens,
17
+ _unify_gens,
18
+ _analyze_gens,
19
+ _sort_factors,
20
+ parallel_dict_from_expr,
21
+ dict_from_expr,
22
+ )
23
+
24
+ from sympy.polys.polyerrors import PolynomialError
25
+
26
+ from sympy.polys.domains import ZZ
27
+
28
+ x, y, z, p, q, r, s, t, u, v, w = symbols('x,y,z,p,q,r,s,t,u,v,w')
29
+ A, B = symbols('A,B', commutative=False)
30
+
31
+
32
+ def test__nsort():
33
+ # issue 6137
34
+ r = S('''[3/2 + sqrt(-14/3 - 2*(-415/216 + 13*I/12)**(1/3) - 4/sqrt(-7/3 +
35
+ 61/(18*(-415/216 + 13*I/12)**(1/3)) + 2*(-415/216 + 13*I/12)**(1/3)) -
36
+ 61/(18*(-415/216 + 13*I/12)**(1/3)))/2 - sqrt(-7/3 + 61/(18*(-415/216
37
+ + 13*I/12)**(1/3)) + 2*(-415/216 + 13*I/12)**(1/3))/2, 3/2 - sqrt(-7/3
38
+ + 61/(18*(-415/216 + 13*I/12)**(1/3)) + 2*(-415/216 +
39
+ 13*I/12)**(1/3))/2 - sqrt(-14/3 - 2*(-415/216 + 13*I/12)**(1/3) -
40
+ 4/sqrt(-7/3 + 61/(18*(-415/216 + 13*I/12)**(1/3)) + 2*(-415/216 +
41
+ 13*I/12)**(1/3)) - 61/(18*(-415/216 + 13*I/12)**(1/3)))/2, 3/2 +
42
+ sqrt(-14/3 - 2*(-415/216 + 13*I/12)**(1/3) + 4/sqrt(-7/3 +
43
+ 61/(18*(-415/216 + 13*I/12)**(1/3)) + 2*(-415/216 + 13*I/12)**(1/3)) -
44
+ 61/(18*(-415/216 + 13*I/12)**(1/3)))/2 + sqrt(-7/3 + 61/(18*(-415/216
45
+ + 13*I/12)**(1/3)) + 2*(-415/216 + 13*I/12)**(1/3))/2, 3/2 + sqrt(-7/3
46
+ + 61/(18*(-415/216 + 13*I/12)**(1/3)) + 2*(-415/216 +
47
+ 13*I/12)**(1/3))/2 - sqrt(-14/3 - 2*(-415/216 + 13*I/12)**(1/3) +
48
+ 4/sqrt(-7/3 + 61/(18*(-415/216 + 13*I/12)**(1/3)) + 2*(-415/216 +
49
+ 13*I/12)**(1/3)) - 61/(18*(-415/216 + 13*I/12)**(1/3)))/2]''')
50
+ ans = [r[1], r[0], r[-1], r[-2]]
51
+ assert _nsort(r) == ans
52
+ assert len(_nsort(r, separated=True)[0]) == 0
53
+ b, c, a = exp(-1000), exp(-999), exp(-1001)
54
+ assert _nsort((b, c, a)) == [a, b, c]
55
+ # issue 12560
56
+ a = cos(1)**2 + sin(1)**2 - 1
57
+ assert _nsort([a]) == [a]
58
+
59
+
60
+ def test__sort_gens():
61
+ assert _sort_gens([]) == ()
62
+
63
+ assert _sort_gens([x]) == (x,)
64
+ assert _sort_gens([p]) == (p,)
65
+ assert _sort_gens([q]) == (q,)
66
+
67
+ assert _sort_gens([x, p]) == (x, p)
68
+ assert _sort_gens([p, x]) == (x, p)
69
+ assert _sort_gens([q, p]) == (p, q)
70
+
71
+ assert _sort_gens([q, p, x]) == (x, p, q)
72
+
73
+ assert _sort_gens([x, p, q], wrt=x) == (x, p, q)
74
+ assert _sort_gens([x, p, q], wrt=p) == (p, x, q)
75
+ assert _sort_gens([x, p, q], wrt=q) == (q, x, p)
76
+
77
+ assert _sort_gens([x, p, q], wrt='x') == (x, p, q)
78
+ assert _sort_gens([x, p, q], wrt='p') == (p, x, q)
79
+ assert _sort_gens([x, p, q], wrt='q') == (q, x, p)
80
+
81
+ assert _sort_gens([x, p, q], wrt='x,q') == (x, q, p)
82
+ assert _sort_gens([x, p, q], wrt='q,x') == (q, x, p)
83
+ assert _sort_gens([x, p, q], wrt='p,q') == (p, q, x)
84
+ assert _sort_gens([x, p, q], wrt='q,p') == (q, p, x)
85
+
86
+ assert _sort_gens([x, p, q], wrt='x, q') == (x, q, p)
87
+ assert _sort_gens([x, p, q], wrt='q, x') == (q, x, p)
88
+ assert _sort_gens([x, p, q], wrt='p, q') == (p, q, x)
89
+ assert _sort_gens([x, p, q], wrt='q, p') == (q, p, x)
90
+
91
+ assert _sort_gens([x, p, q], wrt=[x, 'q']) == (x, q, p)
92
+ assert _sort_gens([x, p, q], wrt=[q, 'x']) == (q, x, p)
93
+ assert _sort_gens([x, p, q], wrt=[p, 'q']) == (p, q, x)
94
+ assert _sort_gens([x, p, q], wrt=[q, 'p']) == (q, p, x)
95
+
96
+ assert _sort_gens([x, p, q], wrt=['x', 'q']) == (x, q, p)
97
+ assert _sort_gens([x, p, q], wrt=['q', 'x']) == (q, x, p)
98
+ assert _sort_gens([x, p, q], wrt=['p', 'q']) == (p, q, x)
99
+ assert _sort_gens([x, p, q], wrt=['q', 'p']) == (q, p, x)
100
+
101
+ assert _sort_gens([x, p, q], sort='x > p > q') == (x, p, q)
102
+ assert _sort_gens([x, p, q], sort='p > x > q') == (p, x, q)
103
+ assert _sort_gens([x, p, q], sort='p > q > x') == (p, q, x)
104
+
105
+ assert _sort_gens([x, p, q], wrt='x', sort='q > p') == (x, q, p)
106
+ assert _sort_gens([x, p, q], wrt='p', sort='q > x') == (p, q, x)
107
+ assert _sort_gens([x, p, q], wrt='q', sort='p > x') == (q, p, x)
108
+
109
+ # https://github.com/sympy/sympy/issues/19353
110
+ n1 = Symbol('\n1')
111
+ assert _sort_gens([n1]) == (n1,)
112
+ assert _sort_gens([x, n1]) == (x, n1)
113
+
114
+ X = symbols('x0,x1,x2,x10,x11,x12,x20,x21,x22')
115
+
116
+ assert _sort_gens(X) == X
117
+
118
+
119
+ def test__unify_gens():
120
+ assert _unify_gens([], []) == ()
121
+
122
+ assert _unify_gens([x], [x]) == (x,)
123
+ assert _unify_gens([y], [y]) == (y,)
124
+
125
+ assert _unify_gens([x, y], [x]) == (x, y)
126
+ assert _unify_gens([x], [x, y]) == (x, y)
127
+
128
+ assert _unify_gens([x, y], [x, y]) == (x, y)
129
+ assert _unify_gens([y, x], [y, x]) == (y, x)
130
+
131
+ assert _unify_gens([x], [y]) == (x, y)
132
+ assert _unify_gens([y], [x]) == (y, x)
133
+
134
+ assert _unify_gens([x], [y, x]) == (y, x)
135
+ assert _unify_gens([y, x], [x]) == (y, x)
136
+
137
+ assert _unify_gens([x, y, z], [x, y, z]) == (x, y, z)
138
+ assert _unify_gens([z, y, x], [x, y, z]) == (z, y, x)
139
+ assert _unify_gens([x, y, z], [z, y, x]) == (x, y, z)
140
+ assert _unify_gens([z, y, x], [z, y, x]) == (z, y, x)
141
+
142
+ assert _unify_gens([x, y, z], [t, x, p, q, z]) == (t, x, y, p, q, z)
143
+
144
+
145
+ def test__analyze_gens():
146
+ assert _analyze_gens((x, y, z)) == (x, y, z)
147
+ assert _analyze_gens([x, y, z]) == (x, y, z)
148
+
149
+ assert _analyze_gens(([x, y, z],)) == (x, y, z)
150
+ assert _analyze_gens(((x, y, z),)) == (x, y, z)
151
+
152
+
153
+ def test__sort_factors():
154
+ assert _sort_factors([], multiple=True) == []
155
+ assert _sort_factors([], multiple=False) == []
156
+
157
+ F = [[1, 2, 3], [1, 2], [1]]
158
+ G = [[1], [1, 2], [1, 2, 3]]
159
+
160
+ assert _sort_factors(F, multiple=False) == G
161
+
162
+ F = [[1, 2], [1, 2, 3], [1, 2], [1]]
163
+ G = [[1], [1, 2], [1, 2], [1, 2, 3]]
164
+
165
+ assert _sort_factors(F, multiple=False) == G
166
+
167
+ F = [[2, 2], [1, 2, 3], [1, 2], [1]]
168
+ G = [[1], [1, 2], [2, 2], [1, 2, 3]]
169
+
170
+ assert _sort_factors(F, multiple=False) == G
171
+
172
+ F = [([1, 2, 3], 1), ([1, 2], 1), ([1], 1)]
173
+ G = [([1], 1), ([1, 2], 1), ([1, 2, 3], 1)]
174
+
175
+ assert _sort_factors(F, multiple=True) == G
176
+
177
+ F = [([1, 2], 1), ([1, 2, 3], 1), ([1, 2], 1), ([1], 1)]
178
+ G = [([1], 1), ([1, 2], 1), ([1, 2], 1), ([1, 2, 3], 1)]
179
+
180
+ assert _sort_factors(F, multiple=True) == G
181
+
182
+ F = [([2, 2], 1), ([1, 2, 3], 1), ([1, 2], 1), ([1], 1)]
183
+ G = [([1], 1), ([1, 2], 1), ([2, 2], 1), ([1, 2, 3], 1)]
184
+
185
+ assert _sort_factors(F, multiple=True) == G
186
+
187
+ F = [([2, 2], 1), ([1, 2, 3], 1), ([1, 2], 2), ([1], 1)]
188
+ G = [([1], 1), ([2, 2], 1), ([1, 2], 2), ([1, 2, 3], 1)]
189
+
190
+ assert _sort_factors(F, multiple=True) == G
191
+
192
+
193
+ def test__dict_from_expr_if_gens():
194
+ assert dict_from_expr(
195
+ Integer(17), gens=(x,)) == ({(0,): Integer(17)}, (x,))
196
+ assert dict_from_expr(
197
+ Integer(17), gens=(x, y)) == ({(0, 0): Integer(17)}, (x, y))
198
+ assert dict_from_expr(
199
+ Integer(17), gens=(x, y, z)) == ({(0, 0, 0): Integer(17)}, (x, y, z))
200
+
201
+ assert dict_from_expr(
202
+ Integer(-17), gens=(x,)) == ({(0,): Integer(-17)}, (x,))
203
+ assert dict_from_expr(
204
+ Integer(-17), gens=(x, y)) == ({(0, 0): Integer(-17)}, (x, y))
205
+ assert dict_from_expr(Integer(
206
+ -17), gens=(x, y, z)) == ({(0, 0, 0): Integer(-17)}, (x, y, z))
207
+
208
+ assert dict_from_expr(
209
+ Integer(17)*x, gens=(x,)) == ({(1,): Integer(17)}, (x,))
210
+ assert dict_from_expr(
211
+ Integer(17)*x, gens=(x, y)) == ({(1, 0): Integer(17)}, (x, y))
212
+ assert dict_from_expr(Integer(
213
+ 17)*x, gens=(x, y, z)) == ({(1, 0, 0): Integer(17)}, (x, y, z))
214
+
215
+ assert dict_from_expr(
216
+ Integer(17)*x**7, gens=(x,)) == ({(7,): Integer(17)}, (x,))
217
+ assert dict_from_expr(
218
+ Integer(17)*x**7*y, gens=(x, y)) == ({(7, 1): Integer(17)}, (x, y))
219
+ assert dict_from_expr(Integer(17)*x**7*y*z**12, gens=(
220
+ x, y, z)) == ({(7, 1, 12): Integer(17)}, (x, y, z))
221
+
222
+ assert dict_from_expr(x + 2*y + 3*z, gens=(x,)) == \
223
+ ({(1,): Integer(1), (0,): 2*y + 3*z}, (x,))
224
+ assert dict_from_expr(x + 2*y + 3*z, gens=(x, y)) == \
225
+ ({(1, 0): Integer(1), (0, 1): Integer(2), (0, 0): 3*z}, (x, y))
226
+ assert dict_from_expr(x + 2*y + 3*z, gens=(x, y, z)) == \
227
+ ({(1, 0, 0): Integer(
228
+ 1), (0, 1, 0): Integer(2), (0, 0, 1): Integer(3)}, (x, y, z))
229
+
230
+ assert dict_from_expr(x*y + 2*x*z + 3*y*z, gens=(x,)) == \
231
+ ({(1,): y + 2*z, (0,): 3*y*z}, (x,))
232
+ assert dict_from_expr(x*y + 2*x*z + 3*y*z, gens=(x, y)) == \
233
+ ({(1, 1): Integer(1), (1, 0): 2*z, (0, 1): 3*z}, (x, y))
234
+ assert dict_from_expr(x*y + 2*x*z + 3*y*z, gens=(x, y, z)) == \
235
+ ({(1, 1, 0): Integer(
236
+ 1), (1, 0, 1): Integer(2), (0, 1, 1): Integer(3)}, (x, y, z))
237
+
238
+ assert dict_from_expr(2**y*x, gens=(x,)) == ({(1,): 2**y}, (x,))
239
+ assert dict_from_expr(Integral(x, (x, 1, 2)) + x) == (
240
+ {(0, 1): 1, (1, 0): 1}, (x, Integral(x, (x, 1, 2))))
241
+ raises(PolynomialError, lambda: dict_from_expr(2**y*x, gens=(x, y)))
242
+
243
+
244
+ def test__dict_from_expr_no_gens():
245
+ assert dict_from_expr(Integer(17)) == ({(): Integer(17)}, ())
246
+
247
+ assert dict_from_expr(x) == ({(1,): Integer(1)}, (x,))
248
+ assert dict_from_expr(y) == ({(1,): Integer(1)}, (y,))
249
+
250
+ assert dict_from_expr(x*y) == ({(1, 1): Integer(1)}, (x, y))
251
+ assert dict_from_expr(
252
+ x + y) == ({(1, 0): Integer(1), (0, 1): Integer(1)}, (x, y))
253
+
254
+ assert dict_from_expr(sqrt(2)) == ({(1,): Integer(1)}, (sqrt(2),))
255
+ assert dict_from_expr(sqrt(2), greedy=False) == ({(): sqrt(2)}, ())
256
+
257
+ assert dict_from_expr(x*y, domain=ZZ[x]) == ({(1,): x}, (y,))
258
+ assert dict_from_expr(x*y, domain=ZZ[y]) == ({(1,): y}, (x,))
259
+
260
+ assert dict_from_expr(3*sqrt(
261
+ 2)*pi*x*y, extension=None) == ({(1, 1, 1, 1): 3}, (x, y, pi, sqrt(2)))
262
+ assert dict_from_expr(3*sqrt(
263
+ 2)*pi*x*y, extension=True) == ({(1, 1, 1): 3*sqrt(2)}, (x, y, pi))
264
+
265
+ assert dict_from_expr(3*sqrt(
266
+ 2)*pi*x*y, extension=True) == ({(1, 1, 1): 3*sqrt(2)}, (x, y, pi))
267
+
268
+ f = cos(x)*sin(x) + cos(x)*sin(y) + cos(y)*sin(x) + cos(y)*sin(y)
269
+
270
+ assert dict_from_expr(f) == ({(0, 1, 0, 1): 1, (0, 1, 1, 0): 1,
271
+ (1, 0, 0, 1): 1, (1, 0, 1, 0): 1}, (cos(x), cos(y), sin(x), sin(y)))
272
+
273
+
274
+ def test__parallel_dict_from_expr_if_gens():
275
+ assert parallel_dict_from_expr([x + 2*y + 3*z, Integer(7)], gens=(x,)) == \
276
+ ([{(1,): Integer(1), (0,): 2*y + 3*z}, {(0,): Integer(7)}], (x,))
277
+
278
+
279
+ def test__parallel_dict_from_expr_no_gens():
280
+ assert parallel_dict_from_expr([x*y, Integer(3)]) == \
281
+ ([{(1, 1): Integer(1)}, {(0, 0): Integer(3)}], (x, y))
282
+ assert parallel_dict_from_expr([x*y, 2*z, Integer(3)]) == \
283
+ ([{(1, 1, 0): Integer(
284
+ 1)}, {(0, 0, 1): Integer(2)}, {(0, 0, 0): Integer(3)}], (x, y, z))
285
+ assert parallel_dict_from_expr((Mul(x, x**2, evaluate=False),)) == \
286
+ ([{(3,): 1}], (x,))
287
+
288
+
289
+ def test_parallel_dict_from_expr():
290
+ assert parallel_dict_from_expr([Eq(x, 1), Eq(
291
+ x**2, 2)]) == ([{(0,): -Integer(1), (1,): Integer(1)},
292
+ {(0,): -Integer(2), (2,): Integer(1)}], (x,))
293
+ raises(PolynomialError, lambda: parallel_dict_from_expr([A*B - B*A]))
294
+
295
+
296
+ def test_dict_from_expr():
297
+ assert dict_from_expr(Eq(x, 1)) == \
298
+ ({(0,): -Integer(1), (1,): Integer(1)}, (x,))
299
+ raises(PolynomialError, lambda: dict_from_expr(A*B - B*A))
300
+ raises(PolynomialError, lambda: dict_from_expr(S.true))
valley/lib/python3.10/site-packages/sympy/polys/tests/test_pythonrational.py ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Tests for PythonRational type. """
2
+
3
+ from sympy.polys.domains import PythonRational as QQ
4
+ from sympy.testing.pytest import raises
5
+
6
+ def test_PythonRational__init__():
7
+ assert QQ(0).numerator == 0
8
+ assert QQ(0).denominator == 1
9
+ assert QQ(0, 1).numerator == 0
10
+ assert QQ(0, 1).denominator == 1
11
+ assert QQ(0, -1).numerator == 0
12
+ assert QQ(0, -1).denominator == 1
13
+
14
+ assert QQ(1).numerator == 1
15
+ assert QQ(1).denominator == 1
16
+ assert QQ(1, 1).numerator == 1
17
+ assert QQ(1, 1).denominator == 1
18
+ assert QQ(-1, -1).numerator == 1
19
+ assert QQ(-1, -1).denominator == 1
20
+
21
+ assert QQ(-1).numerator == -1
22
+ assert QQ(-1).denominator == 1
23
+ assert QQ(-1, 1).numerator == -1
24
+ assert QQ(-1, 1).denominator == 1
25
+ assert QQ( 1, -1).numerator == -1
26
+ assert QQ( 1, -1).denominator == 1
27
+
28
+ assert QQ(1, 2).numerator == 1
29
+ assert QQ(1, 2).denominator == 2
30
+ assert QQ(3, 4).numerator == 3
31
+ assert QQ(3, 4).denominator == 4
32
+
33
+ assert QQ(2, 2).numerator == 1
34
+ assert QQ(2, 2).denominator == 1
35
+ assert QQ(2, 4).numerator == 1
36
+ assert QQ(2, 4).denominator == 2
37
+
38
+ def test_PythonRational__hash__():
39
+ assert hash(QQ(0)) == hash(0)
40
+ assert hash(QQ(1)) == hash(1)
41
+ assert hash(QQ(117)) == hash(117)
42
+
43
+ def test_PythonRational__int__():
44
+ assert int(QQ(-1, 4)) == 0
45
+ assert int(QQ( 1, 4)) == 0
46
+ assert int(QQ(-5, 4)) == -1
47
+ assert int(QQ( 5, 4)) == 1
48
+
49
+ def test_PythonRational__float__():
50
+ assert float(QQ(-1, 2)) == -0.5
51
+ assert float(QQ( 1, 2)) == 0.5
52
+
53
+ def test_PythonRational__abs__():
54
+ assert abs(QQ(-1, 2)) == QQ(1, 2)
55
+ assert abs(QQ( 1, 2)) == QQ(1, 2)
56
+
57
+ def test_PythonRational__pos__():
58
+ assert +QQ(-1, 2) == QQ(-1, 2)
59
+ assert +QQ( 1, 2) == QQ( 1, 2)
60
+
61
+ def test_PythonRational__neg__():
62
+ assert -QQ(-1, 2) == QQ( 1, 2)
63
+ assert -QQ( 1, 2) == QQ(-1, 2)
64
+
65
+ def test_PythonRational__add__():
66
+ assert QQ(-1, 2) + QQ( 1, 2) == QQ(0)
67
+ assert QQ( 1, 2) + QQ(-1, 2) == QQ(0)
68
+
69
+ assert QQ(1, 2) + QQ(1, 2) == QQ(1)
70
+ assert QQ(1, 2) + QQ(3, 2) == QQ(2)
71
+ assert QQ(3, 2) + QQ(1, 2) == QQ(2)
72
+ assert QQ(3, 2) + QQ(3, 2) == QQ(3)
73
+
74
+ assert 1 + QQ(1, 2) == QQ(3, 2)
75
+ assert QQ(1, 2) + 1 == QQ(3, 2)
76
+
77
+ def test_PythonRational__sub__():
78
+ assert QQ(-1, 2) - QQ( 1, 2) == QQ(-1)
79
+ assert QQ( 1, 2) - QQ(-1, 2) == QQ( 1)
80
+
81
+ assert QQ(1, 2) - QQ(1, 2) == QQ( 0)
82
+ assert QQ(1, 2) - QQ(3, 2) == QQ(-1)
83
+ assert QQ(3, 2) - QQ(1, 2) == QQ( 1)
84
+ assert QQ(3, 2) - QQ(3, 2) == QQ( 0)
85
+
86
+ assert 1 - QQ(1, 2) == QQ( 1, 2)
87
+ assert QQ(1, 2) - 1 == QQ(-1, 2)
88
+
89
+ def test_PythonRational__mul__():
90
+ assert QQ(-1, 2) * QQ( 1, 2) == QQ(-1, 4)
91
+ assert QQ( 1, 2) * QQ(-1, 2) == QQ(-1, 4)
92
+
93
+ assert QQ(1, 2) * QQ(1, 2) == QQ(1, 4)
94
+ assert QQ(1, 2) * QQ(3, 2) == QQ(3, 4)
95
+ assert QQ(3, 2) * QQ(1, 2) == QQ(3, 4)
96
+ assert QQ(3, 2) * QQ(3, 2) == QQ(9, 4)
97
+
98
+ assert 2 * QQ(1, 2) == QQ(1)
99
+ assert QQ(1, 2) * 2 == QQ(1)
100
+
101
+ def test_PythonRational__truediv__():
102
+ assert QQ(-1, 2) / QQ( 1, 2) == QQ(-1)
103
+ assert QQ( 1, 2) / QQ(-1, 2) == QQ(-1)
104
+
105
+ assert QQ(1, 2) / QQ(1, 2) == QQ(1)
106
+ assert QQ(1, 2) / QQ(3, 2) == QQ(1, 3)
107
+ assert QQ(3, 2) / QQ(1, 2) == QQ(3)
108
+ assert QQ(3, 2) / QQ(3, 2) == QQ(1)
109
+
110
+ assert 2 / QQ(1, 2) == QQ(4)
111
+ assert QQ(1, 2) / 2 == QQ(1, 4)
112
+
113
+ raises(ZeroDivisionError, lambda: QQ(1, 2) / QQ(0))
114
+ raises(ZeroDivisionError, lambda: QQ(1, 2) / 0)
115
+
116
+ def test_PythonRational__pow__():
117
+ assert QQ(1)**10 == QQ(1)
118
+ assert QQ(2)**10 == QQ(1024)
119
+
120
+ assert QQ(1)**(-10) == QQ(1)
121
+ assert QQ(2)**(-10) == QQ(1, 1024)
122
+
123
+ def test_PythonRational__eq__():
124
+ assert (QQ(1, 2) == QQ(1, 2)) is True
125
+ assert (QQ(1, 2) != QQ(1, 2)) is False
126
+
127
+ assert (QQ(1, 2) == QQ(1, 3)) is False
128
+ assert (QQ(1, 2) != QQ(1, 3)) is True
129
+
130
+ def test_PythonRational__lt_le_gt_ge__():
131
+ assert (QQ(1, 2) < QQ(1, 4)) is False
132
+ assert (QQ(1, 2) <= QQ(1, 4)) is False
133
+ assert (QQ(1, 2) > QQ(1, 4)) is True
134
+ assert (QQ(1, 2) >= QQ(1, 4)) is True
135
+
136
+ assert (QQ(1, 4) < QQ(1, 2)) is True
137
+ assert (QQ(1, 4) <= QQ(1, 2)) is True
138
+ assert (QQ(1, 4) > QQ(1, 2)) is False
139
+ assert (QQ(1, 4) >= QQ(1, 2)) is False
valley/lib/python3.10/site-packages/sympy/polys/tests/test_rootoftools.py ADDED
@@ -0,0 +1,653 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Tests for the implementation of RootOf class and related tools. """
2
+
3
+ from sympy.polys.polytools import Poly
4
+ import sympy.polys.rootoftools as rootoftools
5
+ from sympy.polys.rootoftools import (rootof, RootOf, CRootOf, RootSum,
6
+ _pure_key_dict as D)
7
+
8
+ from sympy.polys.polyerrors import (
9
+ MultivariatePolynomialError,
10
+ GeneratorsNeeded,
11
+ PolynomialError,
12
+ )
13
+
14
+ from sympy.core.function import (Function, Lambda)
15
+ from sympy.core.numbers import (Float, I, Rational)
16
+ from sympy.core.relational import Eq
17
+ from sympy.core.singleton import S
18
+ from sympy.functions.elementary.exponential import (exp, log)
19
+ from sympy.functions.elementary.miscellaneous import sqrt
20
+ from sympy.functions.elementary.trigonometric import tan
21
+ from sympy.integrals.integrals import Integral
22
+ from sympy.polys.orthopolys import legendre_poly
23
+ from sympy.solvers.solvers import solve
24
+
25
+
26
+ from sympy.testing.pytest import raises, slow
27
+ from sympy.core.expr import unchanged
28
+
29
+ from sympy.abc import a, b, x, y, z, r
30
+
31
+
32
+ def test_CRootOf___new__():
33
+ assert rootof(x, 0) == 0
34
+ assert rootof(x, -1) == 0
35
+
36
+ assert rootof(x, S.Zero) == 0
37
+
38
+ assert rootof(x - 1, 0) == 1
39
+ assert rootof(x - 1, -1) == 1
40
+
41
+ assert rootof(x + 1, 0) == -1
42
+ assert rootof(x + 1, -1) == -1
43
+
44
+ assert rootof(x**2 + 2*x + 3, 0) == -1 - I*sqrt(2)
45
+ assert rootof(x**2 + 2*x + 3, 1) == -1 + I*sqrt(2)
46
+ assert rootof(x**2 + 2*x + 3, -1) == -1 + I*sqrt(2)
47
+ assert rootof(x**2 + 2*x + 3, -2) == -1 - I*sqrt(2)
48
+
49
+ r = rootof(x**2 + 2*x + 3, 0, radicals=False)
50
+ assert isinstance(r, RootOf) is True
51
+
52
+ r = rootof(x**2 + 2*x + 3, 1, radicals=False)
53
+ assert isinstance(r, RootOf) is True
54
+
55
+ r = rootof(x**2 + 2*x + 3, -1, radicals=False)
56
+ assert isinstance(r, RootOf) is True
57
+
58
+ r = rootof(x**2 + 2*x + 3, -2, radicals=False)
59
+ assert isinstance(r, RootOf) is True
60
+
61
+ assert rootof((x - 1)*(x + 1), 0, radicals=False) == -1
62
+ assert rootof((x - 1)*(x + 1), 1, radicals=False) == 1
63
+ assert rootof((x - 1)*(x + 1), -1, radicals=False) == 1
64
+ assert rootof((x - 1)*(x + 1), -2, radicals=False) == -1
65
+
66
+ assert rootof((x - 1)*(x + 1), 0, radicals=True) == -1
67
+ assert rootof((x - 1)*(x + 1), 1, radicals=True) == 1
68
+ assert rootof((x - 1)*(x + 1), -1, radicals=True) == 1
69
+ assert rootof((x - 1)*(x + 1), -2, radicals=True) == -1
70
+
71
+ assert rootof((x - 1)*(x**3 + x + 3), 0) == rootof(x**3 + x + 3, 0)
72
+ assert rootof((x - 1)*(x**3 + x + 3), 1) == 1
73
+ assert rootof((x - 1)*(x**3 + x + 3), 2) == rootof(x**3 + x + 3, 1)
74
+ assert rootof((x - 1)*(x**3 + x + 3), 3) == rootof(x**3 + x + 3, 2)
75
+ assert rootof((x - 1)*(x**3 + x + 3), -1) == rootof(x**3 + x + 3, 2)
76
+ assert rootof((x - 1)*(x**3 + x + 3), -2) == rootof(x**3 + x + 3, 1)
77
+ assert rootof((x - 1)*(x**3 + x + 3), -3) == 1
78
+ assert rootof((x - 1)*(x**3 + x + 3), -4) == rootof(x**3 + x + 3, 0)
79
+
80
+ assert rootof(x**4 + 3*x**3, 0) == -3
81
+ assert rootof(x**4 + 3*x**3, 1) == 0
82
+ assert rootof(x**4 + 3*x**3, 2) == 0
83
+ assert rootof(x**4 + 3*x**3, 3) == 0
84
+
85
+ raises(GeneratorsNeeded, lambda: rootof(0, 0))
86
+ raises(GeneratorsNeeded, lambda: rootof(1, 0))
87
+
88
+ raises(PolynomialError, lambda: rootof(Poly(0, x), 0))
89
+ raises(PolynomialError, lambda: rootof(Poly(1, x), 0))
90
+ raises(PolynomialError, lambda: rootof(x - y, 0))
91
+ # issue 8617
92
+ raises(PolynomialError, lambda: rootof(exp(x), 0))
93
+
94
+ raises(NotImplementedError, lambda: rootof(x**3 - x + sqrt(2), 0))
95
+ raises(NotImplementedError, lambda: rootof(x**3 - x + I, 0))
96
+
97
+ raises(IndexError, lambda: rootof(x**2 - 1, -4))
98
+ raises(IndexError, lambda: rootof(x**2 - 1, -3))
99
+ raises(IndexError, lambda: rootof(x**2 - 1, 2))
100
+ raises(IndexError, lambda: rootof(x**2 - 1, 3))
101
+ raises(ValueError, lambda: rootof(x**2 - 1, x))
102
+
103
+ assert rootof(Poly(x - y, x), 0) == y
104
+
105
+ assert rootof(Poly(x**2 - y, x), 0) == -sqrt(y)
106
+ assert rootof(Poly(x**2 - y, x), 1) == sqrt(y)
107
+
108
+ assert rootof(Poly(x**3 - y, x), 0) == y**Rational(1, 3)
109
+
110
+ assert rootof(y*x**3 + y*x + 2*y, x, 0) == -1
111
+ raises(NotImplementedError, lambda: rootof(x**3 + x + 2*y, x, 0))
112
+
113
+ assert rootof(x**3 + x + 1, 0).is_commutative is True
114
+
115
+
116
+ def test_CRootOf_attributes():
117
+ r = rootof(x**3 + x + 3, 0)
118
+ assert r.is_number
119
+ assert r.free_symbols == set()
120
+ # if the following assertion fails then multivariate polynomials
121
+ # are apparently supported and the RootOf.free_symbols routine
122
+ # should be changed to return whatever symbols would not be
123
+ # the PurePoly dummy symbol
124
+ raises(NotImplementedError, lambda: rootof(Poly(x**3 + y*x + 1, x), 0))
125
+
126
+
127
+ def test_CRootOf___eq__():
128
+ assert (rootof(x**3 + x + 3, 0) == rootof(x**3 + x + 3, 0)) is True
129
+ assert (rootof(x**3 + x + 3, 0) == rootof(x**3 + x + 3, 1)) is False
130
+ assert (rootof(x**3 + x + 3, 1) == rootof(x**3 + x + 3, 1)) is True
131
+ assert (rootof(x**3 + x + 3, 1) == rootof(x**3 + x + 3, 2)) is False
132
+ assert (rootof(x**3 + x + 3, 2) == rootof(x**3 + x + 3, 2)) is True
133
+
134
+ assert (rootof(x**3 + x + 3, 0) == rootof(y**3 + y + 3, 0)) is True
135
+ assert (rootof(x**3 + x + 3, 0) == rootof(y**3 + y + 3, 1)) is False
136
+ assert (rootof(x**3 + x + 3, 1) == rootof(y**3 + y + 3, 1)) is True
137
+ assert (rootof(x**3 + x + 3, 1) == rootof(y**3 + y + 3, 2)) is False
138
+ assert (rootof(x**3 + x + 3, 2) == rootof(y**3 + y + 3, 2)) is True
139
+
140
+
141
+ def test_CRootOf___eval_Eq__():
142
+ f = Function('f')
143
+ eq = x**3 + x + 3
144
+ r = rootof(eq, 2)
145
+ r1 = rootof(eq, 1)
146
+ assert Eq(r, r1) is S.false
147
+ assert Eq(r, r) is S.true
148
+ assert unchanged(Eq, r, x)
149
+ assert Eq(r, 0) is S.false
150
+ assert Eq(r, S.Infinity) is S.false
151
+ assert Eq(r, I) is S.false
152
+ assert unchanged(Eq, r, f(0))
153
+ sol = solve(eq)
154
+ for s in sol:
155
+ if s.is_real:
156
+ assert Eq(r, s) is S.false
157
+ r = rootof(eq, 0)
158
+ for s in sol:
159
+ if s.is_real:
160
+ assert Eq(r, s) is S.true
161
+ eq = x**3 + x + 1
162
+ sol = solve(eq)
163
+ assert [Eq(rootof(eq, i), j) for i in range(3) for j in sol
164
+ ].count(True) == 3
165
+ assert Eq(rootof(eq, 0), 1 + S.ImaginaryUnit) == False
166
+
167
+
168
+ def test_CRootOf_is_real():
169
+ assert rootof(x**3 + x + 3, 0).is_real is True
170
+ assert rootof(x**3 + x + 3, 1).is_real is False
171
+ assert rootof(x**3 + x + 3, 2).is_real is False
172
+
173
+
174
+ def test_CRootOf_is_complex():
175
+ assert rootof(x**3 + x + 3, 0).is_complex is True
176
+
177
+
178
+ def test_CRootOf_subs():
179
+ assert rootof(x**3 + x + 1, 0).subs(x, y) == rootof(y**3 + y + 1, 0)
180
+
181
+
182
+ def test_CRootOf_diff():
183
+ assert rootof(x**3 + x + 1, 0).diff(x) == 0
184
+ assert rootof(x**3 + x + 1, 0).diff(y) == 0
185
+
186
+
187
+ @slow
188
+ def test_CRootOf_evalf():
189
+ real = rootof(x**3 + x + 3, 0).evalf(n=20)
190
+
191
+ assert real.epsilon_eq(Float("-1.2134116627622296341"))
192
+
193
+ re, im = rootof(x**3 + x + 3, 1).evalf(n=20).as_real_imag()
194
+
195
+ assert re.epsilon_eq( Float("0.60670583138111481707"))
196
+ assert im.epsilon_eq(-Float("1.45061224918844152650"))
197
+
198
+ re, im = rootof(x**3 + x + 3, 2).evalf(n=20).as_real_imag()
199
+
200
+ assert re.epsilon_eq(Float("0.60670583138111481707"))
201
+ assert im.epsilon_eq(Float("1.45061224918844152650"))
202
+
203
+ p = legendre_poly(4, x, polys=True)
204
+ roots = [str(r.n(17)) for r in p.real_roots()]
205
+ # magnitudes are given by
206
+ # sqrt(3/S(7) - 2*sqrt(6/S(5))/7)
207
+ # and
208
+ # sqrt(3/S(7) + 2*sqrt(6/S(5))/7)
209
+ assert roots == [
210
+ "-0.86113631159405258",
211
+ "-0.33998104358485626",
212
+ "0.33998104358485626",
213
+ "0.86113631159405258",
214
+ ]
215
+
216
+ re = rootof(x**5 - 5*x + 12, 0).evalf(n=20)
217
+ assert re.epsilon_eq(Float("-1.84208596619025438271"))
218
+
219
+ re, im = rootof(x**5 - 5*x + 12, 1).evalf(n=20).as_real_imag()
220
+ assert re.epsilon_eq(Float("-0.351854240827371999559"))
221
+ assert im.epsilon_eq(Float("-1.709561043370328882010"))
222
+
223
+ re, im = rootof(x**5 - 5*x + 12, 2).evalf(n=20).as_real_imag()
224
+ assert re.epsilon_eq(Float("-0.351854240827371999559"))
225
+ assert im.epsilon_eq(Float("+1.709561043370328882010"))
226
+
227
+ re, im = rootof(x**5 - 5*x + 12, 3).evalf(n=20).as_real_imag()
228
+ assert re.epsilon_eq(Float("+1.272897223922499190910"))
229
+ assert im.epsilon_eq(Float("-0.719798681483861386681"))
230
+
231
+ re, im = rootof(x**5 - 5*x + 12, 4).evalf(n=20).as_real_imag()
232
+ assert re.epsilon_eq(Float("+1.272897223922499190910"))
233
+ assert im.epsilon_eq(Float("+0.719798681483861386681"))
234
+
235
+ # issue 6393
236
+ assert str(rootof(x**5 + 2*x**4 + x**3 - 68719476736, 0).n(3)) == '147.'
237
+ eq = (531441*x**11 + 3857868*x**10 + 13730229*x**9 + 32597882*x**8 +
238
+ 55077472*x**7 + 60452000*x**6 + 32172064*x**5 - 4383808*x**4 -
239
+ 11942912*x**3 - 1506304*x**2 + 1453312*x + 512)
240
+ a, b = rootof(eq, 1).n(2).as_real_imag()
241
+ c, d = rootof(eq, 2).n(2).as_real_imag()
242
+ assert a == c
243
+ assert b < d
244
+ assert b == -d
245
+ # issue 6451
246
+ r = rootof(legendre_poly(64, x), 7)
247
+ assert r.n(2) == r.n(100).n(2)
248
+ # issue 9019
249
+ r0 = rootof(x**2 + 1, 0, radicals=False)
250
+ r1 = rootof(x**2 + 1, 1, radicals=False)
251
+ assert r0.n(4) == Float(-1.0, 4) * I
252
+ assert r1.n(4) == Float(1.0, 4) * I
253
+
254
+ # make sure verification is used in case a max/min traps the "root"
255
+ assert str(rootof(4*x**5 + 16*x**3 + 12*x**2 + 7, 0).n(3)) == '-0.976'
256
+
257
+ # watch out for UnboundLocalError
258
+ c = CRootOf(90720*x**6 - 4032*x**4 + 84*x**2 - 1, 0)
259
+ assert c._eval_evalf(2) # doesn't fail
260
+
261
+ # watch out for imaginary parts that don't want to evaluate
262
+ assert str(RootOf(x**16 + 32*x**14 + 508*x**12 + 5440*x**10 +
263
+ 39510*x**8 + 204320*x**6 + 755548*x**4 + 1434496*x**2 +
264
+ 877969, 10).n(2)) == '-3.4*I'
265
+ assert abs(RootOf(x**4 + 10*x**2 + 1, 0).n(2)) < 0.4
266
+
267
+ # check reset and args
268
+ r = [RootOf(x**3 + x + 3, i) for i in range(3)]
269
+ r[0]._reset()
270
+ for ri in r:
271
+ i = ri._get_interval()
272
+ ri.n(2)
273
+ assert i != ri._get_interval()
274
+ ri._reset()
275
+ assert i == ri._get_interval()
276
+ assert i == i.func(*i.args)
277
+
278
+
279
+ def test_issue_24978():
280
+ # Irreducible poly with negative leading coeff is normalized
281
+ # (factor of -1 is extracted), before being stored as CRootOf.poly.
282
+ f = -x**2 + 2
283
+ r = CRootOf(f, 0)
284
+ assert r.poly.as_expr() == x**2 - 2
285
+ # An action that prompts calculation of an interval puts r.poly in
286
+ # the cache.
287
+ r.n()
288
+ assert r.poly in rootoftools._reals_cache
289
+
290
+
291
+ def test_CRootOf_evalf_caching_bug():
292
+ r = rootof(x**5 - 5*x + 12, 1)
293
+ r.n()
294
+ a = r._get_interval()
295
+ r = rootof(x**5 - 5*x + 12, 1)
296
+ r.n()
297
+ b = r._get_interval()
298
+ assert a == b
299
+
300
+
301
+ def test_CRootOf_real_roots():
302
+ assert Poly(x**5 + x + 1).real_roots() == [rootof(x**3 - x**2 + 1, 0)]
303
+ assert Poly(x**5 + x + 1).real_roots(radicals=False) == [rootof(
304
+ x**3 - x**2 + 1, 0)]
305
+
306
+ # https://github.com/sympy/sympy/issues/20902
307
+ p = Poly(-3*x**4 - 10*x**3 - 12*x**2 - 6*x - 1, x, domain='ZZ')
308
+ assert CRootOf.real_roots(p) == [S(-1), S(-1), S(-1), S(-1)/3]
309
+
310
+
311
+ def test_CRootOf_all_roots():
312
+ assert Poly(x**5 + x + 1).all_roots() == [
313
+ rootof(x**3 - x**2 + 1, 0),
314
+ Rational(-1, 2) - sqrt(3)*I/2,
315
+ Rational(-1, 2) + sqrt(3)*I/2,
316
+ rootof(x**3 - x**2 + 1, 1),
317
+ rootof(x**3 - x**2 + 1, 2),
318
+ ]
319
+
320
+ assert Poly(x**5 + x + 1).all_roots(radicals=False) == [
321
+ rootof(x**3 - x**2 + 1, 0),
322
+ rootof(x**2 + x + 1, 0, radicals=False),
323
+ rootof(x**2 + x + 1, 1, radicals=False),
324
+ rootof(x**3 - x**2 + 1, 1),
325
+ rootof(x**3 - x**2 + 1, 2),
326
+ ]
327
+
328
+
329
+ def test_CRootOf_eval_rational():
330
+ p = legendre_poly(4, x, polys=True)
331
+ roots = [r.eval_rational(n=18) for r in p.real_roots()]
332
+ for root in roots:
333
+ assert isinstance(root, Rational)
334
+ roots = [str(root.n(17)) for root in roots]
335
+ assert roots == [
336
+ "-0.86113631159405258",
337
+ "-0.33998104358485626",
338
+ "0.33998104358485626",
339
+ "0.86113631159405258",
340
+ ]
341
+
342
+
343
+ def test_CRootOf_lazy():
344
+ # irreducible poly with both real and complex roots:
345
+ f = Poly(x**3 + 2*x + 2)
346
+
347
+ # real root:
348
+ CRootOf.clear_cache()
349
+ r = CRootOf(f, 0)
350
+ # Not yet in cache, after construction:
351
+ assert r.poly not in rootoftools._reals_cache
352
+ assert r.poly not in rootoftools._complexes_cache
353
+ r.evalf()
354
+ # In cache after evaluation:
355
+ assert r.poly in rootoftools._reals_cache
356
+ assert r.poly not in rootoftools._complexes_cache
357
+
358
+ # complex root:
359
+ CRootOf.clear_cache()
360
+ r = CRootOf(f, 1)
361
+ # Not yet in cache, after construction:
362
+ assert r.poly not in rootoftools._reals_cache
363
+ assert r.poly not in rootoftools._complexes_cache
364
+ r.evalf()
365
+ # In cache after evaluation:
366
+ assert r.poly in rootoftools._reals_cache
367
+ assert r.poly in rootoftools._complexes_cache
368
+
369
+ # composite poly with both real and complex roots:
370
+ f = Poly((x**2 - 2)*(x**2 + 1))
371
+
372
+ # real root:
373
+ CRootOf.clear_cache()
374
+ r = CRootOf(f, 0)
375
+ # In cache immediately after construction:
376
+ assert r.poly in rootoftools._reals_cache
377
+ assert r.poly not in rootoftools._complexes_cache
378
+
379
+ # complex root:
380
+ CRootOf.clear_cache()
381
+ r = CRootOf(f, 2)
382
+ # In cache immediately after construction:
383
+ assert r.poly in rootoftools._reals_cache
384
+ assert r.poly in rootoftools._complexes_cache
385
+
386
+
387
+ def test_RootSum___new__():
388
+ f = x**3 + x + 3
389
+
390
+ g = Lambda(r, log(r*x))
391
+ s = RootSum(f, g)
392
+
393
+ assert isinstance(s, RootSum) is True
394
+
395
+ assert RootSum(f**2, g) == 2*RootSum(f, g)
396
+ assert RootSum((x - 7)*f**3, g) == log(7*x) + 3*RootSum(f, g)
397
+
398
+ # issue 5571
399
+ assert hash(RootSum((x - 7)*f**3, g)) == hash(log(7*x) + 3*RootSum(f, g))
400
+
401
+ raises(MultivariatePolynomialError, lambda: RootSum(x**3 + x + y))
402
+ raises(ValueError, lambda: RootSum(x**2 + 3, lambda x: x))
403
+
404
+ assert RootSum(f, exp) == RootSum(f, Lambda(x, exp(x)))
405
+ assert RootSum(f, log) == RootSum(f, Lambda(x, log(x)))
406
+
407
+ assert isinstance(RootSum(f, auto=False), RootSum) is True
408
+
409
+ assert RootSum(f) == 0
410
+ assert RootSum(f, Lambda(x, x)) == 0
411
+ assert RootSum(f, Lambda(x, x**2)) == -2
412
+
413
+ assert RootSum(f, Lambda(x, 1)) == 3
414
+ assert RootSum(f, Lambda(x, 2)) == 6
415
+
416
+ assert RootSum(f, auto=False).is_commutative is True
417
+
418
+ assert RootSum(f, Lambda(x, 1/(x + x**2))) == Rational(11, 3)
419
+ assert RootSum(f, Lambda(x, y/(x + x**2))) == Rational(11, 3)*y
420
+
421
+ assert RootSum(x**2 - 1, Lambda(x, 3*x**2), x) == 6
422
+ assert RootSum(x**2 - y, Lambda(x, 3*x**2), x) == 6*y
423
+
424
+ assert RootSum(x**2 - 1, Lambda(x, z*x**2), x) == 2*z
425
+ assert RootSum(x**2 - y, Lambda(x, z*x**2), x) == 2*z*y
426
+
427
+ assert RootSum(
428
+ x**2 - 1, Lambda(x, exp(x)), quadratic=True) == exp(-1) + exp(1)
429
+
430
+ assert RootSum(x**3 + a*x + a**3, tan, x) == \
431
+ RootSum(x**3 + x + 1, Lambda(x, tan(a*x)))
432
+ assert RootSum(a**3*x**3 + a*x + 1, tan, x) == \
433
+ RootSum(x**3 + x + 1, Lambda(x, tan(x/a)))
434
+
435
+
436
+ def test_RootSum_free_symbols():
437
+ assert RootSum(x**3 + x + 3, Lambda(r, exp(r))).free_symbols == set()
438
+ assert RootSum(x**3 + x + 3, Lambda(r, exp(a*r))).free_symbols == {a}
439
+ assert RootSum(
440
+ x**3 + x + y, Lambda(r, exp(a*r)), x).free_symbols == {a, y}
441
+
442
+
443
+ def test_RootSum___eq__():
444
+ f = Lambda(x, exp(x))
445
+
446
+ assert (RootSum(x**3 + x + 1, f) == RootSum(x**3 + x + 1, f)) is True
447
+ assert (RootSum(x**3 + x + 1, f) == RootSum(y**3 + y + 1, f)) is True
448
+
449
+ assert (RootSum(x**3 + x + 1, f) == RootSum(x**3 + x + 2, f)) is False
450
+ assert (RootSum(x**3 + x + 1, f) == RootSum(y**3 + y + 2, f)) is False
451
+
452
+
453
+ def test_RootSum_doit():
454
+ rs = RootSum(x**2 + 1, exp)
455
+
456
+ assert isinstance(rs, RootSum) is True
457
+ assert rs.doit() == exp(-I) + exp(I)
458
+
459
+ rs = RootSum(x**2 + a, exp, x)
460
+
461
+ assert isinstance(rs, RootSum) is True
462
+ assert rs.doit() == exp(-sqrt(-a)) + exp(sqrt(-a))
463
+
464
+
465
+ def test_RootSum_evalf():
466
+ rs = RootSum(x**2 + 1, exp)
467
+
468
+ assert rs.evalf(n=20, chop=True).epsilon_eq(Float("1.0806046117362794348"))
469
+ assert rs.evalf(n=15, chop=True).epsilon_eq(Float("1.08060461173628"))
470
+
471
+ rs = RootSum(x**2 + a, exp, x)
472
+
473
+ assert rs.evalf() == rs
474
+
475
+
476
+ def test_RootSum_diff():
477
+ f = x**3 + x + 3
478
+
479
+ g = Lambda(r, exp(r*x))
480
+ h = Lambda(r, r*exp(r*x))
481
+
482
+ assert RootSum(f, g).diff(x) == RootSum(f, h)
483
+
484
+
485
+ def test_RootSum_subs():
486
+ f = x**3 + x + 3
487
+ g = Lambda(r, exp(r*x))
488
+
489
+ F = y**3 + y + 3
490
+ G = Lambda(r, exp(r*y))
491
+
492
+ assert RootSum(f, g).subs(y, 1) == RootSum(f, g)
493
+ assert RootSum(f, g).subs(x, y) == RootSum(F, G)
494
+
495
+
496
+ def test_RootSum_rational():
497
+ assert RootSum(
498
+ z**5 - z + 1, Lambda(z, z/(x - z))) == (4*x - 5)/(x**5 - x + 1)
499
+
500
+ f = 161*z**3 + 115*z**2 + 19*z + 1
501
+ g = Lambda(z, z*log(
502
+ -3381*z**4/4 - 3381*z**3/4 - 625*z**2/2 - z*Rational(125, 2) - 5 + exp(x)))
503
+
504
+ assert RootSum(f, g).diff(x) == -(
505
+ (5*exp(2*x) - 6*exp(x) + 4)*exp(x)/(exp(3*x) - exp(2*x) + 1))/7
506
+
507
+
508
+ def test_RootSum_independent():
509
+ f = (x**3 - a)**2*(x**4 - b)**3
510
+
511
+ g = Lambda(x, 5*tan(x) + 7)
512
+ h = Lambda(x, tan(x))
513
+
514
+ r0 = RootSum(x**3 - a, h, x)
515
+ r1 = RootSum(x**4 - b, h, x)
516
+
517
+ assert RootSum(f, g, x).as_ordered_terms() == [10*r0, 15*r1, 126]
518
+
519
+
520
+ def test_issue_7876():
521
+ l1 = Poly(x**6 - x + 1, x).all_roots()
522
+ l2 = [rootof(x**6 - x + 1, i) for i in range(6)]
523
+ assert frozenset(l1) == frozenset(l2)
524
+
525
+
526
+ def test_issue_8316():
527
+ f = Poly(7*x**8 - 9)
528
+ assert len(f.all_roots()) == 8
529
+ f = Poly(7*x**8 - 10)
530
+ assert len(f.all_roots()) == 8
531
+
532
+
533
+ def test__imag_count():
534
+ from sympy.polys.rootoftools import _imag_count_of_factor
535
+ def imag_count(p):
536
+ return sum(_imag_count_of_factor(f)*m for f, m in
537
+ p.factor_list()[1])
538
+ assert imag_count(Poly(x**6 + 10*x**2 + 1)) == 2
539
+ assert imag_count(Poly(x**2)) == 0
540
+ assert imag_count(Poly([1]*3 + [-1], x)) == 0
541
+ assert imag_count(Poly(x**3 + 1)) == 0
542
+ assert imag_count(Poly(x**2 + 1)) == 2
543
+ assert imag_count(Poly(x**2 - 1)) == 0
544
+ assert imag_count(Poly(x**4 - 1)) == 2
545
+ assert imag_count(Poly(x**4 + 1)) == 0
546
+ assert imag_count(Poly([1, 2, 3], x)) == 0
547
+ assert imag_count(Poly(x**3 + x + 1)) == 0
548
+ assert imag_count(Poly(x**4 + x + 1)) == 0
549
+ def q(r1, r2, p):
550
+ return Poly(((x - r1)*(x - r2)).subs(x, x**p), x)
551
+ assert imag_count(q(-1, -2, 2)) == 4
552
+ assert imag_count(q(-1, 2, 2)) == 2
553
+ assert imag_count(q(1, 2, 2)) == 0
554
+ assert imag_count(q(1, 2, 4)) == 4
555
+ assert imag_count(q(-1, 2, 4)) == 2
556
+ assert imag_count(q(-1, -2, 4)) == 0
557
+
558
+
559
+ def test_RootOf_is_imaginary():
560
+ r = RootOf(x**4 + 4*x**2 + 1, 1)
561
+ i = r._get_interval()
562
+ assert r.is_imaginary and i.ax*i.bx <= 0
563
+
564
+
565
+ def test_is_disjoint():
566
+ eq = x**3 + 5*x + 1
567
+ ir = rootof(eq, 0)._get_interval()
568
+ ii = rootof(eq, 1)._get_interval()
569
+ assert ir.is_disjoint(ii)
570
+ assert ii.is_disjoint(ir)
571
+
572
+
573
+ def test_pure_key_dict():
574
+ p = D()
575
+ assert (x in p) is False
576
+ assert (1 in p) is False
577
+ p[x] = 1
578
+ assert x in p
579
+ assert y in p
580
+ assert p[y] == 1
581
+ raises(KeyError, lambda: p[1])
582
+ def dont(k):
583
+ p[k] = 2
584
+ raises(ValueError, lambda: dont(1))
585
+
586
+
587
+ @slow
588
+ def test_eval_approx_relative():
589
+ CRootOf.clear_cache()
590
+ t = [CRootOf(x**3 + 10*x + 1, i) for i in range(3)]
591
+ assert [i.eval_rational(1e-1) for i in t] == [
592
+ Rational(-21, 220), Rational(15, 256) - I*805/256,
593
+ Rational(15, 256) + I*805/256]
594
+ t[0]._reset()
595
+ assert [i.eval_rational(1e-1, 1e-4) for i in t] == [
596
+ Rational(-21, 220), Rational(3275, 65536) - I*414645/131072,
597
+ Rational(3275, 65536) + I*414645/131072]
598
+ assert S(t[0]._get_interval().dx) < 1e-1
599
+ assert S(t[1]._get_interval().dx) < 1e-1
600
+ assert S(t[1]._get_interval().dy) < 1e-4
601
+ assert S(t[2]._get_interval().dx) < 1e-1
602
+ assert S(t[2]._get_interval().dy) < 1e-4
603
+ t[0]._reset()
604
+ assert [i.eval_rational(1e-4, 1e-4) for i in t] == [
605
+ Rational(-2001, 20020), Rational(6545, 131072) - I*414645/131072,
606
+ Rational(6545, 131072) + I*414645/131072]
607
+ assert S(t[0]._get_interval().dx) < 1e-4
608
+ assert S(t[1]._get_interval().dx) < 1e-4
609
+ assert S(t[1]._get_interval().dy) < 1e-4
610
+ assert S(t[2]._get_interval().dx) < 1e-4
611
+ assert S(t[2]._get_interval().dy) < 1e-4
612
+ # in the following, the actual relative precision is
613
+ # less than tested, but it should never be greater
614
+ t[0]._reset()
615
+ assert [i.eval_rational(n=2) for i in t] == [
616
+ Rational(-202201, 2024022), Rational(104755, 2097152) - I*6634255/2097152,
617
+ Rational(104755, 2097152) + I*6634255/2097152]
618
+ assert abs(S(t[0]._get_interval().dx)/t[0]) < 1e-2
619
+ assert abs(S(t[1]._get_interval().dx)/t[1]).n() < 1e-2
620
+ assert abs(S(t[1]._get_interval().dy)/t[1]).n() < 1e-2
621
+ assert abs(S(t[2]._get_interval().dx)/t[2]).n() < 1e-2
622
+ assert abs(S(t[2]._get_interval().dy)/t[2]).n() < 1e-2
623
+ t[0]._reset()
624
+ assert [i.eval_rational(n=3) for i in t] == [
625
+ Rational(-202201, 2024022), Rational(1676045, 33554432) - I*106148135/33554432,
626
+ Rational(1676045, 33554432) + I*106148135/33554432]
627
+ assert abs(S(t[0]._get_interval().dx)/t[0]) < 1e-3
628
+ assert abs(S(t[1]._get_interval().dx)/t[1]).n() < 1e-3
629
+ assert abs(S(t[1]._get_interval().dy)/t[1]).n() < 1e-3
630
+ assert abs(S(t[2]._get_interval().dx)/t[2]).n() < 1e-3
631
+ assert abs(S(t[2]._get_interval().dy)/t[2]).n() < 1e-3
632
+
633
+ t[0]._reset()
634
+ a = [i.eval_approx(2) for i in t]
635
+ assert [str(i) for i in a] == [
636
+ '-0.10', '0.05 - 3.2*I', '0.05 + 3.2*I']
637
+ assert all(abs(((a[i] - t[i])/t[i]).n()) < 1e-2 for i in range(len(a)))
638
+
639
+
640
+ def test_issue_15920():
641
+ r = rootof(x**5 - x + 1, 0)
642
+ p = Integral(x, (x, 1, y))
643
+ assert unchanged(Eq, r, p)
644
+
645
+
646
+ def test_issue_19113():
647
+ eq = y**3 - y + 1
648
+ # generator is a canonical x in RootOf
649
+ assert str(Poly(eq).real_roots()) == '[CRootOf(x**3 - x + 1, 0)]'
650
+ assert str(Poly(eq.subs(y, tan(y))).real_roots()
651
+ ) == '[CRootOf(x**3 - x + 1, 0)]'
652
+ assert str(Poly(eq.subs(y, tan(x))).real_roots()
653
+ ) == '[CRootOf(x**3 - x + 1, 0)]'
valley/lib/python3.10/site-packages/sympy/polys/tests/test_specialpolys.py ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Tests for functions for generating interesting polynomials. """
2
+
3
+ from sympy.core.add import Add
4
+ from sympy.core.symbol import symbols
5
+ from sympy.functions.elementary.miscellaneous import sqrt
6
+ from sympy.ntheory.generate import prime
7
+ from sympy.polys.domains.integerring import ZZ
8
+ from sympy.polys.polytools import Poly
9
+ from sympy.utilities.iterables import permute_signs
10
+ from sympy.testing.pytest import raises
11
+
12
+ from sympy.polys.specialpolys import (
13
+ swinnerton_dyer_poly,
14
+ cyclotomic_poly,
15
+ symmetric_poly,
16
+ random_poly,
17
+ interpolating_poly,
18
+ fateman_poly_F_1,
19
+ dmp_fateman_poly_F_1,
20
+ fateman_poly_F_2,
21
+ dmp_fateman_poly_F_2,
22
+ fateman_poly_F_3,
23
+ dmp_fateman_poly_F_3,
24
+ )
25
+
26
+ from sympy.abc import x, y, z
27
+
28
+
29
+ def test_swinnerton_dyer_poly():
30
+ raises(ValueError, lambda: swinnerton_dyer_poly(0, x))
31
+
32
+ assert swinnerton_dyer_poly(1, x, polys=True) == Poly(x**2 - 2)
33
+
34
+ assert swinnerton_dyer_poly(1, x) == x**2 - 2
35
+ assert swinnerton_dyer_poly(2, x) == x**4 - 10*x**2 + 1
36
+ assert swinnerton_dyer_poly(
37
+ 3, x) == x**8 - 40*x**6 + 352*x**4 - 960*x**2 + 576
38
+ # we only need to check that the polys arg works but
39
+ # we may as well test that the roots are correct
40
+ p = [sqrt(prime(i)) for i in range(1, 5)]
41
+ assert str([i.n(3) for i in
42
+ swinnerton_dyer_poly(4, polys=True).all_roots()]
43
+ ) == str(sorted([Add(*i).n(3) for i in permute_signs(p)]))
44
+
45
+
46
+ def test_cyclotomic_poly():
47
+ raises(ValueError, lambda: cyclotomic_poly(0, x))
48
+
49
+ assert cyclotomic_poly(1, x, polys=True) == Poly(x - 1)
50
+
51
+ assert cyclotomic_poly(1, x) == x - 1
52
+ assert cyclotomic_poly(2, x) == x + 1
53
+ assert cyclotomic_poly(3, x) == x**2 + x + 1
54
+ assert cyclotomic_poly(4, x) == x**2 + 1
55
+ assert cyclotomic_poly(5, x) == x**4 + x**3 + x**2 + x + 1
56
+ assert cyclotomic_poly(6, x) == x**2 - x + 1
57
+
58
+
59
+ def test_symmetric_poly():
60
+ raises(ValueError, lambda: symmetric_poly(-1, x, y, z))
61
+ raises(ValueError, lambda: symmetric_poly(5, x, y, z))
62
+
63
+ assert symmetric_poly(1, x, y, z, polys=True) == Poly(x + y + z)
64
+ assert symmetric_poly(1, (x, y, z), polys=True) == Poly(x + y + z)
65
+
66
+ assert symmetric_poly(0, x, y, z) == 1
67
+ assert symmetric_poly(1, x, y, z) == x + y + z
68
+ assert symmetric_poly(2, x, y, z) == x*y + x*z + y*z
69
+ assert symmetric_poly(3, x, y, z) == x*y*z
70
+
71
+
72
+ def test_random_poly():
73
+ poly = random_poly(x, 10, -100, 100, polys=False)
74
+
75
+ assert Poly(poly).degree() == 10
76
+ assert all(-100 <= coeff <= 100 for coeff in Poly(poly).coeffs()) is True
77
+
78
+ poly = random_poly(x, 10, -100, 100, polys=True)
79
+
80
+ assert poly.degree() == 10
81
+ assert all(-100 <= coeff <= 100 for coeff in poly.coeffs()) is True
82
+
83
+
84
+ def test_interpolating_poly():
85
+ x0, x1, x2, x3, y0, y1, y2, y3 = symbols('x:4, y:4')
86
+
87
+ assert interpolating_poly(0, x) == 0
88
+ assert interpolating_poly(1, x) == y0
89
+
90
+ assert interpolating_poly(2, x) == \
91
+ y0*(x - x1)/(x0 - x1) + y1*(x - x0)/(x1 - x0)
92
+
93
+ assert interpolating_poly(3, x) == \
94
+ y0*(x - x1)*(x - x2)/((x0 - x1)*(x0 - x2)) + \
95
+ y1*(x - x0)*(x - x2)/((x1 - x0)*(x1 - x2)) + \
96
+ y2*(x - x0)*(x - x1)/((x2 - x0)*(x2 - x1))
97
+
98
+ assert interpolating_poly(4, x) == \
99
+ y0*(x - x1)*(x - x2)*(x - x3)/((x0 - x1)*(x0 - x2)*(x0 - x3)) + \
100
+ y1*(x - x0)*(x - x2)*(x - x3)/((x1 - x0)*(x1 - x2)*(x1 - x3)) + \
101
+ y2*(x - x0)*(x - x1)*(x - x3)/((x2 - x0)*(x2 - x1)*(x2 - x3)) + \
102
+ y3*(x - x0)*(x - x1)*(x - x2)/((x3 - x0)*(x3 - x1)*(x3 - x2))
103
+
104
+ raises(ValueError, lambda:
105
+ interpolating_poly(2, x, (x, 2), (1, 3)))
106
+ raises(ValueError, lambda:
107
+ interpolating_poly(2, x, (x + y, 2), (1, 3)))
108
+ raises(ValueError, lambda:
109
+ interpolating_poly(2, x + y, (x, 2), (1, 3)))
110
+ raises(ValueError, lambda:
111
+ interpolating_poly(2, 3, (4, 5), (6, 7)))
112
+ raises(ValueError, lambda:
113
+ interpolating_poly(2, 3, (4, 5), (6, 7, 8)))
114
+ assert interpolating_poly(0, x, (1, 2), (3, 4)) == 0
115
+ assert interpolating_poly(1, x, (1, 2), (3, 4)) == 3
116
+ assert interpolating_poly(2, x, (1, 2), (3, 4)) == x + 2
117
+
118
+
119
+ def test_fateman_poly_F_1():
120
+ f, g, h = fateman_poly_F_1(1)
121
+ F, G, H = dmp_fateman_poly_F_1(1, ZZ)
122
+
123
+ assert [ t.rep.to_list() for t in [f, g, h] ] == [F, G, H]
124
+
125
+ f, g, h = fateman_poly_F_1(3)
126
+ F, G, H = dmp_fateman_poly_F_1(3, ZZ)
127
+
128
+ assert [ t.rep.to_list() for t in [f, g, h] ] == [F, G, H]
129
+
130
+
131
+ def test_fateman_poly_F_2():
132
+ f, g, h = fateman_poly_F_2(1)
133
+ F, G, H = dmp_fateman_poly_F_2(1, ZZ)
134
+
135
+ assert [ t.rep.to_list() for t in [f, g, h] ] == [F, G, H]
136
+
137
+ f, g, h = fateman_poly_F_2(3)
138
+ F, G, H = dmp_fateman_poly_F_2(3, ZZ)
139
+
140
+ assert [ t.rep.to_list() for t in [f, g, h] ] == [F, G, H]
141
+
142
+
143
+ def test_fateman_poly_F_3():
144
+ f, g, h = fateman_poly_F_3(1)
145
+ F, G, H = dmp_fateman_poly_F_3(1, ZZ)
146
+
147
+ assert [ t.rep.to_list() for t in [f, g, h] ] == [F, G, H]
148
+
149
+ f, g, h = fateman_poly_F_3(3)
150
+ F, G, H = dmp_fateman_poly_F_3(3, ZZ)
151
+
152
+ assert [ t.rep.to_list() for t in [f, g, h] ] == [F, G, H]
wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/CheckIPOSupported/CMakeLists-Fortran.txt.in ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ cmake_minimum_required(VERSION "@CMAKE_VERSION@")
2
+ project("@TRY_COMPILE_PROJECT_NAME@" LANGUAGES Fortran)
3
+
4
+ cmake_policy(SET CMP0069 NEW)
5
+
6
+ add_library(foo foo.f)
7
+ add_executable(boo main.f)
8
+ target_link_libraries(boo PUBLIC foo)
wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/CheckIPOSupported/foo.c ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ int foo(void)
2
+ {
3
+ return 0x42;
4
+ }
wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/CheckIPOSupported/foo.cpp ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ int foo()
2
+ {
3
+ return 0x42;
4
+ }
wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/CheckIPOSupported/foo.f ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ SUBROUTINE FOO
2
+ END
wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/CheckIPOSupported/main.c ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ int foo(void);
2
+
3
+ int main(void)
4
+ {
5
+ return foo();
6
+ }
wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/CheckIPOSupported/main.f ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ PROGRAM BOO
2
+ CALL FOO()
3
+ END
wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/CompilerId/GHS_default.gpj.in ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ #!gbuild
2
+ @bsp_name@
3
+ @os_dir@
4
+ primaryTarget=@ghs_primary_target@
5
+ [Project]
6
+ {isdefined(GHS_BSP)} -bsp $GHS_BSP
7
+ {isdefined(GHS_OS)} -os_dir $GHS_OS
8
+ GHS_lib.gpj [Library]
wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/CompilerId/GHS_lib.gpj.in ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ #!gbuild
2
+ [Library]
3
+ @id_src@
wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/CompilerId/VS-10.csproj.in ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
+ <PropertyGroup Label="Globals">
4
+ <ProjectGuid>{CAE07175-D007-4FC3-BFE8-47B392814159}</ProjectGuid>
5
+ <RootNamespace>CompilerId@id_lang@</RootNamespace>
6
+ <Keyword>Win32Proj</Keyword>
7
+ @id_system@
8
+ @id_system_version@
9
+ @id_TargetFrameworkVersion@
10
+ @id_TargetFrameworkIdentifier@
11
+ @id_TargetFrameworkTargetsVersion@
12
+ @id_WindowsTargetPlatformVersion@
13
+ @id_WindowsSDKDesktopARMSupport@
14
+ </PropertyGroup>
15
+ <PropertyGroup>
16
+ @id_PreferredToolArchitecture@
17
+ </PropertyGroup>
18
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|@id_platform@'" Label="Configuration">
19
+ <ConfigurationType>Application</ConfigurationType>
20
+ @id_toolset@
21
+ <CharacterSet>MultiByte</CharacterSet>
22
+ </PropertyGroup>
23
+ <!-- ============================================================ -->
24
+ <!-- == set preprocessor definitions == -->
25
+ <!-- ============================================================ -->
26
+ <PropertyGroup>
27
+ <DefineConstants></DefineConstants>
28
+ <UnknownValue>Unknown</UnknownValue>
29
+ </PropertyGroup>
30
+ <!-- Platform -->
31
+ <PropertyGroup Condition="'$(Platform)'!=''">
32
+ <DefineConstants>$(DefineConstants);Platform$(Platform)</DefineConstants>
33
+ </PropertyGroup>
34
+ <PropertyGroup Condition="'$(Platform)'==''">
35
+ <DefineConstants>$(DefineConstants);Platform$(UnknownValue)</DefineConstants>
36
+ </PropertyGroup>
37
+ <!-- PlatformToolset -->
38
+ <PropertyGroup Condition="'$(PlatformToolset)'!=''">
39
+ <DefineConstants>$(DefineConstants);PlatformToolset$(PlatformToolset)</DefineConstants>
40
+ </PropertyGroup>
41
+ <PropertyGroup Condition="'$(PlatformToolset)'==''">
42
+ <DefineConstants>$(DefineConstants);PlatformToolset$(UnknownValue)</DefineConstants>
43
+ </PropertyGroup>
44
+ <!-- ============================================================ -->
45
+ <PropertyGroup>
46
+ <OutputPath Condition="'$(Configuration)|$(Platform)'=='Debug|@id_platform@'">.\</OutputPath>
47
+ </PropertyGroup>
48
+ <ItemGroup>
49
+ <Compile Include="@id_src@" />
50
+ </ItemGroup>
51
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
52
+ <PropertyGroup>
53
+ <PostBuildEvent>if not "$(RoslynTargetsPath)"=="" if exist "$(RoslynTargetsPath)\@id_cl@" set _CSC=$(RoslynTargetsPath)
54
+ if exist "$(MSBuildToolsPath)\@id_cl@" set _CSC=$(MSBuildToolsPath)
55
+ if "%_CSC%"=="" exit -1
56
+ %40echo CMAKE_@id_lang@_COMPILER=%_CSC%\@id_cl@</PostBuildEvent>
57
+ </PropertyGroup>
58
+ </Project>
wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/CompilerId/VS-Intel.vfproj.in ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <VisualStudioProject
3
+ ProjectCreator="Intel Fortran"
4
+ Keyword="Console Application"
5
+ Version="@CMAKE_VS_INTEL_Fortran_PROJECT_VERSION@"
6
+ ProjectIdGuid="{AB67BAB7-D7AE-4E97-B492-FE5420447509}"
7
+ >
8
+ <Platforms>
9
+ <Platform Name="@id_platform@"/>
10
+ </Platforms>
11
+ <Configurations>
12
+ <Configuration
13
+ Name="Debug|@id_platform@"
14
+ OutputDirectory="."
15
+ IntermediateDirectory="$(ConfigurationName)"
16
+ @id_UseCompiler@>
17
+ <Tool
18
+ Name="VFFortranCompilerTool"
19
+ DebugInformationFormat="debugEnabled"
20
+ Optimization="optimizeDisabled"
21
+ Preprocess="preprocessYes"
22
+ RuntimeLibrary="rtMultiThreadedDebugDLL"
23
+ />
24
+ <Tool
25
+ Name="VFLinkerTool"
26
+ LinkIncremental="linkIncrementalNo"
27
+ GenerateDebugInformation="true"
28
+ SubSystem="subSystemConsole"
29
+ />
30
+ <Tool
31
+ Name="VFPostBuildEventTool"
32
+ CommandLine="for %%i in (@id_cl@) do @echo CMAKE_@id_lang@_COMPILER=%%~$PATH:i"
33
+ />
34
+ </Configuration>
35
+ </Configurations>
36
+ <Files>
37
+ <Filter Name="Source Files" Filter="F">
38
+ <File RelativePath="@id_src@"/>
39
+ </Filter>
40
+ </Files>
41
+ <Globals/>
42
+ </VisualStudioProject>
wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/CompilerId/main.swift.in ADDED
@@ -0,0 +1 @@
 
 
1
+ print("CMakeSwiftCompilerId")
wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/ExternalProject/PatchInfo.txt.in ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ # This is a generated file and its contents are an internal implementation detail.
2
+ # The update step will be re-executed if anything in this file changes.
3
+ # No other meaning or use of this file is supported.
4
+
5
+ command=@cmd@
6
+ work_dir=@work_dir@
wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/ExternalProject/RepositoryInfo.txt.in ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ # This is a generated file and its contents are an internal implementation detail.
2
+ # The download step will be re-executed if anything in this file changes.
3
+ # No other meaning or use of this file is supported.
4
+
5
+ method=@method@
6
+ command=@cmd@
7
+ source_dir=@source_dir@
8
+ work_dir=@work_dir@
9
+ @extra_repo_info@
wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/ExternalProject/UpdateInfo.txt.in ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ # This is a generated file and its contents are an internal implementation detail.
2
+ # The patch step will be re-executed if anything in this file changes.
3
+ # No other meaning or use of this file is supported.
4
+
5
+ command (connected)=@cmd@
6
+ command (disconnected)=@cmd_disconnected@
7
+ work_dir=@work_dir@
wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/ExternalProject/cfgcmd.txt.in ADDED
@@ -0,0 +1 @@
 
 
1
+ cmd='@cmd@'
wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/ExternalProject/extractfile.cmake.in ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2
+ # file Copyright.txt or https://cmake.org/licensing for details.
3
+
4
+ cmake_minimum_required(VERSION ${CMAKE_VERSION}) # this file comes with cmake
5
+
6
+ # Make file names absolute:
7
+ #
8
+ get_filename_component(filename "@filename@" ABSOLUTE)
9
+ get_filename_component(directory "@directory@" ABSOLUTE)
10
+
11
+ message(VERBOSE "extracting...
12
+ src='${filename}'
13
+ dst='${directory}'"
14
+ )
15
+
16
+ if(NOT EXISTS "${filename}")
17
+ message(FATAL_ERROR "File to extract does not exist: '${filename}'")
18
+ endif()
19
+
20
+ # Prepare a space for extracting:
21
+ #
22
+ set(i 1234)
23
+ while(EXISTS "${directory}/../ex-@name@${i}")
24
+ math(EXPR i "${i} + 1")
25
+ endwhile()
26
+ set(ut_dir "${directory}/../ex-@name@${i}")
27
+ file(MAKE_DIRECTORY "${ut_dir}")
28
+
29
+ # Extract it:
30
+ #
31
+ message(VERBOSE "extracting... [tar @args@]")
32
+ execute_process(COMMAND ${CMAKE_COMMAND} -E tar @args@ ${filename} @options@
33
+ WORKING_DIRECTORY ${ut_dir}
34
+ RESULT_VARIABLE rv
35
+ )
36
+
37
+ if(NOT rv EQUAL 0)
38
+ message(VERBOSE "extracting... [error clean up]")
39
+ file(REMOVE_RECURSE "${ut_dir}")
40
+ message(FATAL_ERROR "Extract of '${filename}' failed")
41
+ endif()
42
+
43
+ # Analyze what came out of the tar file:
44
+ #
45
+ message(VERBOSE "extracting... [analysis]")
46
+ file(GLOB contents "${ut_dir}/*")
47
+ list(REMOVE_ITEM contents "${ut_dir}/.DS_Store")
48
+ list(LENGTH contents n)
49
+ if(NOT n EQUAL 1 OR NOT IS_DIRECTORY "${contents}")
50
+ set(contents "${ut_dir}")
51
+ endif()
52
+
53
+ # Move "the one" directory to the final directory:
54
+ #
55
+ message(VERBOSE "extracting... [rename]")
56
+ file(REMOVE_RECURSE ${directory})
57
+ get_filename_component(contents ${contents} ABSOLUTE)
58
+ file(RENAME ${contents} ${directory})
59
+
60
+ # Clean up:
61
+ #
62
+ message(VERBOSE "extracting... [clean up]")
63
+ file(REMOVE_RECURSE "${ut_dir}")
64
+
65
+ message(VERBOSE "extracting... done")
wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/ExternalProject/gitupdate.cmake.in ADDED
@@ -0,0 +1,317 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2
+ # file Copyright.txt or https://cmake.org/licensing for details.
3
+
4
+ cmake_minimum_required(VERSION ${CMAKE_VERSION}) # this file comes with cmake
5
+
6
+ # Even at VERBOSE level, we don't want to see the commands executed, but
7
+ # enabling them to be shown for DEBUG may be useful to help diagnose problems.
8
+ cmake_language(GET_MESSAGE_LOG_LEVEL active_log_level)
9
+ if(active_log_level MATCHES "DEBUG|TRACE")
10
+ set(maybe_show_command COMMAND_ECHO STDOUT)
11
+ else()
12
+ set(maybe_show_command "")
13
+ endif()
14
+
15
+ function(do_fetch)
16
+ message(VERBOSE "Fetching latest from the remote @git_remote_name@")
17
+ execute_process(
18
+ COMMAND "@git_EXECUTABLE@" --git-dir=.git fetch --tags --force "@git_remote_name@"
19
+ WORKING_DIRECTORY "@work_dir@"
20
+ COMMAND_ERROR_IS_FATAL LAST
21
+ ${maybe_show_command}
22
+ )
23
+ endfunction()
24
+
25
+ function(get_hash_for_ref ref out_var err_var)
26
+ execute_process(
27
+ COMMAND "@git_EXECUTABLE@" --git-dir=.git rev-parse "${ref}^0"
28
+ WORKING_DIRECTORY "@work_dir@"
29
+ RESULT_VARIABLE error_code
30
+ OUTPUT_VARIABLE ref_hash
31
+ ERROR_VARIABLE error_msg
32
+ OUTPUT_STRIP_TRAILING_WHITESPACE
33
+ )
34
+ if(error_code)
35
+ set(${out_var} "" PARENT_SCOPE)
36
+ else()
37
+ set(${out_var} "${ref_hash}" PARENT_SCOPE)
38
+ endif()
39
+ set(${err_var} "${error_msg}" PARENT_SCOPE)
40
+ endfunction()
41
+
42
+ get_hash_for_ref(HEAD head_sha error_msg)
43
+ if(head_sha STREQUAL "")
44
+ message(FATAL_ERROR "Failed to get the hash for HEAD:\n${error_msg}")
45
+ endif()
46
+
47
+ if("${can_fetch}" STREQUAL "")
48
+ set(can_fetch "@can_fetch_default@")
49
+ endif()
50
+
51
+ execute_process(
52
+ COMMAND "@git_EXECUTABLE@" --git-dir=.git show-ref "@git_tag@"
53
+ WORKING_DIRECTORY "@work_dir@"
54
+ OUTPUT_VARIABLE show_ref_output
55
+ )
56
+ if(show_ref_output MATCHES "^[a-z0-9]+[ \\t]+refs/remotes/")
57
+ # Given a full remote/branch-name and we know about it already. Since
58
+ # branches can move around, we should always fetch, if permitted.
59
+ if(can_fetch)
60
+ do_fetch()
61
+ endif()
62
+ set(checkout_name "@git_tag@")
63
+
64
+ elseif(show_ref_output MATCHES "^[a-z0-9]+[ \\t]+refs/tags/")
65
+ # Given a tag name that we already know about. We don't know if the tag we
66
+ # have matches the remote though (tags can move), so we should fetch. As a
67
+ # special case to preserve backward compatibility, if we are already at the
68
+ # same commit as the tag we hold locally, don't do a fetch and assume the tag
69
+ # hasn't moved on the remote.
70
+ # FIXME: We should provide an option to always fetch for this case
71
+ get_hash_for_ref("@git_tag@" tag_sha error_msg)
72
+ if(tag_sha STREQUAL head_sha)
73
+ message(VERBOSE "Already at requested tag: @git_tag@")
74
+ return()
75
+ endif()
76
+
77
+ if(can_fetch)
78
+ do_fetch()
79
+ endif()
80
+ set(checkout_name "@git_tag@")
81
+
82
+ elseif(show_ref_output MATCHES "^[a-z0-9]+[ \\t]+refs/heads/")
83
+ # Given a branch name without any remote and we already have a branch by that
84
+ # name. We might already have that branch checked out or it might be a
85
+ # different branch. It isn't fully safe to use a bare branch name without the
86
+ # remote, so do a fetch (if allowed) and replace the ref with one that
87
+ # includes the remote.
88
+ if(can_fetch)
89
+ do_fetch()
90
+ endif()
91
+ set(checkout_name "@git_remote_name@/@git_tag@")
92
+
93
+ else()
94
+ get_hash_for_ref("@git_tag@" tag_sha error_msg)
95
+ if(tag_sha STREQUAL head_sha)
96
+ # Have the right commit checked out already
97
+ message(VERBOSE "Already at requested ref: ${tag_sha}")
98
+ return()
99
+
100
+ elseif(tag_sha STREQUAL "")
101
+ # We don't know about this ref yet, so we have no choice but to fetch.
102
+ if(NOT can_fetch)
103
+ message(FATAL_ERROR
104
+ "Requested git ref \"@git_tag@\" is not present locally, and not "
105
+ "allowed to contact remote due to UPDATE_DISCONNECTED setting."
106
+ )
107
+ endif()
108
+
109
+ # We deliberately swallow any error message at the default log level
110
+ # because it can be confusing for users to see a failed git command.
111
+ # That failure is being handled here, so it isn't an error.
112
+ if(NOT error_msg STREQUAL "")
113
+ message(DEBUG "${error_msg}")
114
+ endif()
115
+ do_fetch()
116
+ set(checkout_name "@git_tag@")
117
+
118
+ else()
119
+ # We have the commit, so we know we were asked to find a commit hash
120
+ # (otherwise it would have been handled further above), but we don't
121
+ # have that commit checked out yet. We don't need to fetch from the remote.
122
+ set(checkout_name "@git_tag@")
123
+ if(NOT error_msg STREQUAL "")
124
+ message(WARNING "${error_msg}")
125
+ endif()
126
+
127
+ endif()
128
+ endif()
129
+
130
+ set(git_update_strategy "@git_update_strategy@")
131
+ if(git_update_strategy STREQUAL "")
132
+ # Backward compatibility requires REBASE as the default behavior
133
+ set(git_update_strategy REBASE)
134
+ endif()
135
+
136
+ if(git_update_strategy MATCHES "^REBASE(_CHECKOUT)?$")
137
+ # Asked to potentially try to rebase first, maybe with fallback to checkout.
138
+ # We can't if we aren't already on a branch and we shouldn't if that local
139
+ # branch isn't tracking the one we want to checkout.
140
+ execute_process(
141
+ COMMAND "@git_EXECUTABLE@" --git-dir=.git symbolic-ref -q HEAD
142
+ WORKING_DIRECTORY "@work_dir@"
143
+ OUTPUT_VARIABLE current_branch
144
+ OUTPUT_STRIP_TRAILING_WHITESPACE
145
+ # Don't test for an error. If this isn't a branch, we get a non-zero error
146
+ # code but empty output.
147
+ )
148
+
149
+ if(current_branch STREQUAL "")
150
+ # Not on a branch, checkout is the only sensible option since any rebase
151
+ # would always fail (and backward compatibility requires us to checkout in
152
+ # this situation)
153
+ set(git_update_strategy CHECKOUT)
154
+
155
+ else()
156
+ execute_process(
157
+ COMMAND "@git_EXECUTABLE@" --git-dir=.git for-each-ref "--format=%(upstream:short)" "${current_branch}"
158
+ WORKING_DIRECTORY "@work_dir@"
159
+ OUTPUT_VARIABLE upstream_branch
160
+ OUTPUT_STRIP_TRAILING_WHITESPACE
161
+ COMMAND_ERROR_IS_FATAL ANY # There is no error if no upstream is set
162
+ )
163
+ if(NOT upstream_branch STREQUAL checkout_name)
164
+ # Not safe to rebase when asked to checkout a different branch to the one
165
+ # we are tracking. If we did rebase, we could end up with arbitrary
166
+ # commits added to the ref we were asked to checkout if the current local
167
+ # branch happens to be able to rebase onto the target branch. There would
168
+ # be no error message and the user wouldn't know this was occurring.
169
+ set(git_update_strategy CHECKOUT)
170
+ endif()
171
+
172
+ endif()
173
+ elseif(NOT git_update_strategy STREQUAL "CHECKOUT")
174
+ message(FATAL_ERROR "Unsupported git update strategy: ${git_update_strategy}")
175
+ endif()
176
+
177
+
178
+ # Check if stash is needed
179
+ execute_process(
180
+ COMMAND "@git_EXECUTABLE@" --git-dir=.git status --porcelain
181
+ WORKING_DIRECTORY "@work_dir@"
182
+ RESULT_VARIABLE error_code
183
+ OUTPUT_VARIABLE repo_status
184
+ )
185
+ if(error_code)
186
+ message(FATAL_ERROR "Failed to get the status")
187
+ endif()
188
+ string(LENGTH "${repo_status}" need_stash)
189
+
190
+ # If not in clean state, stash changes in order to be able to perform a
191
+ # rebase or checkout without losing those changes permanently
192
+ if(need_stash)
193
+ execute_process(
194
+ COMMAND "@git_EXECUTABLE@" --git-dir=.git stash save @git_stash_save_options@
195
+ WORKING_DIRECTORY "@work_dir@"
196
+ COMMAND_ERROR_IS_FATAL ANY
197
+ ${maybe_show_command}
198
+ )
199
+ endif()
200
+
201
+ if(git_update_strategy STREQUAL "CHECKOUT")
202
+ execute_process(
203
+ COMMAND "@git_EXECUTABLE@" --git-dir=.git checkout "${checkout_name}"
204
+ WORKING_DIRECTORY "@work_dir@"
205
+ COMMAND_ERROR_IS_FATAL ANY
206
+ ${maybe_show_command}
207
+ )
208
+ else()
209
+ execute_process(
210
+ COMMAND "@git_EXECUTABLE@" --git-dir=.git rebase "${checkout_name}"
211
+ WORKING_DIRECTORY "@work_dir@"
212
+ RESULT_VARIABLE error_code
213
+ OUTPUT_VARIABLE rebase_output
214
+ ERROR_VARIABLE rebase_output
215
+ )
216
+ if(error_code)
217
+ # Rebase failed, undo the rebase attempt before continuing
218
+ execute_process(
219
+ COMMAND "@git_EXECUTABLE@" --git-dir=.git rebase --abort
220
+ WORKING_DIRECTORY "@work_dir@"
221
+ ${maybe_show_command}
222
+ )
223
+
224
+ if(NOT git_update_strategy STREQUAL "REBASE_CHECKOUT")
225
+ # Not allowed to do a checkout as a fallback, so cannot proceed
226
+ if(need_stash)
227
+ execute_process(
228
+ COMMAND "@git_EXECUTABLE@" --git-dir=.git stash pop --index --quiet
229
+ WORKING_DIRECTORY "@work_dir@"
230
+ ${maybe_show_command}
231
+ )
232
+ endif()
233
+ message(FATAL_ERROR "\nFailed to rebase in: '@work_dir@'."
234
+ "\nOutput from the attempted rebase follows:"
235
+ "\n${rebase_output}"
236
+ "\n\nYou will have to resolve the conflicts manually")
237
+ endif()
238
+
239
+ # Fall back to checkout. We create an annotated tag so that the user
240
+ # can manually inspect the situation and revert if required.
241
+ # We can't log the failed rebase output because MSVC sees it and
242
+ # intervenes, causing the build to fail even though it completes.
243
+ # Write it to a file instead.
244
+ string(TIMESTAMP tag_timestamp "%Y%m%dT%H%M%S" UTC)
245
+ set(tag_name _cmake_ExternalProject_moved_from_here_${tag_timestamp}Z)
246
+ set(error_log_file ${CMAKE_CURRENT_LIST_DIR}/rebase_error_${tag_timestamp}Z.log)
247
+ file(WRITE ${error_log_file} "${rebase_output}")
248
+ message(WARNING "Rebase failed, output has been saved to ${error_log_file}"
249
+ "\nFalling back to checkout, previous commit tagged as ${tag_name}")
250
+ execute_process(
251
+ COMMAND "@git_EXECUTABLE@" --git-dir=.git tag -a
252
+ -m "ExternalProject attempting to move from here to ${checkout_name}"
253
+ ${tag_name}
254
+ WORKING_DIRECTORY "@work_dir@"
255
+ COMMAND_ERROR_IS_FATAL ANY
256
+ ${maybe_show_command}
257
+ )
258
+
259
+ execute_process(
260
+ COMMAND "@git_EXECUTABLE@" --git-dir=.git checkout "${checkout_name}"
261
+ WORKING_DIRECTORY "@work_dir@"
262
+ COMMAND_ERROR_IS_FATAL ANY
263
+ ${maybe_show_command}
264
+ )
265
+ endif()
266
+ endif()
267
+
268
+ if(need_stash)
269
+ # Put back the stashed changes
270
+ execute_process(
271
+ COMMAND "@git_EXECUTABLE@" --git-dir=.git stash pop --index --quiet
272
+ WORKING_DIRECTORY "@work_dir@"
273
+ RESULT_VARIABLE error_code
274
+ ${maybe_show_command}
275
+ )
276
+ if(error_code)
277
+ # Stash pop --index failed: Try again dropping the index
278
+ execute_process(
279
+ COMMAND "@git_EXECUTABLE@" --git-dir=.git reset --hard --quiet
280
+ WORKING_DIRECTORY "@work_dir@"
281
+ ${maybe_show_command}
282
+ )
283
+ execute_process(
284
+ COMMAND "@git_EXECUTABLE@" --git-dir=.git stash pop --quiet
285
+ WORKING_DIRECTORY "@work_dir@"
286
+ RESULT_VARIABLE error_code
287
+ ${maybe_show_command}
288
+ )
289
+ if(error_code)
290
+ # Stash pop failed: Restore previous state.
291
+ execute_process(
292
+ COMMAND "@git_EXECUTABLE@" --git-dir=.git reset --hard --quiet ${head_sha}
293
+ WORKING_DIRECTORY "@work_dir@"
294
+ ${maybe_show_command}
295
+ )
296
+ execute_process(
297
+ COMMAND "@git_EXECUTABLE@" --git-dir=.git stash pop --index --quiet
298
+ WORKING_DIRECTORY "@work_dir@"
299
+ ${maybe_show_command}
300
+ )
301
+ message(FATAL_ERROR "\nFailed to unstash changes in: '@work_dir@'."
302
+ "\nYou will have to resolve the conflicts manually")
303
+ endif()
304
+ endif()
305
+ endif()
306
+
307
+ set(init_submodules "@init_submodules@")
308
+ if(init_submodules)
309
+ execute_process(
310
+ COMMAND "@git_EXECUTABLE@"
311
+ --git-dir=.git @git_submodules_config_options@
312
+ submodule update @git_submodules_recurse@ --init @git_submodules@
313
+ WORKING_DIRECTORY "@work_dir@"
314
+ COMMAND_ERROR_IS_FATAL ANY
315
+ ${maybe_show_command}
316
+ )
317
+ endif()
wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/ExternalProject/hgclone.cmake.in ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2
+ # file Copyright.txt or https://cmake.org/licensing for details.
3
+
4
+ cmake_minimum_required(VERSION ${CMAKE_VERSION}) # this file comes with cmake
5
+
6
+ if(EXISTS "@hgclone_stampfile@" AND EXISTS "@hgclone_infofile@" AND
7
+ "@hgclone_stampfile@" IS_NEWER_THAN "@hgclone_infofile@")
8
+ message(VERBOSE
9
+ "Avoiding repeated hg clone, stamp file is up to date: "
10
+ "'@hgclone_stampfile@'"
11
+ )
12
+ return()
13
+ endif()
14
+
15
+ # Even at VERBOSE level, we don't want to see the commands executed, but
16
+ # enabling them to be shown for DEBUG may be useful to help diagnose problems.
17
+ cmake_language(GET_MESSAGE_LOG_LEVEL active_log_level)
18
+ if(active_log_level MATCHES "DEBUG|TRACE")
19
+ set(maybe_show_command COMMAND_ECHO STDOUT)
20
+ else()
21
+ set(maybe_show_command "")
22
+ endif()
23
+
24
+ execute_process(
25
+ COMMAND ${CMAKE_COMMAND} -E rm -rf "@source_dir@"
26
+ RESULT_VARIABLE error_code
27
+ ${maybe_show_command}
28
+ )
29
+ if(error_code)
30
+ message(FATAL_ERROR "Failed to remove directory: '@source_dir@'")
31
+ endif()
32
+
33
+ execute_process(
34
+ COMMAND "@hg_EXECUTABLE@" clone -U "@hg_repository@" "@src_name@"
35
+ WORKING_DIRECTORY "@work_dir@"
36
+ RESULT_VARIABLE error_code
37
+ ${maybe_show_command}
38
+ )
39
+ if(error_code)
40
+ message(FATAL_ERROR "Failed to clone repository: '@hg_repository@'")
41
+ endif()
42
+
43
+ execute_process(
44
+ COMMAND "@hg_EXECUTABLE@" update @hg_tag@
45
+ WORKING_DIRECTORY "@work_dir@/@src_name@"
46
+ RESULT_VARIABLE error_code
47
+ ${maybe_show_command}
48
+ )
49
+ if(error_code)
50
+ message(FATAL_ERROR "Failed to checkout tag: '@hg_tag@'")
51
+ endif()
52
+
53
+ # Complete success, update the script-last-run stamp file:
54
+ #
55
+ execute_process(
56
+ COMMAND ${CMAKE_COMMAND} -E copy "@hgclone_infofile@" "@hgclone_stampfile@"
57
+ RESULT_VARIABLE error_code
58
+ ${maybe_show_command}
59
+ )
60
+ if(error_code)
61
+ message(FATAL_ERROR "Failed to copy script-last-run stamp file: '@hgclone_stampfile@'")
62
+ endif()
wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/ExternalProject/shared_internal_commands.cmake ADDED
@@ -0,0 +1,1982 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ cmake_policy(VERSION 3.25)
2
+
3
+ # Determine the remote URL of the project containing the working_directory.
4
+ # This will leave output_variable unset if the URL can't be determined.
5
+ function(_ep_get_git_remote_url output_variable working_directory)
6
+ set("${output_variable}" "" PARENT_SCOPE)
7
+
8
+ find_package(Git QUIET REQUIRED)
9
+
10
+ execute_process(
11
+ COMMAND ${GIT_EXECUTABLE} symbolic-ref --short HEAD
12
+ WORKING_DIRECTORY "${working_directory}"
13
+ OUTPUT_VARIABLE git_symbolic_ref
14
+ OUTPUT_STRIP_TRAILING_WHITESPACE
15
+ ERROR_QUIET
16
+ )
17
+
18
+ if(NOT git_symbolic_ref STREQUAL "")
19
+ # We are potentially on a branch. See if that branch is associated with
20
+ # an upstream remote (might be just a local one or not a branch at all).
21
+ execute_process(
22
+ COMMAND ${GIT_EXECUTABLE} config branch.${git_symbolic_ref}.remote
23
+ WORKING_DIRECTORY "${working_directory}"
24
+ OUTPUT_VARIABLE git_remote_name
25
+ OUTPUT_STRIP_TRAILING_WHITESPACE
26
+ ERROR_QUIET
27
+ )
28
+ endif()
29
+
30
+ if(NOT git_remote_name)
31
+ # Can't select a remote based on a branch. If there's only one remote,
32
+ # or we have multiple remotes but one is called "origin", choose that.
33
+ execute_process(
34
+ COMMAND ${GIT_EXECUTABLE} remote
35
+ WORKING_DIRECTORY "${working_directory}"
36
+ OUTPUT_VARIABLE git_remote_list
37
+ OUTPUT_STRIP_TRAILING_WHITESPACE
38
+ ERROR_QUIET
39
+ )
40
+ string(REPLACE "\n" ";" git_remote_list "${git_remote_list}")
41
+ list(LENGTH git_remote_list git_remote_list_length)
42
+
43
+ if(git_remote_list_length EQUAL 0)
44
+ message(FATAL_ERROR "Git remote not found in parent project.")
45
+ elseif(git_remote_list_length EQUAL 1)
46
+ list(GET git_remote_list 0 git_remote_name)
47
+ else()
48
+ set(base_warning_msg "Multiple git remotes found for parent project")
49
+ if("origin" IN_LIST git_remote_list)
50
+ message(WARNING "${base_warning_msg}, defaulting to origin.")
51
+ set(git_remote_name "origin")
52
+ else()
53
+ message(FATAL_ERROR "${base_warning_msg}, none of which are origin.")
54
+ endif()
55
+ endif()
56
+ endif()
57
+
58
+ if(GIT_VERSION VERSION_LESS 1.7.5)
59
+ set(_git_remote_url_cmd_args config remote.${git_remote_name}.url)
60
+ elseif(GIT_VERSION VERSION_LESS 2.7)
61
+ set(_git_remote_url_cmd_args ls-remote --get-url ${git_remote_name})
62
+ else()
63
+ set(_git_remote_url_cmd_args remote get-url ${git_remote_name})
64
+ endif()
65
+
66
+ execute_process(
67
+ COMMAND ${GIT_EXECUTABLE} ${_git_remote_url_cmd_args}
68
+ WORKING_DIRECTORY "${working_directory}"
69
+ OUTPUT_VARIABLE git_remote_url
70
+ OUTPUT_STRIP_TRAILING_WHITESPACE
71
+ COMMAND_ERROR_IS_FATAL LAST
72
+ ENCODING UTF-8 # Needed to handle non-ascii characters in local paths
73
+ )
74
+
75
+ set("${output_variable}" "${git_remote_url}" PARENT_SCOPE)
76
+ endfunction()
77
+
78
+
79
+ function(_ep_is_relative_git_remote output_variable remote_url)
80
+ if(remote_url MATCHES "^\\.\\./")
81
+ set("${output_variable}" TRUE PARENT_SCOPE)
82
+ else()
83
+ set("${output_variable}" FALSE PARENT_SCOPE)
84
+ endif()
85
+ endfunction()
86
+
87
+
88
+ # Return an absolute remote URL given an existing remote URL and relative path.
89
+ # The output_variable will be set to an empty string if an absolute URL
90
+ # could not be computed (no error message is output).
91
+ function(_ep_resolve_relative_git_remote
92
+ output_variable
93
+ parent_remote_url
94
+ relative_remote_url
95
+ )
96
+ set("${output_variable}" "" PARENT_SCOPE)
97
+
98
+ if(parent_remote_url STREQUAL "")
99
+ return()
100
+ endif()
101
+
102
+ string(REGEX MATCH
103
+ "^(([A-Za-z0-9][A-Za-z0-9+.-]*)://)?(([^/@]+)@)?(\\[[A-Za-z0-9:]+\\]|[^/:]+)?([/:]/?)(.+(\\.git)?/?)$"
104
+ git_remote_url_components
105
+ "${parent_remote_url}"
106
+ )
107
+
108
+ set(protocol "${CMAKE_MATCH_1}")
109
+ set(auth "${CMAKE_MATCH_3}")
110
+ set(host "${CMAKE_MATCH_5}")
111
+ set(separator "${CMAKE_MATCH_6}")
112
+ set(path "${CMAKE_MATCH_7}")
113
+
114
+ string(REPLACE "/" ";" remote_path_components "${path}")
115
+ string(REPLACE "/" ";" relative_path_components "${relative_remote_url}")
116
+
117
+ foreach(relative_path_component IN LISTS relative_path_components)
118
+ if(NOT relative_path_component STREQUAL "..")
119
+ break()
120
+ endif()
121
+
122
+ list(LENGTH remote_path_components remote_path_component_count)
123
+
124
+ if(remote_path_component_count LESS 1)
125
+ return()
126
+ endif()
127
+
128
+ list(POP_BACK remote_path_components)
129
+ list(POP_FRONT relative_path_components)
130
+ endforeach()
131
+
132
+ list(APPEND final_path_components ${remote_path_components} ${relative_path_components})
133
+ list(JOIN final_path_components "/" path)
134
+
135
+ set("${output_variable}" "${protocol}${auth}${host}${separator}${path}" PARENT_SCOPE)
136
+ endfunction()
137
+
138
+
139
+ # The output_variable will be set to the original git_repository if it
140
+ # could not be resolved (no error message is output). The original value is
141
+ # also returned if it doesn't need to be resolved.
142
+ function(_ep_resolve_git_remote
143
+ output_variable
144
+ git_repository
145
+ cmp0150
146
+ cmp0150_old_base_dir
147
+ )
148
+ if(git_repository STREQUAL "")
149
+ set("${output_variable}" "" PARENT_SCOPE)
150
+ return()
151
+ endif()
152
+
153
+ _ep_is_relative_git_remote(_git_repository_is_relative "${git_repository}")
154
+
155
+ if(NOT _git_repository_is_relative)
156
+ set("${output_variable}" "${git_repository}" PARENT_SCOPE)
157
+ return()
158
+ endif()
159
+
160
+ if(cmp0150 STREQUAL "NEW")
161
+ _ep_get_git_remote_url(_parent_git_remote_url "${CMAKE_CURRENT_SOURCE_DIR}")
162
+ _ep_resolve_relative_git_remote(_resolved_git_remote_url "${_parent_git_remote_url}" "${git_repository}")
163
+
164
+ if(_resolved_git_remote_url STREQUAL "")
165
+ message(FATAL_ERROR
166
+ "Failed to resolve relative git remote URL:\n"
167
+ " Relative URL: ${git_repository}\n"
168
+ " Parent URL: ${_parent_git_remote_url}"
169
+ )
170
+ endif()
171
+ set("${output_variable}" "${_resolved_git_remote_url}" PARENT_SCOPE)
172
+ return()
173
+ elseif(cmp0150 STREQUAL "")
174
+ cmake_policy(GET_WARNING CMP0150 _cmp0150_warning)
175
+ message(AUTHOR_WARNING
176
+ "${_cmp0150_warning}\n"
177
+ "A relative GIT_REPOSITORY path was detected. "
178
+ "This will be interpreted as a local path to where the project is being cloned. "
179
+ "Set GIT_REPOSITORY to an absolute path or set policy CMP0150 to NEW to avoid "
180
+ "this warning."
181
+ )
182
+ endif()
183
+
184
+ set("${output_variable}" "${cmp0150_old_base_dir}/${git_repository}" PARENT_SCOPE)
185
+ endfunction()
186
+
187
+
188
+ macro(_ep_get_hash_algos out_var)
189
+ set(${out_var}
190
+ MD5
191
+ SHA1
192
+ SHA224
193
+ SHA256
194
+ SHA384
195
+ SHA512
196
+ SHA3_224
197
+ SHA3_256
198
+ SHA3_384
199
+ SHA3_512
200
+ )
201
+ endmacro()
202
+
203
+
204
+ macro(_ep_get_hash_regex out_var)
205
+ _ep_get_hash_algos(${out_var})
206
+ list(JOIN ${out_var} "|" ${out_var})
207
+ set(${out_var} "^(${${out_var}})=([0-9A-Fa-f]+)$")
208
+ endmacro()
209
+
210
+
211
+ function(_ep_parse_arguments_to_vars
212
+ f
213
+ keywords
214
+ name
215
+ ns
216
+ args
217
+ )
218
+ # Transfer the arguments into variables in the calling scope.
219
+ # Because some keywords can be repeated, we can't use cmake_parse_arguments().
220
+ # Instead, we loop through the args and consider the namespace starting with
221
+ # an upper-case letter followed by at least two more upper-case letters,
222
+ # numbers or underscores to be keywords.
223
+
224
+ foreach(key IN LISTS keywords)
225
+ unset(${ns}${key})
226
+ endforeach()
227
+
228
+ set(key)
229
+
230
+ foreach(arg IN LISTS args)
231
+ set(is_value 1)
232
+
233
+ if(arg MATCHES "^[A-Z][A-Z0-9_][A-Z0-9_]+$" AND
234
+ NOT (("x${arg}x" STREQUAL "x${key}x") AND
235
+ ("x${key}x" STREQUAL "xCOMMANDx")) AND
236
+ NOT arg MATCHES "^(TRUE|FALSE|YES)$")
237
+ if(arg IN_LIST keywords)
238
+ set(is_value 0)
239
+ endif()
240
+ endif()
241
+
242
+ if(is_value)
243
+ if(key)
244
+ # Value
245
+ list(APPEND ${ns}${key} "${arg}")
246
+ else()
247
+ # Missing Keyword
248
+ message(AUTHOR_WARNING
249
+ "value '${arg}' with no previous keyword in ${f}"
250
+ )
251
+ endif()
252
+ else()
253
+ set(key "${arg}")
254
+ endif()
255
+ endforeach()
256
+
257
+ foreach(key IN LISTS keywords)
258
+ if(DEFINED ${ns}${key})
259
+ set(${ns}${key} "${${ns}${key}}" PARENT_SCOPE)
260
+ else()
261
+ unset(${ns}${key} PARENT_SCOPE)
262
+ endif()
263
+ endforeach()
264
+
265
+ endfunction()
266
+
267
+
268
+ # NOTE: This cannot be a macro because that will evaluate anything that looks
269
+ # like a CMake variable in any of the args.
270
+ function(_ep_parse_arguments
271
+ f
272
+ keywords
273
+ name
274
+ ns
275
+ args
276
+ )
277
+ _ep_parse_arguments_to_vars(
278
+ "${f}"
279
+ "${keywords}"
280
+ ${name}
281
+ ${ns}
282
+ "${args}"
283
+ )
284
+
285
+ foreach(key IN LISTS keywords)
286
+ if(DEFINED ${ns}${key})
287
+ set(${ns}${key} "${${ns}${key}}" PARENT_SCOPE)
288
+ else()
289
+ unset(${ns}${key} PARENT_SCOPE)
290
+ endif()
291
+ endforeach()
292
+
293
+ # Transfer the arguments to the target as target properties. These are
294
+ # read by the various steps, potentially from different scopes.
295
+ foreach(key IN LISTS keywords)
296
+ if(DEFINED ${ns}${key})
297
+ set_property(TARGET ${name} PROPERTY ${ns}${key} "${${ns}${key}}")
298
+ endif()
299
+ endforeach()
300
+
301
+ endfunction()
302
+
303
+
304
+ function(_ep_get_tls_version name tls_version_var)
305
+ # Note that the arguments are assumed to have already been parsed and have
306
+ # been translated into variables with the prefix _EP_... by a call to
307
+ # ep_parse_arguments() or ep_parse_arguments_to_vars().
308
+ set(tls_version_regex "^1\\.[0-3]$")
309
+ set(tls_version "${_EP_TLS_VERSION}")
310
+ if(NOT "x${tls_version}" STREQUAL "x")
311
+ if(NOT tls_version MATCHES "${tls_version_regex}")
312
+ message(FATAL_ERROR "TLS_VERSION '${tls_version}' not known")
313
+ endif()
314
+ elseif(NOT "x${CMAKE_TLS_VERSION}" STREQUAL "x")
315
+ set(tls_version "${CMAKE_TLS_VERSION}")
316
+ if(NOT tls_version MATCHES "${tls_version_regex}")
317
+ message(FATAL_ERROR "CMAKE_TLS_VERSION '${tls_version}' not known")
318
+ endif()
319
+ elseif(NOT "x$ENV{CMAKE_TLS_VERSION}" STREQUAL "x")
320
+ set(tls_version "$ENV{CMAKE_TLS_VERSION}")
321
+ if(NOT tls_version MATCHES "${tls_version_regex}")
322
+ message(FATAL_ERROR "ENV{CMAKE_TLS_VERSION} '${tls_version}' not known")
323
+ endif()
324
+ endif()
325
+ set("${tls_version_var}" "${tls_version}" PARENT_SCOPE)
326
+ endfunction()
327
+
328
+
329
+ function(_ep_get_tls_verify name tls_verify_var)
330
+ # Note that the arguments are assumed to have already been parsed and have
331
+ # been translated into variables with the prefix _EP_... by a call to
332
+ # ep_parse_arguments() or ep_parse_arguments_to_vars().
333
+ set(tls_verify "${_EP_TLS_VERIFY}")
334
+ if("x${tls_verify}" STREQUAL "x")
335
+ if(NOT "x${CMAKE_TLS_VERIFY}" STREQUAL "x")
336
+ set(tls_verify "${CMAKE_TLS_VERIFY}")
337
+ elseif(NOT "x$ENV{CMAKE_TLS_VERIFY}" STREQUAL "x")
338
+ set(tls_verify "$ENV{CMAKE_TLS_VERIFY}")
339
+ endif()
340
+ endif()
341
+ set("${tls_verify_var}" "${tls_verify}" PARENT_SCOPE)
342
+ endfunction()
343
+
344
+
345
+ function(_ep_get_tls_cainfo name tls_cainfo_var)
346
+ # Note that the arguments are assumed to have already been parsed and have
347
+ # been translated into variables with the prefix _EP_... by a call to
348
+ # ep_parse_arguments() or ep_parse_arguments_to_vars().
349
+ set(tls_cainfo "${_EP_TLS_CAINFO}")
350
+ if("x${tls_cainfo}" STREQUAL "x" AND DEFINED CMAKE_TLS_CAINFO)
351
+ set(tls_cainfo "${CMAKE_TLS_CAINFO}")
352
+ endif()
353
+ set("${tls_cainfo_var}" "${tls_cainfo}" PARENT_SCOPE)
354
+ endfunction()
355
+
356
+
357
+ function(_ep_get_netrc name netrc_var)
358
+ # Note that the arguments are assumed to have already been parsed and have
359
+ # been translated into variables with the prefix _EP_... by a call to
360
+ # ep_parse_arguments() or ep_parse_arguments_to_vars().
361
+ set(netrc "${_EP_NETRC}")
362
+ if("x${netrc}" STREQUAL "x" AND DEFINED CMAKE_NETRC)
363
+ set(netrc "${CMAKE_NETRC}")
364
+ endif()
365
+ set("${netrc_var}" "${netrc}" PARENT_SCOPE)
366
+ endfunction()
367
+
368
+
369
+ function(_ep_get_netrc_file name netrc_file_var)
370
+ # Note that the arguments are assumed to have already been parsed and have
371
+ # been translated into variables with the prefix _EP_... by a call to
372
+ # ep_parse_arguments() or ep_parse_arguments_to_vars().
373
+ set(netrc_file "${_EP_NETRC_FILE}")
374
+ if("x${netrc_file}" STREQUAL "x" AND DEFINED CMAKE_NETRC_FILE)
375
+ set(netrc_file "${CMAKE_NETRC_FILE}")
376
+ endif()
377
+ set("${netrc_file_var}" "${netrc_file}" PARENT_SCOPE)
378
+ endfunction()
379
+
380
+
381
+ function(_ep_write_gitclone_script
382
+ script_filename
383
+ source_dir
384
+ git_EXECUTABLE
385
+ git_repository
386
+ git_tag
387
+ git_remote_name
388
+ init_submodules
389
+ git_submodules_recurse
390
+ git_submodules
391
+ git_shallow
392
+ git_progress
393
+ git_config
394
+ src_name
395
+ work_dir
396
+ gitclone_infofile
397
+ gitclone_stampfile
398
+ tls_version
399
+ tls_verify
400
+ )
401
+
402
+ if(NOT GIT_VERSION_STRING VERSION_LESS 1.8.5)
403
+ # Use `git checkout <tree-ish> --` to avoid ambiguity with a local path.
404
+ set(git_checkout_explicit-- "--")
405
+ else()
406
+ # Use `git checkout <branch>` even though this risks ambiguity with a
407
+ # local path. Unfortunately we cannot use `git checkout <tree-ish> --`
408
+ # because that will not search for remote branch names, a common use case.
409
+ set(git_checkout_explicit-- "")
410
+ endif()
411
+ if("${git_tag}" STREQUAL "")
412
+ message(FATAL_ERROR "Tag for git checkout should not be empty.")
413
+ endif()
414
+
415
+ if(GIT_VERSION_STRING VERSION_LESS 2.20 OR
416
+ 2.21 VERSION_LESS_EQUAL GIT_VERSION_STRING)
417
+ set(git_clone_options "--no-checkout")
418
+ else()
419
+ set(git_clone_options)
420
+ endif()
421
+ if(git_shallow)
422
+ if(NOT GIT_VERSION_STRING VERSION_LESS 1.7.10)
423
+ list(APPEND git_clone_options "--depth 1 --no-single-branch")
424
+ else()
425
+ list(APPEND git_clone_options "--depth 1")
426
+ endif()
427
+ endif()
428
+ if(git_progress)
429
+ list(APPEND git_clone_options --progress)
430
+ endif()
431
+ foreach(config IN LISTS git_config)
432
+ list(APPEND git_clone_options --config \"${config}\")
433
+ endforeach()
434
+ if(NOT ${git_remote_name} STREQUAL "origin")
435
+ list(APPEND git_clone_options --origin \"${git_remote_name}\")
436
+ endif()
437
+
438
+ # The clone config option is sticky, it will apply to all subsequent git
439
+ # update operations. The submodules config option is not sticky, because
440
+ # git doesn't provide any way to do that. Thus, we will have to pass the
441
+ # same config option in the update step too for submodules, but not for
442
+ # the main git repo.
443
+ set(git_submodules_config_options "")
444
+ if(NOT "x${tls_version}" STREQUAL "x")
445
+ list(APPEND git_clone_options -c http.sslVersion=tlsv${tls_version})
446
+ list(APPEND git_submodules_config_options -c http.sslVersion=tlsv${tls_version})
447
+ endif()
448
+ if(NOT "x${tls_verify}" STREQUAL "x")
449
+ if(tls_verify)
450
+ # Default git behavior is "true", but the user might have changed the
451
+ # global default to "false". Since TLS_VERIFY was given, ensure we honor
452
+ # the specified setting regardless of what the global default might be.
453
+ list(APPEND git_clone_options -c http.sslVerify=true)
454
+ list(APPEND git_submodules_config_options -c http.sslVerify=true)
455
+ else()
456
+ list(APPEND git_clone_options -c http.sslVerify=false)
457
+ list(APPEND git_submodules_config_options -c http.sslVerify=false)
458
+ endif()
459
+ endif()
460
+
461
+ string (REPLACE ";" " " git_clone_options "${git_clone_options}")
462
+
463
+ configure_file(
464
+ ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/gitclone.cmake.in
465
+ ${script_filename}
466
+ @ONLY
467
+ )
468
+ endfunction()
469
+
470
+
471
+ function(_ep_write_hgclone_script
472
+ script_filename
473
+ source_dir
474
+ hg_EXECUTABLE
475
+ hg_repository
476
+ hg_tag
477
+ src_name
478
+ work_dir
479
+ hgclone_infofile
480
+ hgclone_stampfile
481
+ )
482
+
483
+ if("${hg_tag}" STREQUAL "")
484
+ message(FATAL_ERROR "Tag for hg checkout should not be empty.")
485
+ endif()
486
+
487
+ configure_file(
488
+ ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/hgclone.cmake.in
489
+ ${script_filename}
490
+ @ONLY
491
+ )
492
+ endfunction()
493
+
494
+
495
+ function(_ep_write_gitupdate_script
496
+ script_filename
497
+ git_EXECUTABLE
498
+ git_tag
499
+ git_remote_name
500
+ init_submodules
501
+ git_submodules_recurse
502
+ git_submodules
503
+ git_repository
504
+ work_dir
505
+ git_update_strategy
506
+ tls_version
507
+ tls_verify
508
+ )
509
+
510
+ if("${git_tag}" STREQUAL "")
511
+ message(FATAL_ERROR "Tag for git checkout should not be empty.")
512
+ endif()
513
+ set(git_stash_save_options --quiet)
514
+ if(GIT_VERSION_STRING VERSION_GREATER_EQUAL 1.7.7)
515
+ # This avoids stashing files covered by .gitignore
516
+ list(APPEND git_stash_save_options --include-untracked)
517
+ elseif(GIT_VERSION_STRING VERSION_GREATER_EQUAL 1.7.6)
518
+ # Untracked files, but also ignored files, so potentially slower
519
+ list(APPEND git_stash_save_options --all)
520
+ endif()
521
+
522
+ # The submodules config option is not sticky, git doesn't provide any way
523
+ # to do that. We have to pass this config option for the update step too.
524
+ # We don't need to set it for the non-submodule update because it gets
525
+ # recorded as part of the clone operation in a sticky manner.
526
+ set(git_submodules_config_options "")
527
+ if(NOT "x${tls_version}" STREQUAL "x")
528
+ list(APPEND git_submodules_config_options -c http.sslVersion=tlsv${tls_version})
529
+ endif()
530
+ if(NOT "x${tls_verify}" STREQUAL "x")
531
+ if(tls_verify)
532
+ # Default git behavior is "true", but the user might have changed the
533
+ # global default to "false". Since TLS_VERIFY was given, ensure we honor
534
+ # the specified setting regardless of what the global default might be.
535
+ list(APPEND git_submodules_config_options -c http.sslVerify=true)
536
+ else()
537
+ list(APPEND git_submodules_config_options -c http.sslVerify=false)
538
+ endif()
539
+ endif()
540
+
541
+ configure_file(
542
+ "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/gitupdate.cmake.in"
543
+ "${script_filename}"
544
+ @ONLY
545
+ )
546
+ endfunction()
547
+
548
+
549
+ function(_ep_write_downloadfile_script
550
+ script_filename
551
+ REMOTE
552
+ LOCAL
553
+ timeout
554
+ inactivity_timeout
555
+ no_progress
556
+ hash
557
+ tls_version
558
+ tls_verify
559
+ tls_cainfo
560
+ userpwd
561
+ http_headers
562
+ netrc
563
+ netrc_file
564
+ )
565
+ if("x${REMOTE}" STREQUAL "x")
566
+ message(FATAL_ERROR "REMOTE can't be empty")
567
+ endif()
568
+ if("x${LOCAL}" STREQUAL "x")
569
+ message(FATAL_ERROR "LOCAL can't be empty")
570
+ endif()
571
+
572
+ # REMOTE could contain special characters that parse as separate arguments.
573
+ # Things like parentheses are legitimate characters in a URL, but would be
574
+ # seen as the start of a new unquoted argument by the cmake language parser.
575
+ # Avoid those special cases by preparing quoted strings for direct inclusion
576
+ # in the foreach() call that iterates over the set of URLs in REMOTE.
577
+ set(REMOTE "[====[${REMOTE}]====]")
578
+ string(REPLACE ";" "]====] [====[" REMOTE "${REMOTE}")
579
+
580
+ if(timeout)
581
+ set(TIMEOUT_ARGS TIMEOUT ${timeout})
582
+ set(TIMEOUT_MSG "${timeout} seconds")
583
+ else()
584
+ set(TIMEOUT_ARGS "# no TIMEOUT")
585
+ set(TIMEOUT_MSG "none")
586
+ endif()
587
+ if(inactivity_timeout)
588
+ set(INACTIVITY_TIMEOUT_ARGS INACTIVITY_TIMEOUT ${inactivity_timeout})
589
+ set(INACTIVITY_TIMEOUT_MSG "${inactivity_timeout} seconds")
590
+ else()
591
+ set(INACTIVITY_TIMEOUT_ARGS "# no INACTIVITY_TIMEOUT")
592
+ set(INACTIVITY_TIMEOUT_MSG "none")
593
+ endif()
594
+
595
+ if(no_progress)
596
+ set(SHOW_PROGRESS "")
597
+ else()
598
+ set(SHOW_PROGRESS "SHOW_PROGRESS")
599
+ endif()
600
+
601
+ _ep_get_hash_regex(_ep_hash_regex)
602
+ if("${hash}" MATCHES "${_ep_hash_regex}")
603
+ set(ALGO "${CMAKE_MATCH_1}")
604
+ string(TOLOWER "${CMAKE_MATCH_2}" EXPECT_VALUE)
605
+ else()
606
+ set(ALGO "")
607
+ set(EXPECT_VALUE "")
608
+ endif()
609
+
610
+ set(TLS_VERSION_CODE "")
611
+ if(NOT "x${tls_version}" STREQUAL "x")
612
+ set(TLS_VERSION_CODE "set(CMAKE_TLS_VERSION \"${tls_version}\")")
613
+ endif()
614
+
615
+ set(TLS_VERIFY_CODE "")
616
+ if(NOT "x${tls_verify}" STREQUAL "x")
617
+ set(TLS_VERIFY_CODE "set(CMAKE_TLS_VERIFY \"${tls_verify}\")")
618
+ endif()
619
+
620
+ set(TLS_CAINFO_CODE "")
621
+ if(NOT "x${tls_cainfo}" STREQUAL "x")
622
+ set(TLS_CAINFO_CODE "set(CMAKE_TLS_CAINFO \"${tls_cainfo}\")")
623
+ endif()
624
+
625
+ set(NETRC_CODE "")
626
+ if(NOT "x${netrc}" STREQUAL "x")
627
+ set(NETRC_CODE "set(CMAKE_NETRC \"${netrc}\")")
628
+ endif()
629
+
630
+ set(NETRC_FILE_CODE "")
631
+ if(NOT "x${netrc_file}" STREQUAL "x")
632
+ set(NETRC_FILE_CODE "set(CMAKE_NETRC_FILE \"${netrc_file}\")")
633
+ endif()
634
+
635
+ if(userpwd STREQUAL ":")
636
+ set(USERPWD_ARGS)
637
+ else()
638
+ set(USERPWD_ARGS USERPWD "${userpwd}")
639
+ endif()
640
+
641
+ set(HTTP_HEADERS_ARGS "")
642
+ if(NOT http_headers STREQUAL "")
643
+ foreach(header IN LISTS http_headers)
644
+ string(PREPEND HTTP_HEADERS_ARGS
645
+ "HTTPHEADER \"${header}\"\n "
646
+ )
647
+ endforeach()
648
+ endif()
649
+
650
+ # Used variables:
651
+ # * TLS_VERSION_CODE
652
+ # * TLS_VERIFY_CODE
653
+ # * TLS_CAINFO_CODE
654
+ # * ALGO
655
+ # * EXPECT_VALUE
656
+ # * REMOTE
657
+ # * LOCAL
658
+ # * SHOW_PROGRESS
659
+ # * TIMEOUT_ARGS
660
+ # * TIMEOUT_MSG
661
+ # * USERPWD_ARGS
662
+ # * HTTP_HEADERS_ARGS
663
+ configure_file(
664
+ "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/download.cmake.in"
665
+ "${script_filename}"
666
+ @ONLY
667
+ )
668
+ endfunction()
669
+
670
+
671
+ function(_ep_write_verifyfile_script
672
+ script_filename
673
+ LOCAL
674
+ hash
675
+ )
676
+ _ep_get_hash_regex(_ep_hash_regex)
677
+ if("${hash}" MATCHES "${_ep_hash_regex}")
678
+ set(ALGO "${CMAKE_MATCH_1}")
679
+ string(TOLOWER "${CMAKE_MATCH_2}" EXPECT_VALUE)
680
+ else()
681
+ set(ALGO "")
682
+ set(EXPECT_VALUE "")
683
+ endif()
684
+
685
+ # Used variables:
686
+ # * ALGO
687
+ # * EXPECT_VALUE
688
+ # * LOCAL
689
+ configure_file(
690
+ "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/verify.cmake.in"
691
+ "${script_filename}"
692
+ @ONLY
693
+ )
694
+ endfunction()
695
+
696
+
697
+ function(_ep_write_extractfile_script
698
+ script_filename
699
+ name
700
+ filename
701
+ directory
702
+ options
703
+ )
704
+ set(args "")
705
+
706
+ if(filename MATCHES
707
+ "(\\.|=)(7z|tar\\.bz2|tar\\.gz|tar\\.xz|tbz2|tgz|txz|zip)$")
708
+ set(args xfz)
709
+ endif()
710
+
711
+ if(filename MATCHES "(\\.|=)tar$")
712
+ set(args xf)
713
+ endif()
714
+
715
+ if(args STREQUAL "")
716
+ message(FATAL_ERROR
717
+ "Do not know how to extract '${filename}' -- known types are: "
718
+ ".7z, .tar, .tar.bz2, .tar.gz, .tar.xz, .tbz2, .tgz, .txz and .zip"
719
+ )
720
+ endif()
721
+
722
+ configure_file(
723
+ "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/extractfile.cmake.in"
724
+ "${script_filename}"
725
+ @ONLY
726
+ )
727
+ endfunction()
728
+
729
+
730
+ function(_ep_is_dir_empty dir empty_var)
731
+ file(GLOB gr "${dir}/*")
732
+ if("${gr}" STREQUAL "")
733
+ set(${empty_var} 1 PARENT_SCOPE)
734
+ else()
735
+ set(${empty_var} 0 PARENT_SCOPE)
736
+ endif()
737
+ endfunction()
738
+
739
+ function(_ep_get_git_submodules_recurse git_submodules_recurse)
740
+ # Checks for GIT_SUBMODULES_RECURSE argument. Default is ON, which sets
741
+ # git_submodules_recurse output variable to "--recursive". Otherwise, the
742
+ # output variable is set to an empty value "".
743
+ # Note that the arguments are assumed to have already been parsed and have
744
+ # been translated into variables with the prefix _EP_... by a call to
745
+ # ep_parse_arguments() or ep_parse_arguments_to_vars().
746
+ if(NOT DEFINED _EP_GIT_SUBMODULES_RECURSE)
747
+ set(recurseFlag "--recursive")
748
+ else()
749
+ if(_EP_GIT_SUBMODULES_RECURSE)
750
+ set(recurseFlag "--recursive")
751
+ else()
752
+ set(recurseFlag "")
753
+ endif()
754
+ endif()
755
+ set(${git_submodules_recurse} "${recurseFlag}" PARENT_SCOPE)
756
+
757
+ # The git submodule update '--recursive' flag requires git >= v1.6.5
758
+ if(recurseFlag AND GIT_VERSION_STRING VERSION_LESS 1.6.5)
759
+ message(FATAL_ERROR
760
+ "git version 1.6.5 or later required for --recursive flag with "
761
+ "'git submodule ...': GIT_VERSION_STRING='${GIT_VERSION_STRING}'"
762
+ )
763
+ endif()
764
+ endfunction()
765
+
766
+
767
+ function(_ep_add_script_commands script_var work_dir cmd)
768
+ # We only support a subset of what ep_replace_location_tags() handles
769
+ set(location_tags
770
+ SOURCE_DIR
771
+ SOURCE_SUBDIR
772
+ BINARY_DIR
773
+ TMP_DIR
774
+ DOWNLOAD_DIR
775
+ DOWNLOADED_FILE
776
+ )
777
+
778
+ # There can be multiple COMMANDs, but we have to split those up to
779
+ # one command per call to execute_process()
780
+ string(CONCAT execute_process_cmd
781
+ "execute_process(\n"
782
+ " WORKING_DIRECTORY \"${work_dir}\"\n"
783
+ " COMMAND_ERROR_IS_FATAL LAST\n"
784
+ )
785
+ cmake_language(GET_MESSAGE_LOG_LEVEL active_log_level)
786
+ if(active_log_level MATCHES "VERBOSE|DEBUG|TRACE")
787
+ string(APPEND execute_process_cmd " COMMAND_ECHO STDOUT\n")
788
+ endif()
789
+ string(APPEND execute_process_cmd " COMMAND ")
790
+
791
+ string(APPEND ${script_var} "${execute_process_cmd}")
792
+
793
+ foreach(cmd_arg IN LISTS cmd)
794
+ if(cmd_arg STREQUAL "COMMAND")
795
+ string(APPEND ${script_var} "\n)\n${execute_process_cmd}")
796
+ else()
797
+ if(_EP_LIST_SEPARATOR)
798
+ string(REPLACE "${_EP_LIST_SEPARATOR}" "\\;" cmd_arg "${cmd_arg}")
799
+ endif()
800
+ foreach(dir IN LISTS location_tags)
801
+ string(REPLACE "<${dir}>" "${_EP_${dir}}" cmd_arg "${cmd_arg}")
802
+ endforeach()
803
+ string(APPEND ${script_var} " [====[${cmd_arg}]====]")
804
+ endif()
805
+ endforeach()
806
+
807
+ string(APPEND ${script_var} "\n)")
808
+ set(${script_var} "${${script_var}}" PARENT_SCOPE)
809
+ endfunction()
810
+
811
+
812
+ function(_ep_add_download_command name)
813
+ set(noValueOptions )
814
+ set(singleValueOptions
815
+ SCRIPT_FILE # These should only be used by FetchContent
816
+ DEPENDS_VARIABLE #
817
+ )
818
+ set(multiValueOptions )
819
+ cmake_parse_arguments(PARSE_ARGV 1 arg
820
+ "${noValueOptions}" "${singleValueOptions}" "${multiValueOptions}"
821
+ )
822
+
823
+ # The various _EP_... variables mentioned here and throughout this function
824
+ # are expected to already have been set by the caller via a call to
825
+ # _ep_parse_arguments() or ep_parse_arguments_to_vars(). Other variables
826
+ # with different names are assigned to for historical reasons only to keep
827
+ # the code more readable and minimize change.
828
+
829
+ set(source_dir "${_EP_SOURCE_DIR}")
830
+ set(stamp_dir "${_EP_STAMP_DIR}")
831
+ set(download_dir "${_EP_DOWNLOAD_DIR}")
832
+ set(tmp_dir "${_EP_TMP_DIR}")
833
+
834
+ set(cmd "${_EP_DOWNLOAD_COMMAND}")
835
+ set(cvs_repository "${_EP_CVS_REPOSITORY}")
836
+ set(svn_repository "${_EP_SVN_REPOSITORY}")
837
+ set(git_repository "${_EP_GIT_REPOSITORY}")
838
+ set(hg_repository "${_EP_HG_REPOSITORY}")
839
+ set(url "${_EP_URL}")
840
+ set(fname "${_EP_DOWNLOAD_NAME}")
841
+
842
+ # TODO: Perhaps file:// should be copied to download dir before extraction.
843
+ string(REGEX REPLACE "file://" "" url "${url}")
844
+
845
+ set(step_script_contents)
846
+ set(depends)
847
+ set(comment)
848
+ set(work_dir)
849
+ set(extra_repo_info)
850
+
851
+ if(DEFINED _EP_DOWNLOAD_COMMAND)
852
+ set(work_dir ${download_dir})
853
+ set(method custom)
854
+ if(NOT "x${cmd}" STREQUAL "x" AND arg_SCRIPT_FILE)
855
+ _ep_add_script_commands(
856
+ step_script_contents
857
+ "${work_dir}"
858
+ "${cmd}" # Must be a single quoted argument
859
+ )
860
+ endif()
861
+
862
+ elseif(cvs_repository)
863
+ set(method cvs)
864
+ find_package(CVS QUIET)
865
+ if(NOT CVS_EXECUTABLE)
866
+ message(FATAL_ERROR "error: could not find cvs for checkout of ${name}")
867
+ endif()
868
+
869
+ set(cvs_module "${_EP_CVS_MODULE}")
870
+ if(NOT cvs_module)
871
+ message(FATAL_ERROR "error: no CVS_MODULE")
872
+ endif()
873
+
874
+ set(cvs_tag "${_EP_CVS_TAG}")
875
+ get_filename_component(src_name "${source_dir}" NAME)
876
+ get_filename_component(work_dir "${source_dir}" PATH)
877
+ set(comment "Performing download step (CVS checkout) for '${name}'")
878
+ set(cmd
879
+ ${CVS_EXECUTABLE}
880
+ -d ${cvs_repository}
881
+ -q
882
+ co ${cvs_tag}
883
+ -d ${src_name}
884
+ ${cvs_module}
885
+ )
886
+ if(arg_SCRIPT_FILE)
887
+ _ep_add_script_commands(
888
+ step_script_contents
889
+ "${work_dir}"
890
+ "${cmd}" # Must be a single quoted argument
891
+ )
892
+ endif()
893
+
894
+ elseif(svn_repository)
895
+ set(method svn)
896
+ find_package(Subversion QUIET)
897
+ if(NOT Subversion_SVN_EXECUTABLE)
898
+ message(FATAL_ERROR "error: could not find svn for checkout of ${name}")
899
+ endif()
900
+
901
+ set(svn_trust_cert "${_EP_SVN_TRUST_CERT}")
902
+ set(uses_terminal "${_EP_USES_TERMINAL_DOWNLOAD}")
903
+
904
+ get_filename_component(src_name "${source_dir}" NAME)
905
+ get_filename_component(work_dir "${source_dir}" PATH)
906
+ set(comment "Performing download step (SVN checkout) for '${name}'")
907
+ set(cmd
908
+ ${Subversion_SVN_EXECUTABLE}
909
+ co
910
+ ${svn_repository}
911
+ ${_EP_SVN_REVISION}
912
+ )
913
+ # The --trust-server-cert option requires --non-interactive
914
+ if(svn_trust_cert OR NOT uses_terminal)
915
+ list(APPEND cmd "--non-interactive")
916
+ endif()
917
+ if(svn_trust_cert)
918
+ list(APPEND cmd "--trust-server-cert")
919
+ endif()
920
+ if(DEFINED _EP_SVN_USERNAME)
921
+ list(APPEND cmd "--username=${_EP_SVN_USERNAME}")
922
+ endif()
923
+ if(DEFINED _EP_SVN_PASSWORD)
924
+ list(APPEND cmd "--password=${_EP_SVN_PASSWORD}")
925
+ endif()
926
+ list(APPEND cmd ${src_name})
927
+
928
+ if(arg_SCRIPT_FILE)
929
+ _ep_add_script_commands(
930
+ step_script_contents
931
+ "${work_dir}"
932
+ "${cmd}" # Must be a single quoted argument
933
+ )
934
+ endif()
935
+
936
+ elseif(git_repository)
937
+ set(method git)
938
+ # FetchContent gives us these directly, so don't try to recompute them
939
+ if(NOT GIT_EXECUTABLE OR NOT GIT_VERSION_STRING)
940
+ unset(CMAKE_MODULE_PATH) # Use CMake builtin find module
941
+ find_package(Git QUIET)
942
+ if(NOT GIT_EXECUTABLE)
943
+ message(FATAL_ERROR "error: could not find git for clone of ${name}")
944
+ endif()
945
+ endif()
946
+
947
+ _ep_get_git_submodules_recurse(git_submodules_recurse)
948
+
949
+ set(git_tag "${_EP_GIT_TAG}")
950
+ if(NOT git_tag)
951
+ set(git_tag "master")
952
+ endif()
953
+
954
+ set(git_init_submodules TRUE)
955
+ if(DEFINED _EP_GIT_SUBMODULES)
956
+ set(git_submodules "${_EP_GIT_SUBMODULES}")
957
+ if(git_submodules STREQUAL "" AND _EP_CMP0097 STREQUAL "NEW")
958
+ set(git_init_submodules FALSE)
959
+ endif()
960
+ endif()
961
+
962
+ set(git_remote_name "${_EP_GIT_REMOTE_NAME}")
963
+ if(NOT git_remote_name)
964
+ set(git_remote_name "origin")
965
+ endif()
966
+
967
+ _ep_get_tls_version(${name} tls_version)
968
+ _ep_get_tls_verify(${name} tls_verify)
969
+ set(git_shallow "${_EP_GIT_SHALLOW}")
970
+ set(git_progress "${_EP_GIT_PROGRESS}")
971
+ set(git_config "${_EP_GIT_CONFIG}")
972
+
973
+ # If git supports it, make checkouts quiet when checking out a git hash.
974
+ # This avoids the very noisy detached head message.
975
+ if(GIT_VERSION_STRING VERSION_GREATER_EQUAL 1.7.7)
976
+ list(PREPEND git_config advice.detachedHead=false)
977
+ endif()
978
+
979
+ # The command doesn't expose any details, so we need to record additional
980
+ # information in the RepositoryInfo.txt file. For the download step, only
981
+ # the things specifically affecting the clone operation should be recorded.
982
+ # If the repo changes, the clone script should be run again.
983
+ # But if only the tag changes, avoid running the clone script again.
984
+ # Let the 'always' running update step checkout the new tag.
985
+ #
986
+ set(extra_repo_info
987
+ "repository=${git_repository}
988
+ remote=${git_remote_name}
989
+ init_submodules=${git_init_submodules}
990
+ recurse_submodules=${git_submodules_recurse}
991
+ submodules=${git_submodules}
992
+ CMP0097=${_EP_CMP0097}
993
+ ")
994
+ get_filename_component(src_name "${source_dir}" NAME)
995
+ get_filename_component(work_dir "${source_dir}" PATH)
996
+
997
+ # Since git clone doesn't succeed if the non-empty source_dir exists,
998
+ # create a cmake script to invoke as download command.
999
+ # The script will delete the source directory and then call git clone.
1000
+ #
1001
+ set(clone_script ${tmp_dir}/${name}-gitclone.cmake)
1002
+ _ep_write_gitclone_script(
1003
+ ${clone_script}
1004
+ ${source_dir}
1005
+ ${GIT_EXECUTABLE}
1006
+ ${git_repository}
1007
+ ${git_tag}
1008
+ ${git_remote_name}
1009
+ ${git_init_submodules}
1010
+ "${git_submodules_recurse}"
1011
+ "${git_submodules}"
1012
+ "${git_shallow}"
1013
+ "${git_progress}"
1014
+ "${git_config}"
1015
+ ${src_name}
1016
+ ${work_dir}
1017
+ ${stamp_dir}/${name}-gitinfo.txt
1018
+ ${stamp_dir}/${name}-gitclone-lastrun.txt
1019
+ "${tls_version}"
1020
+ "${tls_verify}"
1021
+ )
1022
+ set(comment "Performing download step (git clone) for '${name}'")
1023
+ set(cmd ${CMAKE_COMMAND}
1024
+ -DCMAKE_MESSAGE_LOG_LEVEL=VERBOSE
1025
+ -P ${clone_script}
1026
+ )
1027
+
1028
+ if(arg_SCRIPT_FILE)
1029
+ set(step_script_contents "include(\"${clone_script}\")")
1030
+ list(APPEND depends ${clone_script})
1031
+ endif()
1032
+
1033
+ elseif(hg_repository)
1034
+ set(method hg)
1035
+ find_package(Hg QUIET)
1036
+ if(NOT HG_EXECUTABLE)
1037
+ message(FATAL_ERROR "error: could not find hg for clone of ${name}")
1038
+ endif()
1039
+
1040
+ set(hg_tag "${_EP_HG_TAG}")
1041
+ if(NOT hg_tag)
1042
+ set(hg_tag "tip")
1043
+ endif()
1044
+
1045
+ # The command doesn't expose any details, so we need to record additional
1046
+ # information in the RepositoryInfo.txt file. For the download step, only
1047
+ # the things specifically affecting the clone operation should be recorded.
1048
+ # If the repo changes, the clone script should be run again.
1049
+ # But if only the tag changes, avoid running the clone script again.
1050
+ # Let the 'always' running update step checkout the new tag.
1051
+ #
1052
+ set(extra_repo_info "repository=${hg_repository}")
1053
+ get_filename_component(src_name "${source_dir}" NAME)
1054
+ get_filename_component(work_dir "${source_dir}" PATH)
1055
+
1056
+ # Since hg clone doesn't succeed if the non-empty source_dir exists,
1057
+ # create a cmake script to invoke as download command.
1058
+ # The script will delete the source directory and then call hg clone.
1059
+ #
1060
+ set(clone_script ${tmp_dir}/${name}-hgclone.cmake)
1061
+ _ep_write_hgclone_script(
1062
+ ${clone_script}
1063
+ ${source_dir}
1064
+ ${HG_EXECUTABLE}
1065
+ ${hg_repository}
1066
+ ${hg_tag}
1067
+ ${src_name}
1068
+ ${work_dir}
1069
+ ${stamp_dir}/${name}-hginfo.txt
1070
+ ${stamp_dir}/${name}-hgclone-lastrun.txt
1071
+ )
1072
+ set(comment "Performing download step (hg clone) for '${name}'")
1073
+ set(cmd ${CMAKE_COMMAND}
1074
+ -DCMAKE_MESSAGE_LOG_LEVEL=VERBOSE
1075
+ -P ${clone_script}
1076
+ )
1077
+
1078
+ if(arg_SCRIPT_FILE)
1079
+ set(step_script_contents "include(\"${clone_script}\")")
1080
+ list(APPEND depends ${clone_script})
1081
+ endif()
1082
+
1083
+ elseif(url)
1084
+ set(method url)
1085
+ get_filename_component(work_dir "${source_dir}" PATH)
1086
+ set(hash "${_EP_URL_HASH}")
1087
+ _ep_get_hash_regex(_ep_hash_regex)
1088
+ if(hash AND NOT "${hash}" MATCHES "${_ep_hash_regex}")
1089
+ _ep_get_hash_algos(_ep_hash_algos)
1090
+ list(JOIN _ep_hash_algos "|" _ep_hash_algos)
1091
+ message(FATAL_ERROR
1092
+ "URL_HASH is set to\n"
1093
+ " ${hash}\n"
1094
+ "but must be ALGO=value where ALGO is\n"
1095
+ " ${_ep_hash_algos}\n"
1096
+ "and value is a hex string."
1097
+ )
1098
+ endif()
1099
+ set(md5 "${_EP_URL_MD5}")
1100
+ if(md5 AND NOT "MD5=${md5}" MATCHES "${_ep_hash_regex}")
1101
+ message(FATAL_ERROR
1102
+ "URL_MD5 is set to\n"
1103
+ " ${md5}\n"
1104
+ "but must be a hex string."
1105
+ )
1106
+ endif()
1107
+ if(md5 AND NOT hash)
1108
+ set(hash "MD5=${md5}")
1109
+ endif()
1110
+ set(extra_repo_info
1111
+ "url(s)=${url}
1112
+ hash=${hash}
1113
+ ")
1114
+
1115
+ list(LENGTH url url_list_length)
1116
+ if(NOT "${url_list_length}" STREQUAL "1")
1117
+ foreach(entry IN LISTS url)
1118
+ if(NOT "${entry}" MATCHES "^[a-z]+://")
1119
+ message(FATAL_ERROR
1120
+ "At least one entry of URL is a path (invalid in a list)"
1121
+ )
1122
+ endif()
1123
+ endforeach()
1124
+ if("x${fname}" STREQUAL "x")
1125
+ list(GET url 0 fname)
1126
+ endif()
1127
+ endif()
1128
+
1129
+ if(IS_DIRECTORY "${url}")
1130
+ get_filename_component(abs_dir "${url}" ABSOLUTE)
1131
+ set(comment "Performing download step (DIR copy) for '${name}'")
1132
+ set(cmd
1133
+ ${CMAKE_COMMAND} -E rm -rf ${source_dir}
1134
+ COMMAND ${CMAKE_COMMAND} -E copy_directory ${abs_dir} ${source_dir}
1135
+ )
1136
+ if(arg_SCRIPT_FILE)
1137
+ # While it may be tempting to implement the two operations directly
1138
+ # with file(), the behavior is different. file(COPY) preserves input
1139
+ # file timestamps, which we don't want. Therefore, still use the same
1140
+ # external commands so that we get the same behavior.
1141
+ _ep_add_script_commands(
1142
+ step_script_contents
1143
+ "${work_dir}"
1144
+ "${cmd}" # Must be a single quoted argument
1145
+ )
1146
+ endif()
1147
+ else()
1148
+ set(no_extract "${_EP_DOWNLOAD_NO_EXTRACT}")
1149
+ string(APPEND extra_repo_info "no_extract=${no_extract}\n")
1150
+ set(verify_script "${stamp_dir}/verify-${name}.cmake")
1151
+ if("${url}" MATCHES "^[a-z]+://")
1152
+ # TODO: Should download and extraction be different steps?
1153
+ if("x${fname}" STREQUAL "x")
1154
+ set(fname "${url}")
1155
+ endif()
1156
+ set(ext_regex [[7z|tar|tar\.bz2|tar\.gz|tar\.xz|tbz2|tgz|txz|zip]])
1157
+ if("${fname}" MATCHES "([^/\\?#]+(\\.|=)(${ext_regex}))([/?#].*)?$")
1158
+ set(fname "${CMAKE_MATCH_1}")
1159
+ elseif(no_extract)
1160
+ get_filename_component(fname "${fname}" NAME)
1161
+ else()
1162
+ # Fall back to a default file name. The actual file name does not
1163
+ # matter because it is used only internally and our extraction tool
1164
+ # inspects the file content directly. If it turns out the wrong URL
1165
+ # was given that will be revealed during the build which is an easier
1166
+ # place for users to diagnose than an error here anyway.
1167
+ set(fname "archive.tar")
1168
+ endif()
1169
+ string(REPLACE ";" "-" fname "${fname}")
1170
+ set(file ${download_dir}/${fname})
1171
+ set(timeout "${_EP_TIMEOUT}")
1172
+ set(inactivity_timeout "${_EP_INACTIVITY_TIMEOUT}")
1173
+ set(no_progress "${_EP_DOWNLOAD_NO_PROGRESS}")
1174
+ _ep_get_tls_version(${name} tls_version)
1175
+ _ep_get_tls_verify(${name} tls_verify)
1176
+ _ep_get_tls_cainfo(${name} tls_cainfo)
1177
+ _ep_get_netrc(${name} netrc)
1178
+ _ep_get_netrc_file(${name} netrc_file)
1179
+ set(http_username "${_EP_HTTP_USERNAME}")
1180
+ set(http_password "${_EP_HTTP_PASSWORD}")
1181
+ set(http_headers "${_EP_HTTP_HEADER}")
1182
+ set(download_script "${stamp_dir}/download-${name}.cmake")
1183
+ _ep_write_downloadfile_script(
1184
+ "${download_script}"
1185
+ "${url}"
1186
+ "${file}"
1187
+ "${timeout}"
1188
+ "${inactivity_timeout}"
1189
+ "${no_progress}"
1190
+ "${hash}"
1191
+ "${tls_version}"
1192
+ "${tls_verify}"
1193
+ "${tls_cainfo}"
1194
+ "${http_username}:${http_password}"
1195
+ "${http_headers}"
1196
+ "${netrc}"
1197
+ "${netrc_file}"
1198
+ )
1199
+ set(cmd
1200
+ ${CMAKE_COMMAND}
1201
+ -DCMAKE_MESSAGE_LOG_LEVEL=VERBOSE
1202
+ -P "${download_script}"
1203
+ COMMAND
1204
+ )
1205
+ if(arg_SCRIPT_FILE)
1206
+ set(step_script_contents "include(\"${download_script}\")\n")
1207
+ endif()
1208
+
1209
+ if (no_extract)
1210
+ set(steps "download and verify")
1211
+ else ()
1212
+ set(steps "download, verify and extract")
1213
+ endif ()
1214
+ set(comment "Performing download step (${steps}) for '${name}'")
1215
+ # already verified by 'download_script'
1216
+ # We use file(CONFIGURE) instead of file(WRITE) to avoid updating the
1217
+ # timestamp when the file already existed and was empty.
1218
+ file(CONFIGURE OUTPUT "${verify_script}" CONTENT "")
1219
+
1220
+ # Rather than adding everything to the RepositoryInfo.txt file, it is
1221
+ # more robust to just depend on the download script. That way, we will
1222
+ # re-download if any aspect of the download changes.
1223
+ list(APPEND depends "${download_script}")
1224
+ else()
1225
+ set(file "${url}")
1226
+ if (no_extract)
1227
+ set(steps "verify")
1228
+ else ()
1229
+ set(steps "verify and extract")
1230
+ endif ()
1231
+ set(comment "Performing download step (${steps}) for '${name}'")
1232
+ _ep_write_verifyfile_script(
1233
+ "${verify_script}"
1234
+ "${file}"
1235
+ "${hash}"
1236
+ )
1237
+ endif()
1238
+ list(APPEND cmd ${CMAKE_COMMAND}
1239
+ -DCMAKE_MESSAGE_LOG_LEVEL=VERBOSE
1240
+ -P ${verify_script}
1241
+ )
1242
+ if(arg_SCRIPT_FILE)
1243
+ string(APPEND step_script_contents "include(\"${verify_script}\")\n")
1244
+ list(APPEND depends ${verify_script})
1245
+ endif()
1246
+ set(extract_timestamp "${_EP_DOWNLOAD_EXTRACT_TIMESTAMP}")
1247
+ if(no_extract)
1248
+ if(DEFINED _EP_DOWNLOAD_EXTRACT_TIMESTAMP)
1249
+ message(FATAL_ERROR
1250
+ "Cannot specify DOWNLOAD_EXTRACT_TIMESTAMP when using "
1251
+ "DOWNLOAD_NO_EXTRACT TRUE"
1252
+ )
1253
+ endif()
1254
+ if(arg_SCRIPT_FILE)
1255
+ # There's no target to record the location of the downloaded file.
1256
+ # Instead, we copy it to the source directory within the script,
1257
+ # which is what FetchContent always does in this situation.
1258
+ cmake_path(SET safe_file NORMALIZE "${file}")
1259
+ cmake_path(GET safe_file FILENAME filename)
1260
+ string(APPEND step_script_contents
1261
+ "file(COPY_FILE\n"
1262
+ " \"${file}\"\n"
1263
+ " \"${source_dir}/${filename}\"\n"
1264
+ " ONLY_IF_DIFFERENT\n"
1265
+ " INPUT_MAY_BE_RECENT\n"
1266
+ ")"
1267
+ )
1268
+ list(APPEND depends ${source_dir}/${filename})
1269
+ else()
1270
+ set_property(TARGET ${name} PROPERTY _EP_DOWNLOADED_FILE ${file})
1271
+ endif()
1272
+ else()
1273
+ if(NOT DEFINED _EP_DOWNLOAD_EXTRACT_TIMESTAMP)
1274
+ # Default depends on policy CMP0135
1275
+ if(_EP_CMP0135 STREQUAL "")
1276
+ message(AUTHOR_WARNING
1277
+ "The DOWNLOAD_EXTRACT_TIMESTAMP option was not given and policy "
1278
+ "CMP0135 is not set. The policy's OLD behavior will be used. "
1279
+ "When using a URL download, the timestamps of extracted files "
1280
+ "should preferably be that of the time of extraction, otherwise "
1281
+ "code that depends on the extracted contents might not be "
1282
+ "rebuilt if the URL changes. The OLD behavior preserves the "
1283
+ "timestamps from the archive instead, but this is usually not "
1284
+ "what you want. Update your project to the NEW behavior or "
1285
+ "specify the DOWNLOAD_EXTRACT_TIMESTAMP option with a value of "
1286
+ "true to avoid this robustness issue."
1287
+ )
1288
+ set(extract_timestamp TRUE)
1289
+ elseif(_EP_CMP0135 STREQUAL "NEW")
1290
+ set(extract_timestamp FALSE)
1291
+ else()
1292
+ set(extract_timestamp TRUE)
1293
+ endif()
1294
+ endif()
1295
+ if(extract_timestamp)
1296
+ set(options "")
1297
+ else()
1298
+ set(options "--touch")
1299
+ endif()
1300
+ set(extract_script "${stamp_dir}/extract-${name}.cmake")
1301
+ _ep_write_extractfile_script(
1302
+ "${extract_script}"
1303
+ "${name}"
1304
+ "${file}"
1305
+ "${source_dir}"
1306
+ "${options}"
1307
+ )
1308
+ list(APPEND cmd
1309
+ COMMAND ${CMAKE_COMMAND}
1310
+ -DCMAKE_MESSAGE_LOG_LEVEL=VERBOSE
1311
+ -P ${extract_script}
1312
+ )
1313
+ if(arg_SCRIPT_FILE)
1314
+ string(APPEND step_script_contents "include(\"${extract_script}\")\n")
1315
+ list(APPEND depends ${extract_script})
1316
+ endif()
1317
+ endif ()
1318
+ endif()
1319
+ else()
1320
+ set(method source_dir)
1321
+ _ep_is_dir_empty("${source_dir}" empty)
1322
+ if(${empty})
1323
+ message(FATAL_ERROR
1324
+ "No download info given for '${name}' and its source directory:\n"
1325
+ " ${source_dir}\n"
1326
+ "is not an existing non-empty directory. Please specify one of:\n"
1327
+ " * SOURCE_DIR with an existing non-empty directory\n"
1328
+ " * DOWNLOAD_COMMAND\n"
1329
+ " * URL\n"
1330
+ " * GIT_REPOSITORY\n"
1331
+ " * SVN_REPOSITORY\n"
1332
+ " * HG_REPOSITORY\n"
1333
+ " * CVS_REPOSITORY and CVS_MODULE"
1334
+ )
1335
+ endif()
1336
+ if(arg_SCRIPT_FILE)
1337
+ set(step_script_contents "message(VERBOSE [[Using SOURCE_DIR as is]])")
1338
+ endif()
1339
+ endif()
1340
+
1341
+ # We use configure_file() to write the repo_info_file so that the file's
1342
+ # timestamp is not updated if we don't change the contents
1343
+
1344
+ set(repo_info_file ${stamp_dir}/${name}-${method}info.txt)
1345
+ list(APPEND depends ${repo_info_file})
1346
+ configure_file(
1347
+ "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/RepositoryInfo.txt.in"
1348
+ "${repo_info_file}"
1349
+ @ONLY
1350
+ )
1351
+
1352
+ if(arg_SCRIPT_FILE)
1353
+ set(step_name download)
1354
+ configure_file(
1355
+ "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/stepscript.cmake.in"
1356
+ "${arg_SCRIPT_FILE}"
1357
+ @ONLY
1358
+ )
1359
+ set(${arg_DEPENDS_VARIABLE} "${depends}" PARENT_SCOPE)
1360
+ return()
1361
+ endif()
1362
+
1363
+ # Nothing below this point is applicable when we've been asked to put the
1364
+ # download step in a script file (which is the FetchContent case).
1365
+
1366
+ if(_EP_LOG_DOWNLOAD)
1367
+ set(log LOG 1)
1368
+ else()
1369
+ set(log "")
1370
+ endif()
1371
+
1372
+ if(_EP_USES_TERMINAL_DOWNLOAD)
1373
+ set(uses_terminal USES_TERMINAL 1)
1374
+ else()
1375
+ set(uses_terminal "")
1376
+ endif()
1377
+
1378
+ set(__cmdQuoted)
1379
+ foreach(__item IN LISTS cmd)
1380
+ string(APPEND __cmdQuoted " [==[${__item}]==]")
1381
+ endforeach()
1382
+ cmake_language(EVAL CODE "
1383
+ ExternalProject_Add_Step(\${name} download
1384
+ INDEPENDENT TRUE
1385
+ COMMENT \${comment}
1386
+ COMMAND ${__cmdQuoted}
1387
+ WORKING_DIRECTORY \${work_dir}
1388
+ DEPENDS \${depends}
1389
+ DEPENDEES mkdir
1390
+ ${log}
1391
+ ${uses_terminal}
1392
+ )"
1393
+ )
1394
+ endfunction()
1395
+
1396
+ function(_ep_get_update_disconnected var name)
1397
+ # Note that the arguments are assumed to have already been parsed and have
1398
+ # been translated into variables with the prefix _EP_... by a call to
1399
+ # ep_parse_arguments() or ep_parse_arguments_to_vars().
1400
+ if(DEFINED _EP_UPDATE_DISCONNECTED)
1401
+ set(update_disconnected "${_EP_UPDATE_DISCONNECTED}")
1402
+ else()
1403
+ get_property(update_disconnected
1404
+ DIRECTORY
1405
+ PROPERTY EP_UPDATE_DISCONNECTED
1406
+ )
1407
+ endif()
1408
+ set(${var} "${update_disconnected}" PARENT_SCOPE)
1409
+ endfunction()
1410
+
1411
+ function(_ep_add_update_command name)
1412
+ set(noValueOptions )
1413
+ set(singleValueOptions
1414
+ SCRIPT_FILE # These should only be used by FetchContent
1415
+ DEPEND_VARIABLE #
1416
+ )
1417
+ set(multiValueOptions )
1418
+ cmake_parse_arguments(PARSE_ARGV 1 arg
1419
+ "${noValueOptions}" "${singleValueOptions}" "${multiValueOptions}"
1420
+ )
1421
+
1422
+ # The various _EP_... variables mentioned here and throughout this function
1423
+ # are expected to already have been set by the caller via a call to
1424
+ # _ep_parse_arguments() or ep_parse_arguments_to_vars(). Other variables
1425
+ # with different names are assigned to for historical reasons only to keep
1426
+ # the code more readable and minimize change.
1427
+
1428
+ set(source_dir "${_EP_SOURCE_DIR}")
1429
+ set(stamp_dir "${_EP_STAMP_DIR}")
1430
+ set(tmp_dir "${_EP_TMP_DIR}")
1431
+
1432
+ set(cmd "${_EP_UPDATE_COMMAND}")
1433
+ set(cvs_repository "${_EP_CVS_REPOSITORY}")
1434
+ set(svn_repository "${_EP_SVN_REPOSITORY}")
1435
+ set(git_repository "${_EP_GIT_REPOSITORY}")
1436
+ set(hg_repository "${_EP_HG_REPOSITORY}")
1437
+
1438
+ _ep_get_update_disconnected(update_disconnected ${name})
1439
+
1440
+ set(work_dir)
1441
+ set(cmd_disconnected)
1442
+ set(comment)
1443
+ set(comment_disconnected)
1444
+ set(always)
1445
+ set(file_deps)
1446
+
1447
+ if(DEFINED _EP_UPDATE_COMMAND)
1448
+ set(work_dir ${source_dir})
1449
+ if(NOT "x${cmd}" STREQUAL "x")
1450
+ set(always 1)
1451
+ _ep_add_script_commands(
1452
+ step_script_contents
1453
+ "${work_dir}"
1454
+ "${cmd}" # Must be a single quoted argument
1455
+ )
1456
+ endif()
1457
+
1458
+ elseif(cvs_repository)
1459
+ if(NOT CVS_EXECUTABLE)
1460
+ message(FATAL_ERROR "error: could not find cvs for update of ${name}")
1461
+ endif()
1462
+ set(work_dir ${source_dir})
1463
+ set(comment "Performing update step (CVS update) for '${name}'")
1464
+ set(cvs_tag "${_EP_CVS_TAG}")
1465
+ set(cmd ${CVS_EXECUTABLE} -d ${cvs_repository} -q up -dP ${cvs_tag})
1466
+ set(always 1)
1467
+
1468
+ if(arg_SCRIPT_FILE)
1469
+ _ep_add_script_commands(
1470
+ step_script_contents
1471
+ "${work_dir}"
1472
+ "${cmd}" # Must be a single quoted argument
1473
+ )
1474
+ endif()
1475
+
1476
+ elseif(svn_repository)
1477
+ if(NOT Subversion_SVN_EXECUTABLE)
1478
+ message(FATAL_ERROR "error: could not find svn for update of ${name}")
1479
+ endif()
1480
+ set(work_dir ${source_dir})
1481
+ set(comment "Performing update step (SVN update) for '${name}'")
1482
+ set(svn_trust_cert "${_EP_SVN_TRUST_CERT}")
1483
+ set(uses_terminal "${_EP_USES_TERMINAL_UPDATE}")
1484
+ set(cmd
1485
+ ${Subversion_SVN_EXECUTABLE}
1486
+ up
1487
+ ${_EP_SVN_REVISION}
1488
+ )
1489
+ # The --trust-server-cert option requires --non-interactive
1490
+ if(svn_trust_cert OR NOT uses_terminal)
1491
+ list(APPEND cmd "--non-interactive")
1492
+ endif()
1493
+ if(svn_trust_cert)
1494
+ list(APPEND cmd --trust-server-cert)
1495
+ endif()
1496
+ if(DEFINED _EP_SVN_USERNAME)
1497
+ list(APPEND cmd "--username=${_EP_SVN_USERNAME}")
1498
+ endif()
1499
+ if(DEFINED _EP_SVN_PASSWORD)
1500
+ list(APPEND cmd "--password=${_EP_SVN_PASSWORD}")
1501
+ endif()
1502
+ set(always 1)
1503
+
1504
+ if(arg_SCRIPT_FILE)
1505
+ _ep_add_script_commands(
1506
+ step_script_contents
1507
+ "${work_dir}"
1508
+ "${cmd}" # Must be a single quoted argument
1509
+ )
1510
+ endif()
1511
+
1512
+ elseif(git_repository)
1513
+ # FetchContent gives us these directly, so don't try to recompute them
1514
+ if(NOT GIT_EXECUTABLE OR NOT GIT_VERSION_STRING)
1515
+ unset(CMAKE_MODULE_PATH) # Use CMake builtin find module
1516
+ find_package(Git QUIET)
1517
+ if(NOT GIT_EXECUTABLE)
1518
+ message(FATAL_ERROR "error: could not find git for fetch of ${name}")
1519
+ endif()
1520
+ endif()
1521
+ set(work_dir ${source_dir})
1522
+ set(comment "Performing update step for '${name}'")
1523
+ set(comment_disconnected "Performing disconnected update step for '${name}'")
1524
+
1525
+ if(update_disconnected)
1526
+ set(can_fetch_default NO)
1527
+ else()
1528
+ set(can_fetch_default YES)
1529
+ endif()
1530
+
1531
+ set(git_tag "${_EP_GIT_TAG}")
1532
+ if(NOT git_tag)
1533
+ set(git_tag "master")
1534
+ endif()
1535
+
1536
+ set(git_remote_name "${_EP_GIT_REMOTE_NAME}")
1537
+ if(NOT git_remote_name)
1538
+ set(git_remote_name "origin")
1539
+ endif()
1540
+
1541
+ set(git_init_submodules TRUE)
1542
+ if(DEFINED _EP_GIT_SUBMODULES)
1543
+ set(git_submodules "${_EP_GIT_SUBMODULES}")
1544
+ if(git_submodules STREQUAL "" AND _EP_CMP0097 STREQUAL "NEW")
1545
+ set(git_init_submodules FALSE)
1546
+ endif()
1547
+ endif()
1548
+
1549
+ set(git_update_strategy "${_EP_GIT_REMOTE_UPDATE_STRATEGY}")
1550
+ if(NOT git_update_strategy)
1551
+ set(git_update_strategy "${CMAKE_EP_GIT_REMOTE_UPDATE_STRATEGY}")
1552
+ endif()
1553
+ if(NOT git_update_strategy)
1554
+ set(git_update_strategy REBASE)
1555
+ endif()
1556
+ set(strategies CHECKOUT REBASE REBASE_CHECKOUT)
1557
+ if(NOT git_update_strategy IN_LIST strategies)
1558
+ message(FATAL_ERROR
1559
+ "'${git_update_strategy}' is not one of the supported strategies: "
1560
+ "${strategies}"
1561
+ )
1562
+ endif()
1563
+
1564
+ _ep_get_git_submodules_recurse(git_submodules_recurse)
1565
+
1566
+ _ep_get_tls_version(${name} tls_version)
1567
+ _ep_get_tls_verify(${name} tls_verify)
1568
+
1569
+ set(update_script "${tmp_dir}/${name}-gitupdate.cmake")
1570
+ list(APPEND file_deps ${update_script})
1571
+ _ep_write_gitupdate_script(
1572
+ "${update_script}"
1573
+ "${GIT_EXECUTABLE}"
1574
+ "${git_tag}"
1575
+ "${git_remote_name}"
1576
+ "${git_init_submodules}"
1577
+ "${git_submodules_recurse}"
1578
+ "${git_submodules}"
1579
+ "${git_repository}"
1580
+ "${work_dir}"
1581
+ "${git_update_strategy}"
1582
+ "${tls_version}"
1583
+ "${tls_verify}"
1584
+ )
1585
+ set(cmd ${CMAKE_COMMAND}
1586
+ -Dcan_fetch=YES
1587
+ -DCMAKE_MESSAGE_LOG_LEVEL=VERBOSE
1588
+ -P ${update_script}
1589
+ )
1590
+ set(cmd_disconnected ${CMAKE_COMMAND}
1591
+ -Dcan_fetch=NO
1592
+ -DCMAKE_MESSAGE_LOG_LEVEL=VERBOSE
1593
+ -P ${update_script}
1594
+ )
1595
+ set(always 1)
1596
+
1597
+ if(arg_SCRIPT_FILE)
1598
+ set(step_script_contents "include(\"${update_script}\")")
1599
+ endif()
1600
+
1601
+ elseif(hg_repository)
1602
+ if(NOT HG_EXECUTABLE)
1603
+ message(FATAL_ERROR "error: could not find hg for pull of ${name}")
1604
+ endif()
1605
+ set(work_dir ${source_dir})
1606
+ set(comment "Performing update step (hg pull) for '${name}'")
1607
+ set(comment_disconnected "Performing disconnected update step for '${name}'")
1608
+
1609
+ set(hg_tag "${_EP_HG_TAG}")
1610
+ if(NOT hg_tag)
1611
+ set(hg_tag "tip")
1612
+ endif()
1613
+
1614
+ if("${HG_VERSION_STRING}" STREQUAL "2.1")
1615
+ set(notesAnchor
1616
+ "#A2.1.1:_revert_pull_return_code_change.2C_compile_issue_on_OS_X"
1617
+ )
1618
+ message(WARNING
1619
+ "Mercurial 2.1 does not distinguish an empty pull from a failed pull:
1620
+ http://mercurial.selenic.com/wiki/UpgradeNotes${notesAnchor}
1621
+ http://thread.gmane.org/gmane.comp.version-control.mercurial.devel/47656
1622
+ Update to Mercurial >= 2.1.1.
1623
+ ")
1624
+ endif()
1625
+
1626
+ set(cmd
1627
+ ${HG_EXECUTABLE} pull
1628
+ COMMAND ${HG_EXECUTABLE} update ${hg_tag}
1629
+ )
1630
+ set(cmd_disconnected ${HG_EXECUTABLE} update ${hg_tag})
1631
+ set(always 1)
1632
+
1633
+ if(arg_SCRIPT_FILE)
1634
+ # These commands are simple, and we know whether updates need to be
1635
+ # disconnected or not for this case, so write them directly instead of
1636
+ # forming them from "cmd" and "cmd_disconnected".
1637
+ if(NOT update_disconnected)
1638
+ string(APPEND step_script_contents
1639
+ "execute_process(\n"
1640
+ " WORKING_DIRECTORY \"${work_dir}\"\n"
1641
+ " COMMAND_ERROR_IS_FATAL LAST\n"
1642
+ " COMMAND \"${HG_EXECUTABLE}\" pull\n"
1643
+ ")"
1644
+ )
1645
+ endif()
1646
+ string(APPEND step_script_contents
1647
+ "execute_process(\n"
1648
+ " WORKING_DIRECTORY \"${work_dir}\"\n"
1649
+ " COMMAND_ERROR_IS_FATAL LAST\n"
1650
+ " COMMAND \"${HG_EXECUTABLE}\" update \"${hg_tag}\"\n"
1651
+ ")"
1652
+ )
1653
+ endif()
1654
+ endif()
1655
+
1656
+ # We use configure_file() to write the update_info_file so that the file's
1657
+ # timestamp is not updated if we don't change the contents
1658
+ if(NOT DEFINED cmd_disconnected)
1659
+ set(cmd_disconnected "${cmd}")
1660
+ endif()
1661
+ set(update_info_file ${stamp_dir}/${name}-update-info.txt)
1662
+ list(APPEND file_deps ${update_info_file})
1663
+ configure_file(
1664
+ "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/UpdateInfo.txt.in"
1665
+ "${update_info_file}"
1666
+ @ONLY
1667
+ )
1668
+
1669
+ if(arg_SCRIPT_FILE)
1670
+ set(step_name update)
1671
+ configure_file(
1672
+ "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/stepscript.cmake.in"
1673
+ "${arg_SCRIPT_FILE}"
1674
+ @ONLY
1675
+ )
1676
+ set(${arg_DEPENDS_VARIABLE} "${file_deps}" PARENT_SCOPE)
1677
+ return()
1678
+ endif()
1679
+
1680
+ # Nothing below this point is applicable when we've been asked to put the
1681
+ # update step in a script file (which is the FetchContent case).
1682
+
1683
+ if(_EP_LOG_UPDATE)
1684
+ set(log LOG 1)
1685
+ else()
1686
+ set(log "")
1687
+ endif()
1688
+
1689
+ if(_EP_USES_TERMINAL_UPDATE)
1690
+ set(uses_terminal USES_TERMINAL 1)
1691
+ else()
1692
+ set(uses_terminal "")
1693
+ endif()
1694
+
1695
+ set(__cmdQuoted)
1696
+ foreach(__item IN LISTS cmd)
1697
+ string(APPEND __cmdQuoted " [==[${__item}]==]")
1698
+ endforeach()
1699
+ cmake_language(EVAL CODE "
1700
+ ExternalProject_Add_Step(${name} update
1701
+ INDEPENDENT TRUE
1702
+ COMMENT \${comment}
1703
+ COMMAND ${__cmdQuoted}
1704
+ ALWAYS \${always}
1705
+ EXCLUDE_FROM_MAIN \${update_disconnected}
1706
+ WORKING_DIRECTORY \${work_dir}
1707
+ DEPENDEES download
1708
+ DEPENDS \${file_deps}
1709
+ ${log}
1710
+ ${uses_terminal}
1711
+ )"
1712
+ )
1713
+ if(update_disconnected)
1714
+ if(NOT DEFINED comment_disconnected)
1715
+ set(comment_disconnected "${comment}")
1716
+ endif()
1717
+ set(__cmdQuoted)
1718
+ foreach(__item IN LISTS cmd_disconnected)
1719
+ string(APPEND __cmdQuoted " [==[${__item}]==]")
1720
+ endforeach()
1721
+
1722
+ cmake_language(EVAL CODE "
1723
+ ExternalProject_Add_Step(${name} update_disconnected
1724
+ INDEPENDENT TRUE
1725
+ COMMENT \${comment_disconnected}
1726
+ COMMAND ${__cmdQuoted}
1727
+ WORKING_DIRECTORY \${work_dir}
1728
+ DEPENDEES download
1729
+ DEPENDS \${file_deps}
1730
+ ${log}
1731
+ ${uses_terminal}
1732
+ )"
1733
+ )
1734
+ endif()
1735
+
1736
+ endfunction()
1737
+
1738
+
1739
+ function(_ep_add_patch_command name)
1740
+ set(noValueOptions )
1741
+ set(singleValueOptions
1742
+ SCRIPT_FILE # These should only be used by FetchContent
1743
+ )
1744
+ set(multiValueOptions )
1745
+ cmake_parse_arguments(PARSE_ARGV 1 arg
1746
+ "${noValueOptions}" "${singleValueOptions}" "${multiValueOptions}"
1747
+ )
1748
+
1749
+ # The various _EP_... variables mentioned here and throughout this function
1750
+ # are expected to already have been set by the caller via a call to
1751
+ # _ep_parse_arguments() or ep_parse_arguments_to_vars(). Other variables
1752
+ # with different names are assigned to for historical reasons only to keep
1753
+ # the code more readable and minimize change.
1754
+
1755
+ set(source_dir "${_EP_SOURCE_DIR}")
1756
+ set(stamp_dir "${_EP_STAMP_DIR}")
1757
+
1758
+ set(cmd "${_EP_PATCH_COMMAND}")
1759
+ set(step_script_contents "")
1760
+
1761
+ set(work_dir)
1762
+ if(DEFINED _EP_PATCH_COMMAND)
1763
+ set(work_dir ${source_dir})
1764
+ if(arg_SCRIPT_FILE)
1765
+ _ep_add_script_commands(
1766
+ step_script_contents
1767
+ "${work_dir}"
1768
+ "${cmd}" # Must be a single quoted argument
1769
+ )
1770
+ endif()
1771
+ endif()
1772
+
1773
+ # We use configure_file() to write the patch_info_file so that the file's
1774
+ # timestamp is not updated if we don't change the contents
1775
+ set(patch_info_file ${stamp_dir}/${name}-patch-info.txt)
1776
+ configure_file(
1777
+ "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/PatchInfo.txt.in"
1778
+ "${patch_info_file}"
1779
+ @ONLY
1780
+ )
1781
+
1782
+ if(arg_SCRIPT_FILE)
1783
+ set(step_name patch)
1784
+ configure_file(
1785
+ "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/stepscript.cmake.in"
1786
+ "${arg_SCRIPT_FILE}"
1787
+ @ONLY
1788
+ )
1789
+ return()
1790
+ endif()
1791
+
1792
+ # Nothing below this point is applicable when we've been asked to put the
1793
+ # patch step in a script file (which is the FetchContent case).
1794
+
1795
+ if(_EP_LOG_PATCH)
1796
+ set(log LOG 1)
1797
+ else()
1798
+ set(log "")
1799
+ endif()
1800
+
1801
+ if(_EP_USES_TERMINAL_PATCH)
1802
+ set(uses_terminal USES_TERMINAL 1)
1803
+ else()
1804
+ set(uses_terminal "")
1805
+ endif()
1806
+
1807
+ _ep_get_update_disconnected(update_disconnected ${name})
1808
+
1809
+ set(__cmdQuoted)
1810
+ foreach(__item IN LISTS cmd)
1811
+ string(APPEND __cmdQuoted " [==[${__item}]==]")
1812
+ endforeach()
1813
+ cmake_language(EVAL CODE "
1814
+ ExternalProject_Add_Step(${name} patch
1815
+ INDEPENDENT TRUE
1816
+ COMMAND ${__cmdQuoted}
1817
+ WORKING_DIRECTORY \${work_dir}
1818
+ EXCLUDE_FROM_MAIN \${update_disconnected}
1819
+ DEPENDEES update
1820
+ DEPENDS \${patch_info_file}
1821
+ ${log}
1822
+ ${uses_terminal}
1823
+ )"
1824
+ )
1825
+
1826
+ if(update_disconnected)
1827
+ cmake_language(EVAL CODE "
1828
+ ExternalProject_Add_Step(${name} patch_disconnected
1829
+ INDEPENDENT TRUE
1830
+ COMMAND ${__cmdQuoted}
1831
+ WORKING_DIRECTORY \${work_dir}
1832
+ DEPENDEES update_disconnected
1833
+ DEPENDS \${patch_info_file}
1834
+ ${log}
1835
+ ${uses_terminal}
1836
+ )"
1837
+ )
1838
+ endif()
1839
+
1840
+ endfunction()
1841
+
1842
+
1843
+ macro(_ep_get_add_keywords out_var)
1844
+ set(${out_var}
1845
+ #
1846
+ # Directory options
1847
+ #
1848
+ PREFIX
1849
+ TMP_DIR
1850
+ STAMP_DIR
1851
+ LOG_DIR
1852
+ DOWNLOAD_DIR
1853
+ SOURCE_DIR
1854
+ BINARY_DIR
1855
+ INSTALL_DIR
1856
+ #
1857
+ # Download step options
1858
+ #
1859
+ DOWNLOAD_COMMAND
1860
+ #
1861
+ URL
1862
+ URL_HASH
1863
+ URL_MD5
1864
+ DOWNLOAD_NAME
1865
+ DOWNLOAD_EXTRACT_TIMESTAMP
1866
+ DOWNLOAD_NO_EXTRACT
1867
+ DOWNLOAD_NO_PROGRESS
1868
+ TIMEOUT
1869
+ INACTIVITY_TIMEOUT
1870
+ HTTP_USERNAME
1871
+ HTTP_PASSWORD
1872
+ HTTP_HEADER
1873
+ TLS_VERSION # Also used for git clone operations
1874
+ TLS_VERIFY # Also used for git clone operations
1875
+ TLS_CAINFO
1876
+ NETRC
1877
+ NETRC_FILE
1878
+ #
1879
+ GIT_REPOSITORY
1880
+ GIT_TAG
1881
+ GIT_REMOTE_NAME
1882
+ GIT_SUBMODULES
1883
+ GIT_SUBMODULES_RECURSE
1884
+ GIT_SHALLOW
1885
+ GIT_PROGRESS
1886
+ GIT_CONFIG
1887
+ GIT_REMOTE_UPDATE_STRATEGY
1888
+ #
1889
+ SVN_REPOSITORY
1890
+ SVN_REVISION
1891
+ SVN_USERNAME
1892
+ SVN_PASSWORD
1893
+ SVN_TRUST_CERT
1894
+ #
1895
+ HG_REPOSITORY
1896
+ HG_TAG
1897
+ #
1898
+ CVS_REPOSITORY
1899
+ CVS_MODULE
1900
+ CVS_TAG
1901
+ #
1902
+ # Update step options
1903
+ #
1904
+ UPDATE_COMMAND
1905
+ UPDATE_DISCONNECTED
1906
+ #
1907
+ # Patch step options
1908
+ #
1909
+ PATCH_COMMAND
1910
+ #
1911
+ # Configure step options
1912
+ #
1913
+ CONFIGURE_COMMAND
1914
+ CMAKE_COMMAND
1915
+ CMAKE_GENERATOR
1916
+ CMAKE_GENERATOR_PLATFORM
1917
+ CMAKE_GENERATOR_TOOLSET
1918
+ CMAKE_GENERATOR_INSTANCE
1919
+ CMAKE_ARGS
1920
+ CMAKE_CACHE_ARGS
1921
+ CMAKE_CACHE_DEFAULT_ARGS
1922
+ SOURCE_SUBDIR
1923
+ CONFIGURE_HANDLED_BY_BUILD
1924
+ #
1925
+ # Build step options
1926
+ #
1927
+ BUILD_COMMAND
1928
+ BUILD_IN_SOURCE
1929
+ BUILD_ALWAYS
1930
+ BUILD_BYPRODUCTS
1931
+ BUILD_JOB_SERVER_AWARE
1932
+ #
1933
+ # Install step options
1934
+ #
1935
+ INSTALL_COMMAND
1936
+ INSTALL_BYPRODUCTS
1937
+ #
1938
+ # Test step options
1939
+ #
1940
+ TEST_COMMAND
1941
+ TEST_BEFORE_INSTALL
1942
+ TEST_AFTER_INSTALL
1943
+ TEST_EXCLUDE_FROM_MAIN
1944
+ #
1945
+ # Logging options
1946
+ #
1947
+ LOG_DOWNLOAD
1948
+ LOG_UPDATE
1949
+ LOG_PATCH
1950
+ LOG_CONFIGURE
1951
+ LOG_BUILD
1952
+ LOG_INSTALL
1953
+ LOG_TEST
1954
+ LOG_MERGED_STDOUTERR
1955
+ LOG_OUTPUT_ON_FAILURE
1956
+ #
1957
+ # Terminal access options
1958
+ #
1959
+ USES_TERMINAL_DOWNLOAD
1960
+ USES_TERMINAL_UPDATE
1961
+ USES_TERMINAL_PATCH
1962
+ USES_TERMINAL_CONFIGURE
1963
+ USES_TERMINAL_BUILD
1964
+ USES_TERMINAL_INSTALL
1965
+ USES_TERMINAL_TEST
1966
+ #
1967
+ # Target options
1968
+ #
1969
+ DEPENDS
1970
+ EXCLUDE_FROM_ALL
1971
+ STEP_TARGETS
1972
+ INDEPENDENT_STEP_TARGETS
1973
+ #
1974
+ # Miscellaneous options
1975
+ #
1976
+ LIST_SEPARATOR
1977
+ #
1978
+ # Internal options (undocumented)
1979
+ #
1980
+ EXTERNALPROJECT_INTERNAL_ARGUMENT_SEPARATOR
1981
+ )
1982
+ endmacro()
wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/ExternalProject/stepscript.cmake.in ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ cmake_minimum_required(VERSION ${CMAKE_VERSION}) # this file comes with cmake
2
+
3
+ message(VERBOSE "Executing @step_name@ step for @name@")
4
+
5
+ block(SCOPE_FOR VARIABLES)
6
+
7
+ @step_script_contents@
8
+
9
+ endblock()
wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/ExternalProject/verify.cmake.in ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2
+ # file Copyright.txt or https://cmake.org/licensing for details.
3
+
4
+ cmake_minimum_required(VERSION ${CMAKE_VERSION}) # this file comes with cmake
5
+
6
+ if("@LOCAL@" STREQUAL "")
7
+ message(FATAL_ERROR "LOCAL can't be empty")
8
+ endif()
9
+
10
+ if(NOT EXISTS "@LOCAL@")
11
+ message(FATAL_ERROR "File not found: @LOCAL@")
12
+ endif()
13
+
14
+ if("@ALGO@" STREQUAL "")
15
+ message(WARNING "File cannot be verified since no URL_HASH specified")
16
+ return()
17
+ endif()
18
+
19
+ if("@EXPECT_VALUE@" STREQUAL "")
20
+ message(FATAL_ERROR "EXPECT_VALUE can't be empty")
21
+ endif()
22
+
23
+ message(VERBOSE "verifying file...
24
+ file='@LOCAL@'")
25
+
26
+ file("@ALGO@" "@LOCAL@" actual_value)
27
+
28
+ if(NOT "${actual_value}" STREQUAL "@EXPECT_VALUE@")
29
+ message(FATAL_ERROR "error: @ALGO@ hash of
30
+ @LOCAL@
31
+ does not match expected value
32
+ expected: '@EXPECT_VALUE@'
33
+ actual: '${actual_value}'
34
+ ")
35
+ endif()
36
+
37
+ message(VERBOSE "verifying file... done")
wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/FetchContent/package-config-version.cmake.in ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ # Automatically generated by CMake's FetchContent module.
2
+ # Do not edit this file, it will be regenerated every time CMake runs.
3
+
4
+ # Version not available, assuming it is compatible. We must also say it is an
5
+ # exact match to ensure find_package() calls with the EXACT keyword still get
6
+ # redirected.
7
+ set(PACKAGE_VERSION_COMPATIBLE TRUE)
8
+ set(PACKAGE_VERSION_EXACT TRUE)
wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/FortranCInterface/Detect.cmake ADDED
@@ -0,0 +1,196 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2
+ # file Copyright.txt or https://cmake.org/licensing for details.
3
+
4
+ configure_file(${FortranCInterface_SOURCE_DIR}/Input.cmake.in
5
+ ${FortranCInterface_BINARY_DIR}/Input.cmake @ONLY)
6
+
7
+ # Detect the Fortran/C interface on the first run or when the
8
+ # configuration changes.
9
+ if(NOT EXISTS ${FortranCInterface_BINARY_DIR}/Output.cmake
10
+ OR NOT EXISTS ${FortranCInterface_BINARY_DIR}/Input.cmake
11
+ OR NOT ${FortranCInterface_BINARY_DIR}/Output.cmake
12
+ IS_NEWER_THAN ${FortranCInterface_BINARY_DIR}/Input.cmake
13
+ OR NOT ${FortranCInterface_BINARY_DIR}/Output.cmake
14
+ IS_NEWER_THAN ${FortranCInterface_SOURCE_DIR}/Output.cmake.in
15
+ OR NOT ${FortranCInterface_BINARY_DIR}/Output.cmake
16
+ IS_NEWER_THAN ${FortranCInterface_SOURCE_DIR}/CMakeLists.txt
17
+ OR NOT ${FortranCInterface_BINARY_DIR}/Output.cmake
18
+ IS_NEWER_THAN ${CMAKE_CURRENT_LIST_FILE}
19
+ )
20
+ message(CHECK_START "Detecting Fortran/C Interface")
21
+ else()
22
+ return()
23
+ endif()
24
+
25
+ # Invalidate verification results.
26
+ unset(FortranCInterface_VERIFIED_C CACHE)
27
+ unset(FortranCInterface_VERIFIED_CXX CACHE)
28
+
29
+ set(_result)
30
+
31
+ # Perform detection with only one architecture so that
32
+ # the info strings are not repeated.
33
+ if(CMAKE_OSX_ARCHITECTURES MATCHES "^([^;]+)(;|$)")
34
+ set(_FortranCInterface_OSX_ARCH "-DCMAKE_OSX_ARCHITECTURES=${CMAKE_MATCH_1}")
35
+ else()
36
+ set(_FortranCInterface_OSX_ARCH "")
37
+ endif()
38
+
39
+ cmake_policy(GET CMP0056 _FortranCInterface_CMP0056)
40
+ if(_FortranCInterface_CMP0056 STREQUAL "NEW")
41
+ set(_FortranCInterface_EXE_LINKER_FLAGS "-DCMAKE_EXE_LINKER_FLAGS:STRING=${CMAKE_EXE_LINKER_FLAGS}")
42
+ else()
43
+ set(_FortranCInterface_EXE_LINKER_FLAGS "")
44
+ endif()
45
+ unset(_FortranCInterface_CMP0056)
46
+
47
+ # Build a sample project which reports symbols.
48
+ set(CMAKE_TRY_COMPILE_CONFIGURATION Release)
49
+ try_compile(FortranCInterface_COMPILED
50
+ PROJECT FortranCInterface
51
+ TARGET FortranCInterface
52
+ SOURCE_DIR ${FortranCInterface_SOURCE_DIR}
53
+ BINARY_DIR ${FortranCInterface_BINARY_DIR}
54
+ LOG_DESCRIPTION "Fortran/C interface test project"
55
+ CMAKE_FLAGS
56
+ "-DCMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS}"
57
+ "-DCMAKE_Fortran_FLAGS:STRING=${CMAKE_Fortran_FLAGS}"
58
+ "-DCMAKE_C_FLAGS_RELEASE:STRING=${CMAKE_C_FLAGS_RELEASE}"
59
+ "-DCMAKE_Fortran_FLAGS_RELEASE:STRING=${CMAKE_Fortran_FLAGS_RELEASE}"
60
+ ${_FortranCInterface_OSX_ARCH}
61
+ ${_FortranCInterface_EXE_LINKER_FLAGS}
62
+ )
63
+ set(FortranCInterface_COMPILED ${FortranCInterface_COMPILED})
64
+ unset(FortranCInterface_COMPILED CACHE)
65
+ unset(_FortranCInterface_EXE_LINKER_FLAGS)
66
+ unset(_FortranCInterface_OSX_ARCH)
67
+
68
+ # Locate the sample project executable.
69
+ set(FortranCInterface_EXE)
70
+ if(FortranCInterface_COMPILED)
71
+ include(${FortranCInterface_BINARY_DIR}/exe-Release.cmake OPTIONAL)
72
+ else()
73
+ set(_result "Failed to compile")
74
+ endif()
75
+
76
+ # Load symbols from INFO:symbol[] strings in the executable.
77
+ set(FortranCInterface_SYMBOLS)
78
+ if(FortranCInterface_EXE)
79
+ cmake_policy(PUSH)
80
+ cmake_policy(SET CMP0159 NEW) # file(STRINGS) with REGEX updates CMAKE_MATCH_<n>
81
+ file(STRINGS "${FortranCInterface_EXE}" _info_strings
82
+ LIMIT_COUNT 8 REGEX "INFO:[A-Za-z0-9_]+\\[[^]]*\\]")
83
+ cmake_policy(POP)
84
+ foreach(info ${_info_strings})
85
+ if("${info}" MATCHES "INFO:symbol\\[([^]]*)\\]")
86
+ list(APPEND FortranCInterface_SYMBOLS ${CMAKE_MATCH_1})
87
+ endif()
88
+ endforeach()
89
+ elseif(NOT _result)
90
+ set(_result "Failed to load sample executable")
91
+ endif()
92
+
93
+ set(_case_mysub "LOWER")
94
+ set(_case_my_sub "LOWER")
95
+ set(_case_MYSUB "UPPER")
96
+ set(_case_MY_SUB "UPPER")
97
+ set(_global_regex "^(_*)(mysub|MYSUB)([_$]*)$")
98
+ set(_global__regex "^(_*)(my_sub|MY_SUB)([_$]*)$")
99
+ set(_module_regex "^([A-Za-z_$]*)(mymodule|MYMODULE)([A-Za-z_$]*)(mysub|MYSUB)([_$]*)$")
100
+ set(_module__regex "^([A-Za-z_$]*)(my_module|MY_MODULE)([A-Za-z_$]*)(my_sub|MY_SUB)([_$]*)$")
101
+
102
+ # Parse the symbol names.
103
+ foreach(symbol ${FortranCInterface_SYMBOLS})
104
+ foreach(form "" "_")
105
+ # Look for global symbols.
106
+ string(REGEX REPLACE "${_global_${form}regex}"
107
+ "\\1;\\2;\\3" pieces "${symbol}")
108
+ list(LENGTH pieces len)
109
+ if(len EQUAL 3)
110
+ set(FortranCInterface_GLOBAL_${form}SYMBOL "${symbol}")
111
+ list(GET pieces 0 FortranCInterface_GLOBAL_${form}PREFIX)
112
+ list(GET pieces 1 name)
113
+ list(GET pieces 2 FortranCInterface_GLOBAL_${form}SUFFIX)
114
+ set(FortranCInterface_GLOBAL_${form}CASE "${_case_${name}}")
115
+ endif()
116
+
117
+ # Look for module symbols.
118
+ string(REGEX REPLACE "${_module_${form}regex}"
119
+ "\\1;\\2;\\3;\\4;\\5" pieces "${symbol}")
120
+ list(LENGTH pieces len)
121
+ if(len EQUAL 5)
122
+ set(FortranCInterface_MODULE_${form}SYMBOL "${symbol}")
123
+ list(GET pieces 0 FortranCInterface_MODULE_${form}PREFIX)
124
+ list(GET pieces 1 module)
125
+ list(GET pieces 2 FortranCInterface_MODULE_${form}MIDDLE)
126
+ list(GET pieces 3 name)
127
+ list(GET pieces 4 FortranCInterface_MODULE_${form}SUFFIX)
128
+ set(FortranCInterface_MODULE_${form}CASE "${_case_${name}}")
129
+ endif()
130
+ endforeach()
131
+ endforeach()
132
+
133
+ # Construct mangling macro definitions.
134
+ set(_name_LOWER "name")
135
+ set(_name_UPPER "NAME")
136
+ foreach(form "" "_")
137
+ if(FortranCInterface_GLOBAL_${form}SYMBOL)
138
+ if(FortranCInterface_GLOBAL_${form}PREFIX)
139
+ set(_prefix "${FortranCInterface_GLOBAL_${form}PREFIX}##")
140
+ else()
141
+ set(_prefix "")
142
+ endif()
143
+ if(FortranCInterface_GLOBAL_${form}SUFFIX)
144
+ set(_suffix "##${FortranCInterface_GLOBAL_${form}SUFFIX}")
145
+ else()
146
+ set(_suffix "")
147
+ endif()
148
+ set(_name "${_name_${FortranCInterface_GLOBAL_${form}CASE}}")
149
+ set(FortranCInterface_GLOBAL${form}_MACRO
150
+ "(name,NAME) ${_prefix}${_name}${_suffix}")
151
+ endif()
152
+ if(FortranCInterface_MODULE_${form}SYMBOL)
153
+ if(FortranCInterface_MODULE_${form}PREFIX)
154
+ set(_prefix "${FortranCInterface_MODULE_${form}PREFIX}##")
155
+ else()
156
+ set(_prefix "")
157
+ endif()
158
+ if(FortranCInterface_MODULE_${form}SUFFIX)
159
+ set(_suffix "##${FortranCInterface_MODULE_${form}SUFFIX}")
160
+ else()
161
+ set(_suffix "")
162
+ endif()
163
+ set(_name "${_name_${FortranCInterface_MODULE_${form}CASE}}")
164
+ set(_middle "##${FortranCInterface_MODULE_${form}MIDDLE}##")
165
+ set(FortranCInterface_MODULE${form}_MACRO
166
+ "(mod_name,name, mod_NAME,NAME) ${_prefix}mod_${_name}${_middle}${_name}${_suffix}")
167
+ endif()
168
+ endforeach()
169
+
170
+ # Summarize what is available.
171
+ foreach(scope GLOBAL MODULE)
172
+ if(FortranCInterface_${scope}_SYMBOL AND
173
+ FortranCInterface_${scope}__SYMBOL)
174
+ set(FortranCInterface_${scope}_FOUND 1)
175
+ else()
176
+ set(FortranCInterface_${scope}_FOUND 0)
177
+ endif()
178
+ endforeach()
179
+
180
+ # Record the detection results.
181
+ configure_file(${FortranCInterface_SOURCE_DIR}/Output.cmake.in
182
+ ${FortranCInterface_BINARY_DIR}/Output.cmake @ONLY)
183
+
184
+ # Report the results.
185
+ if(FortranCInterface_GLOBAL_FOUND)
186
+ if(FortranCInterface_MODULE_FOUND)
187
+ set(_result "Found GLOBAL and MODULE mangling")
188
+ else()
189
+ set(_result "Found GLOBAL but not MODULE mangling")
190
+ endif()
191
+ set(_result_type CHECK_PASS)
192
+ elseif(NOT _result)
193
+ set(_result "Failed to recognize symbols")
194
+ set(_result_type CHECK_FAIL)
195
+ endif()
196
+ message(${_result_type} "${_result}")
wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/FortranCInterface/call_sub.f ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ subroutine call_sub
2
+ call mysub()
3
+ call my_sub()
4
+ end
wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/Platform/Android/Determine-Compiler-NDK.cmake ADDED
@@ -0,0 +1,276 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2
+ # file Copyright.txt or https://cmake.org/licensing for details.
3
+
4
+ # In Android NDK r19 and above there is a single clang toolchain.
5
+ if(CMAKE_ANDROID_NDK_TOOLCHAIN_UNIFIED)
6
+ if(CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION AND NOT CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION STREQUAL "clang")
7
+ message(FATAL_ERROR
8
+ "Android: The CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION value '${CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION}' "
9
+ "is not supported by this NDK. It must be 'clang' or not set at all."
10
+ )
11
+ endif()
12
+ message(STATUS "Android: Selected unified Clang toolchain")
13
+ set(_ANDROID_TOOL_NDK_TOOLCHAIN_VERSION "clang")
14
+ set(_ANDROID_TOOL_C_COMPILER "${CMAKE_ANDROID_NDK_TOOLCHAIN_UNIFIED}/bin/clang${_ANDROID_HOST_EXT}")
15
+ set(_ANDROID_TOOL_C_TOOLCHAIN_MACHINE "${CMAKE_ANDROID_ARCH_TRIPLE}")
16
+ set(_ANDROID_TOOL_C_TOOLCHAIN_VERSION "")
17
+ set(_ANDROID_TOOL_C_COMPILER_EXTERNAL_TOOLCHAIN "")
18
+ set(_ANDROID_TOOL_C_TOOLCHAIN_PREFIX "${CMAKE_ANDROID_NDK_TOOLCHAIN_UNIFIED}/bin/${CMAKE_ANDROID_ARCH_TRIPLE}-")
19
+ set(_ANDROID_TOOL_C_TOOLCHAIN_SUFFIX "${_ANDROID_HOST_EXT}")
20
+ set(_ANDROID_TOOL_CXX_COMPILER "${CMAKE_ANDROID_NDK_TOOLCHAIN_UNIFIED}/bin/clang++${_ANDROID_HOST_EXT}")
21
+ set(_ANDROID_TOOL_CXX_TOOLCHAIN_MACHINE "${CMAKE_ANDROID_ARCH_TRIPLE}")
22
+ set(_ANDROID_TOOL_CXX_TOOLCHAIN_VERSION "")
23
+ set(_ANDROID_TOOL_CXX_COMPILER_EXTERNAL_TOOLCHAIN "")
24
+ set(_ANDROID_TOOL_CXX_TOOLCHAIN_PREFIX "${CMAKE_ANDROID_NDK_TOOLCHAIN_UNIFIED}/bin/${CMAKE_ANDROID_ARCH_TRIPLE}-")
25
+ set(_ANDROID_TOOL_CXX_TOOLCHAIN_SUFFIX "${_ANDROID_HOST_EXT}")
26
+ set(_CMAKE_TOOLCHAIN_PREFIX "${CMAKE_ANDROID_ARCH_TRIPLE}-")
27
+ return()
28
+ endif()
29
+
30
+ # In Android NDK releases there is build system toolchain selection logic in
31
+ # these files:
32
+ #
33
+ # * <ndk>/build/core/init.mk
34
+ # * <ndk>/build/core/setup-toolchain.mk
35
+ # * <ndk>/[build/core/]toolchains/<toolchain>/{config.mk,setup.mk}
36
+ #
37
+ # We parse information out of the ``config.mk`` and ``setup.mk`` files below.
38
+ #
39
+ # There is also a "toolchains" directory with the prebuilt toolchains themselves:
40
+ #
41
+ # * <triple-or-arch>-<gcc-version>/prebuilt/<host>/bin/<triple>-gcc(.exe)?
42
+ # The gcc compiler to be invoked.
43
+ #
44
+ # * llvm*/prebuilt/<host>/bin/clang
45
+ # The clang compiler to be invoked with flags:
46
+ # -target <triple>
47
+ # -gcc-toolchain <ndk>/toolchains/<triple-or-arch>-<gcc-version>
48
+
49
+ cmake_policy(PUSH)
50
+ cmake_policy(SET CMP0159 NEW) # file(STRINGS) with REGEX updates CMAKE_MATCH_<n>
51
+
52
+ # Glob available toolchains in the NDK, restricted by any version request.
53
+ if(CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION STREQUAL "clang")
54
+ set(_ANDROID_TOOL_PATTERNS "*-clang" "*-clang[0-9].[0-9]")
55
+ elseif(CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION)
56
+ if(NOT CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION MATCHES "^(clang)?[0-9]\\.[0-9]$")
57
+ message(FATAL_ERROR
58
+ "Android: The CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION value '${CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION}' "
59
+ "is not one of the allowed forms:\n"
60
+ " <major>.<minor> = GCC of specified version\n"
61
+ " clang<major>.<minor> = Clang of specified version\n"
62
+ " clang = Clang of most recent available version\n"
63
+ )
64
+ endif()
65
+ set(_ANDROID_TOOL_PATTERNS "*-${CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION}")
66
+ else()
67
+ # If we can find any gcc toolchains then use one by default.
68
+ # Otherwise we look for clang toolchains (e.g. NDK r18+).
69
+ file(GLOB _ANDROID_CONFIG_MKS_FOR_GCC
70
+ "${CMAKE_ANDROID_NDK}/build/core/toolchains/*-[0-9].[0-9]/config.mk"
71
+ "${CMAKE_ANDROID_NDK}/toolchains/*-[0-9].[0-9]/config.mk"
72
+ )
73
+ if(_ANDROID_CONFIG_MKS_FOR_GCC)
74
+ set(_ANDROID_TOOL_PATTERNS "*-[0-9].[0-9]")
75
+ else()
76
+ set(_ANDROID_TOOL_PATTERNS "*-clang")
77
+ endif()
78
+ unset(_ANDROID_CONFIG_MKS_FOR_GCC)
79
+ endif()
80
+ set(_ANDROID_CONFIG_MK_PATTERNS)
81
+ foreach(base "build/core/toolchains" "toolchains")
82
+ foreach(pattern IN LISTS _ANDROID_TOOL_PATTERNS)
83
+ list(APPEND _ANDROID_CONFIG_MK_PATTERNS
84
+ "${CMAKE_ANDROID_NDK}/${base}/${pattern}/config.mk"
85
+ )
86
+ endforeach()
87
+ endforeach()
88
+ unset(_ANDROID_TOOL_PATTERNS)
89
+ file(GLOB _ANDROID_CONFIG_MKS ${_ANDROID_CONFIG_MK_PATTERNS})
90
+ unset(_ANDROID_CONFIG_MK_PATTERNS)
91
+
92
+ # Find the newest toolchain version matching the ABI.
93
+ set(_ANDROID_TOOL_NAME "")
94
+ set(_ANDROID_TOOL_VERS 0)
95
+ set(_ANDROID_TOOL_VERS_NDK "")
96
+ set(_ANDROID_TOOL_SETUP_MK "")
97
+ foreach(config_mk IN LISTS _ANDROID_CONFIG_MKS)
98
+ # Check that the toolchain matches the ABI.
99
+ file(STRINGS "${config_mk}" _ANDROID_TOOL_ABIS REGEX "^TOOLCHAIN_ABIS :=.* ${CMAKE_ANDROID_ARCH_ABI}( |$)")
100
+ if(NOT _ANDROID_TOOL_ABIS)
101
+ continue()
102
+ endif()
103
+ unset(_ANDROID_TOOL_ABIS)
104
+
105
+ # Check the version.
106
+ if("${config_mk}" MATCHES [[/([^/]+-((clang)?([0-9]\.[0-9]|)))/config.mk$]])
107
+ set(_ANDROID_CUR_NAME "${CMAKE_MATCH_1}")
108
+ set(_ANDROID_CUR_VERS "${CMAKE_MATCH_4}")
109
+ set(_ANDROID_CUR_VERS_NDK "${CMAKE_MATCH_2}")
110
+ if(_ANDROID_TOOL_VERS STREQUAL "")
111
+ # already the latest possible
112
+ elseif(_ANDROID_CUR_VERS STREQUAL "" OR _ANDROID_CUR_VERS VERSION_GREATER _ANDROID_TOOL_VERS)
113
+ set(_ANDROID_TOOL_NAME "${_ANDROID_CUR_NAME}")
114
+ set(_ANDROID_TOOL_VERS "${_ANDROID_CUR_VERS}")
115
+ set(_ANDROID_TOOL_VERS_NDK "${_ANDROID_CUR_VERS_NDK}")
116
+ string(REPLACE "/config.mk" "/setup.mk" _ANDROID_TOOL_SETUP_MK "${config_mk}")
117
+ endif()
118
+ unset(_ANDROID_CUR_TOOL)
119
+ unset(_ANDROID_CUR_VERS)
120
+ unset(_ANDROID_CUR_VERS_NDK)
121
+ endif()
122
+ endforeach()
123
+
124
+ # Verify that we have a suitable toolchain.
125
+ if(NOT _ANDROID_TOOL_NAME)
126
+ if(_ANDROID_CONFIG_MKS)
127
+ string(REPLACE ";" "\n " _ANDROID_TOOLS_MSG "after considering:;${_ANDROID_CONFIG_MKS}")
128
+ else()
129
+ set(_ANDROID_TOOLS_MSG "")
130
+ endif()
131
+ if(CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION)
132
+ string(CONCAT _ANDROID_TOOLS_MSG
133
+ "of the version specified by CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION:\n"
134
+ " ${CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION}\n"
135
+ "${_ANDROID_TOOLS_MSG}")
136
+ endif()
137
+ message(FATAL_ERROR
138
+ "Android: No toolchain for ABI '${CMAKE_ANDROID_ARCH_ABI}' found in the NDK:\n"
139
+ " ${CMAKE_ANDROID_NDK}\n"
140
+ "${_ANDROID_TOOLS_MSG}"
141
+ )
142
+ endif()
143
+ unset(_ANDROID_CONFIG_MKS)
144
+
145
+ # For clang toolchains we still need to find a gcc toolchain.
146
+ if(_ANDROID_TOOL_NAME MATCHES "-clang")
147
+ set(_ANDROID_TOOL_CLANG_NAME "${_ANDROID_TOOL_NAME}")
148
+ set(_ANDROID_TOOL_CLANG_VERS "${_ANDROID_TOOL_VERS}")
149
+ set(_ANDROID_TOOL_NAME "")
150
+ set(_ANDROID_TOOL_VERS "")
151
+ else()
152
+ set(_ANDROID_TOOL_CLANG_NAME "")
153
+ set(_ANDROID_TOOL_CLANG_VERS "")
154
+ endif()
155
+
156
+ # Parse the toolchain setup.mk file to extract information we need.
157
+ # Their content is not standardized across toolchains or NDK versions,
158
+ # so we match known cases. Note that the parsing is stateful across
159
+ # lines because we need to substitute for some Make variable references.
160
+ if(CMAKE_ANDROID_NDK_TOOLCHAIN_DEBUG)
161
+ message(STATUS "loading: ${_ANDROID_TOOL_SETUP_MK}")
162
+ endif()
163
+ file(STRINGS "${_ANDROID_TOOL_SETUP_MK}" _ANDROID_TOOL_SETUP REGEX "^(LLVM|TOOLCHAIN)_[A-Z_]+ +:= +.*$")
164
+ unset(_ANDROID_TOOL_SETUP_MK)
165
+ set(_ANDROID_TOOL_PREFIX "")
166
+ set(_ANDROID_TOOL_NAME_ONLY "")
167
+ set(_ANDROID_TOOL_LLVM_NAME "llvm")
168
+ set(_ANDROID_TOOL_LLVM_VERS "")
169
+ foreach(line IN LISTS _ANDROID_TOOL_SETUP)
170
+ if(CMAKE_ANDROID_NDK_TOOLCHAIN_DEBUG)
171
+ message(STATUS "setup.mk: ${line}")
172
+ endif()
173
+
174
+ if(line MATCHES [[^TOOLCHAIN_PREFIX +:= +.*/bin/([^$/ ]*) *$]])
175
+ # We just matched the toolchain prefix with no Make variable references.
176
+ set(_ANDROID_TOOL_PREFIX "${CMAKE_MATCH_1}")
177
+ elseif(_ANDROID_TOOL_CLANG_NAME)
178
+ # For clang toolchains we need to find more information.
179
+ if(line MATCHES [[^TOOLCHAIN_VERSION +:= +([0-9.]+) *$]])
180
+ # We just matched the gcc toolchain version number. Save it for later.
181
+ set(_ANDROID_TOOL_VERS "${CMAKE_MATCH_1}")
182
+ elseif(line MATCHES [[^TOOLCHAIN_NAME +:= +(.*\$\(TOOLCHAIN_VERSION\)) *$]])
183
+ # We just matched the gcc toolchain name with a version number placeholder, so substitute it.
184
+ # The gcc toolchain version number will have already been extracted from a TOOLCHAIN_VERSION line.
185
+ string(REPLACE "$(TOOLCHAIN_VERSION)" "${_ANDROID_TOOL_VERS}" _ANDROID_TOOL_NAME "${CMAKE_MATCH_1}")
186
+ elseif(line MATCHES [[^TOOLCHAIN_NAME +:= +([^$/ ]+) *$]])
187
+ # We just matched the gcc toolchain name without version number. Save it for later.
188
+ set(_ANDROID_TOOL_NAME_ONLY "${CMAKE_MATCH_1}")
189
+ elseif(line MATCHES [[^TOOLCHAIN_PREFIX +:= +.*/bin/(\$\(TOOLCHAIN_NAME\)-) *$]])
190
+ # We just matched the toolchain prefix with a name placeholder, so substitute it.
191
+ # The gcc toolchain name will have already been extracted without version number from a TOOLCHAIN_NAME line.
192
+ string(REPLACE "$(TOOLCHAIN_NAME)" "${_ANDROID_TOOL_NAME_ONLY}" _ANDROID_TOOL_PREFIX "${CMAKE_MATCH_1}")
193
+ elseif(line MATCHES [[^LLVM_VERSION +:= +([0-9.]+)$]])
194
+ # We just matched the llvm prebuilt binary toolchain version number. Save it for later.
195
+ set(_ANDROID_TOOL_LLVM_VERS "${CMAKE_MATCH_1}")
196
+ elseif(line MATCHES [[^LLVM_NAME +:= +(llvm-\$\(LLVM_VERSION\)) *$]])
197
+ # We just matched the llvm prebuilt binary toolchain directory name with a version number placeholder,
198
+ # so substitute it. The llvm prebuilt binary toolchain version number will have already been extracted
199
+ # from a LLVM_VERSION line.
200
+ string(REPLACE "$(LLVM_VERSION)" "${_ANDROID_TOOL_LLVM_VERS}" _ANDROID_TOOL_LLVM_NAME "${CMAKE_MATCH_1}")
201
+ elseif(line MATCHES [[^LLVM_TOOLCHAIN_PREBUILT_ROOT +:= +\$\(call get-toolchain-root.*,([^$ ]+)\) *$]])
202
+ # We just matched the llvm prebuilt binary toolchain directory name.
203
+ set(_ANDROID_TOOL_LLVM_NAME "${CMAKE_MATCH_1}")
204
+ elseif(line MATCHES [[^TOOLCHAIN_ROOT +:= +\$\(call get-toolchain-root.*,(\$\(TOOLCHAIN_NAME\)-[0-9.]+)\) *$]])
205
+ # We just matched a placeholder for the name followed by a version number.
206
+ # The gcc toolchain name will have already been extracted without version number from a TOOLCHAIN_NAME line.
207
+ # Substitute for the placeholder to get the full gcc toolchain name.
208
+ string(REPLACE "$(TOOLCHAIN_NAME)" "${_ANDROID_TOOL_NAME_ONLY}" _ANDROID_TOOL_NAME "${CMAKE_MATCH_1}")
209
+ elseif(line MATCHES [[^TOOLCHAIN_ROOT +:= +\$\(call get-toolchain-root.*,([^$ ]+)\) *$]])
210
+ # We just matched the full gcc toolchain name without placeholder.
211
+ set(_ANDROID_TOOL_NAME "${CMAKE_MATCH_1}")
212
+ endif()
213
+ endif()
214
+ endforeach()
215
+ unset(_ANDROID_TOOL_NAME_ONLY)
216
+ unset(_ANDROID_TOOL_LLVM_VERS)
217
+ unset(_ANDROID_TOOL_SETUP)
218
+
219
+ # Fall back to parsing the version and prefix from the tool name.
220
+ if(NOT _ANDROID_TOOL_VERS AND "${_ANDROID_TOOL_NAME}" MATCHES "-([0-9.]+)$")
221
+ set(_ANDROID_TOOL_VERS "${CMAKE_MATCH_1}")
222
+ endif()
223
+ if(NOT _ANDROID_TOOL_PREFIX AND "${_ANDROID_TOOL_NAME}" MATCHES "^(.*-)[0-9.]+$")
224
+ set(_ANDROID_TOOL_PREFIX "${CMAKE_MATCH_1}")
225
+ endif()
226
+
227
+ # Help CMakeFindBinUtils locate things.
228
+ set(_CMAKE_TOOLCHAIN_PREFIX "${_ANDROID_TOOL_PREFIX}")
229
+
230
+ set(_ANDROID_TOOL_NDK_TOOLCHAIN_VERSION "${_ANDROID_TOOL_VERS_NDK}")
231
+
232
+ # _ANDROID_TOOL_PREFIX should now match `gcc -dumpmachine`.
233
+ string(REGEX REPLACE "-$" "" _ANDROID_TOOL_C_TOOLCHAIN_MACHINE "${_ANDROID_TOOL_PREFIX}")
234
+
235
+ set(_ANDROID_TOOL_C_TOOLCHAIN_VERSION "${_ANDROID_TOOL_VERS}")
236
+ set(_ANDROID_TOOL_C_TOOLCHAIN_PREFIX "${CMAKE_ANDROID_NDK}/toolchains/${_ANDROID_TOOL_NAME}/prebuilt/${CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG}/bin/${_ANDROID_TOOL_PREFIX}")
237
+ set(_ANDROID_TOOL_C_TOOLCHAIN_SUFFIX "${_ANDROID_HOST_EXT}")
238
+
239
+ set(_ANDROID_TOOL_CXX_TOOLCHAIN_MACHINE "${_ANDROID_TOOL_C_TOOLCHAIN_MACHINE}")
240
+ set(_ANDROID_TOOL_CXX_TOOLCHAIN_VERSION "${_ANDROID_TOOL_C_TOOLCHAIN_VERSION}")
241
+ set(_ANDROID_TOOL_CXX_TOOLCHAIN_PREFIX "${_ANDROID_TOOL_C_TOOLCHAIN_PREFIX}")
242
+ set(_ANDROID_TOOL_CXX_TOOLCHAIN_SUFFIX "${_ANDROID_TOOL_C_TOOLCHAIN_SUFFIX}")
243
+
244
+ if(_ANDROID_TOOL_CLANG_NAME)
245
+ message(STATUS "Android: Selected Clang toolchain '${_ANDROID_TOOL_CLANG_NAME}' with GCC toolchain '${_ANDROID_TOOL_NAME}'")
246
+ set(_ANDROID_TOOL_C_COMPILER "${CMAKE_ANDROID_NDK}/toolchains/${_ANDROID_TOOL_LLVM_NAME}/prebuilt/${CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG}/bin/clang${_ANDROID_HOST_EXT}")
247
+ set(_ANDROID_TOOL_C_COMPILER_EXTERNAL_TOOLCHAIN ${CMAKE_ANDROID_NDK}/toolchains/${_ANDROID_TOOL_NAME}/prebuilt/${CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG})
248
+ set(_ANDROID_TOOL_CXX_COMPILER "${CMAKE_ANDROID_NDK}/toolchains/${_ANDROID_TOOL_LLVM_NAME}/prebuilt/${CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG}/bin/clang++${_ANDROID_HOST_EXT}")
249
+ set(_ANDROID_TOOL_CXX_COMPILER_EXTERNAL_TOOLCHAIN "${_ANDROID_TOOL_C_COMPILER_EXTERNAL_TOOLCHAIN}")
250
+ else()
251
+ message(STATUS "Android: Selected GCC toolchain '${_ANDROID_TOOL_NAME}'")
252
+ set(_ANDROID_TOOL_C_COMPILER "${_ANDROID_TOOL_C_TOOLCHAIN_PREFIX}gcc${_ANDROID_TOOL_C_TOOLCHAIN_SUFFIX}")
253
+ set(_ANDROID_TOOL_C_COMPILER_EXTERNAL_TOOLCHAIN "")
254
+ set(_ANDROID_TOOL_CXX_COMPILER "${_ANDROID_TOOL_CXX_TOOLCHAIN_PREFIX}g++${_ANDROID_TOOL_CXX_TOOLCHAIN_SUFFIX}")
255
+ set(_ANDROID_TOOL_CXX_COMPILER_EXTERNAL_TOOLCHAIN "")
256
+ endif()
257
+
258
+ if(CMAKE_ANDROID_NDK_TOOLCHAIN_DEBUG)
259
+ message(STATUS "_ANDROID_TOOL_NAME=${_ANDROID_TOOL_NAME}")
260
+ message(STATUS "_ANDROID_TOOL_VERS=${_ANDROID_TOOL_VERS}")
261
+ message(STATUS "_ANDROID_TOOL_VERS_NDK=${_ANDROID_TOOL_VERS_NDK}")
262
+ message(STATUS "_ANDROID_TOOL_PREFIX=${_ANDROID_TOOL_PREFIX}")
263
+ message(STATUS "_ANDROID_TOOL_CLANG_NAME=${_ANDROID_TOOL_CLANG_NAME}")
264
+ message(STATUS "_ANDROID_TOOL_CLANG_VERS=${_ANDROID_TOOL_CLANG_VERS}")
265
+ message(STATUS "_ANDROID_TOOL_LLVM_NAME=${_ANDROID_TOOL_LLVM_NAME}")
266
+ endif()
267
+
268
+ unset(_ANDROID_TOOL_NAME)
269
+ unset(_ANDROID_TOOL_VERS)
270
+ unset(_ANDROID_TOOL_VERS_NDK)
271
+ unset(_ANDROID_TOOL_PREFIX)
272
+ unset(_ANDROID_TOOL_CLANG_NAME)
273
+ unset(_ANDROID_TOOL_CLANG_VERS)
274
+ unset(_ANDROID_TOOL_LLVM_NAME)
275
+
276
+ cmake_policy(POP)
wemm/lib/python3.10/site-packages/cmake/data/share/cmake-3.31/Modules/Platform/Android/VCXProjInspect.vcxproj.in ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
+ <ItemGroup Label="ProjectConfigurations">
4
+ <ProjectConfiguration Include="Debug|@vcx_platform@">
5
+ <Configuration>Debug</Configuration>
6
+ <Platform>@vcx_platform@</Platform>
7
+ </ProjectConfiguration>
8
+ </ItemGroup>
9
+ <PropertyGroup Label="Globals">
10
+ <ProjectGuid>{14D44772-ECF7-47BD-9E29-BC62FAF940A5}</ProjectGuid>
11
+ <RootNamespace>VCXProjInspect</RootNamespace>
12
+ <Keyword>Android</Keyword>
13
+ <ApplicationType>Android</ApplicationType>
14
+ <ApplicationTypeRevision>@vcx_revision@</ApplicationTypeRevision>
15
+ </PropertyGroup>
16
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
17
+ <PropertyGroup>
18
+ </PropertyGroup>
19
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|@vcx_platform@'" Label="Configuration">
20
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
21
+ <CharacterSet>MultiByte</CharacterSet>
22
+ <AndroidAPILevel>android-21</AndroidAPILevel>
23
+ </PropertyGroup>
24
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
25
+ <ImportGroup Label="ExtensionSettings">
26
+ </ImportGroup>
27
+ <PropertyGroup>
28
+ <_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
29
+ <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|@vcx_platform@'">false</LinkIncremental>
30
+ </PropertyGroup>
31
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|@vcx_platform@'">
32
+ <PostBuildEvent>
33
+ <Command>%40echo CMAKE_ANDROID_NDK=$(VS_NdkRoot)</Command>
34
+ </PostBuildEvent>
35
+ </ItemDefinitionGroup>
36
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
37
+ <ImportGroup Label="ExtensionTargets">
38
+ </ImportGroup>
39
+ </Project>