Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- llmeval-env/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_graycode.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_group_constructs.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_homomorphisms.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_perm_groups.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_prufer.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/combinatorics/tests/test_free_groups.py +215 -0
- llmeval-env/lib/python3.10/site-packages/sympy/combinatorics/tests/test_generators.py +105 -0
- llmeval-env/lib/python3.10/site-packages/sympy/combinatorics/tests/test_group_constructs.py +15 -0
- llmeval-env/lib/python3.10/site-packages/sympy/combinatorics/tests/test_pc_groups.py +87 -0
- llmeval-env/lib/python3.10/site-packages/sympy/combinatorics/tests/test_util.py +120 -0
- llmeval-env/lib/python3.10/site-packages/sympy/logic/algorithms/__pycache__/__init__.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/logic/algorithms/__pycache__/dpll.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/logic/algorithms/__pycache__/dpll2.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/logic/algorithms/__pycache__/minisat22_wrapper.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/logic/algorithms/__pycache__/pycosat_wrapper.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/logic/algorithms/pycosat_wrapper.py +41 -0
- llmeval-env/lib/python3.10/site-packages/sympy/series/__init__.py +23 -0
- llmeval-env/lib/python3.10/site-packages/sympy/series/__pycache__/__init__.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/series/__pycache__/acceleration.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/series/__pycache__/approximants.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/series/__pycache__/aseries.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/series/__pycache__/formal.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/series/__pycache__/fourier.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/series/__pycache__/gruntz.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/series/__pycache__/kauers.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/series/__pycache__/limits.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/series/__pycache__/limitseq.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/series/__pycache__/order.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/series/__pycache__/residues.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/series/__pycache__/sequences.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/series/__pycache__/series.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/series/__pycache__/series_class.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/series/approximants.py +103 -0
- llmeval-env/lib/python3.10/site-packages/sympy/series/aseries.py +10 -0
- llmeval-env/lib/python3.10/site-packages/sympy/series/benchmarks/__init__.py +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/series/benchmarks/__pycache__/__init__.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/series/benchmarks/__pycache__/bench_limit.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/series/benchmarks/__pycache__/bench_order.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/series/benchmarks/bench_limit.py +9 -0
- llmeval-env/lib/python3.10/site-packages/sympy/series/benchmarks/bench_order.py +10 -0
- llmeval-env/lib/python3.10/site-packages/sympy/series/kauers.py +51 -0
- llmeval-env/lib/python3.10/site-packages/sympy/series/order.py +517 -0
- llmeval-env/lib/python3.10/site-packages/sympy/series/residues.py +73 -0
- llmeval-env/lib/python3.10/site-packages/sympy/series/tests/__init__.py +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/series/tests/__pycache__/__init__.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/series/tests/__pycache__/test_approximants.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/series/tests/__pycache__/test_aseries.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/series/tests/__pycache__/test_demidovich.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/series/tests/__pycache__/test_formal.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/series/tests/__pycache__/test_fourier.cpython-310.pyc +0 -0
llmeval-env/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_graycode.cpython-310.pyc
ADDED
Binary file (3.41 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_group_constructs.cpython-310.pyc
ADDED
Binary file (731 Bytes). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_homomorphisms.cpython-310.pyc
ADDED
Binary file (3.34 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_perm_groups.cpython-310.pyc
ADDED
Binary file (36.2 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_prufer.cpython-310.pyc
ADDED
Binary file (3.69 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/combinatorics/tests/test_free_groups.py
ADDED
@@ -0,0 +1,215 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from sympy.combinatorics.free_groups import free_group, FreeGroup
|
2 |
+
from sympy.core import Symbol
|
3 |
+
from sympy.testing.pytest import raises
|
4 |
+
from sympy.core.numbers import oo
|
5 |
+
|
6 |
+
F, x, y, z = free_group("x, y, z")
|
7 |
+
|
8 |
+
|
9 |
+
def test_FreeGroup__init__():
|
10 |
+
x, y, z = map(Symbol, "xyz")
|
11 |
+
|
12 |
+
assert len(FreeGroup("x, y, z").generators) == 3
|
13 |
+
assert len(FreeGroup(x).generators) == 1
|
14 |
+
assert len(FreeGroup(("x", "y", "z"))) == 3
|
15 |
+
assert len(FreeGroup((x, y, z)).generators) == 3
|
16 |
+
|
17 |
+
|
18 |
+
def test_free_group():
|
19 |
+
G, a, b, c = free_group("a, b, c")
|
20 |
+
assert F.generators == (x, y, z)
|
21 |
+
assert x*z**2 in F
|
22 |
+
assert x in F
|
23 |
+
assert y*z**-1 in F
|
24 |
+
assert (y*z)**0 in F
|
25 |
+
assert a not in F
|
26 |
+
assert a**0 not in F
|
27 |
+
assert len(F) == 3
|
28 |
+
assert str(F) == '<free group on the generators (x, y, z)>'
|
29 |
+
assert not F == G
|
30 |
+
assert F.order() is oo
|
31 |
+
assert F.is_abelian == False
|
32 |
+
assert F.center() == {F.identity}
|
33 |
+
|
34 |
+
(e,) = free_group("")
|
35 |
+
assert e.order() == 1
|
36 |
+
assert e.generators == ()
|
37 |
+
assert e.elements == {e.identity}
|
38 |
+
assert e.is_abelian == True
|
39 |
+
|
40 |
+
|
41 |
+
def test_FreeGroup__hash__():
|
42 |
+
assert hash(F)
|
43 |
+
|
44 |
+
|
45 |
+
def test_FreeGroup__eq__():
|
46 |
+
assert free_group("x, y, z")[0] == free_group("x, y, z")[0]
|
47 |
+
assert free_group("x, y, z")[0] is free_group("x, y, z")[0]
|
48 |
+
|
49 |
+
assert free_group("x, y, z")[0] != free_group("a, x, y")[0]
|
50 |
+
assert free_group("x, y, z")[0] is not free_group("a, x, y")[0]
|
51 |
+
|
52 |
+
assert free_group("x, y")[0] != free_group("x, y, z")[0]
|
53 |
+
assert free_group("x, y")[0] is not free_group("x, y, z")[0]
|
54 |
+
|
55 |
+
assert free_group("x, y, z")[0] != free_group("x, y")[0]
|
56 |
+
assert free_group("x, y, z")[0] is not free_group("x, y")[0]
|
57 |
+
|
58 |
+
|
59 |
+
def test_FreeGroup__getitem__():
|
60 |
+
assert F[0:] == FreeGroup("x, y, z")
|
61 |
+
assert F[1:] == FreeGroup("y, z")
|
62 |
+
assert F[2:] == FreeGroup("z")
|
63 |
+
|
64 |
+
|
65 |
+
def test_FreeGroupElm__hash__():
|
66 |
+
assert hash(x*y*z)
|
67 |
+
|
68 |
+
|
69 |
+
def test_FreeGroupElm_copy():
|
70 |
+
f = x*y*z**3
|
71 |
+
g = f.copy()
|
72 |
+
h = x*y*z**7
|
73 |
+
|
74 |
+
assert f == g
|
75 |
+
assert f != h
|
76 |
+
|
77 |
+
|
78 |
+
def test_FreeGroupElm_inverse():
|
79 |
+
assert x.inverse() == x**-1
|
80 |
+
assert (x*y).inverse() == y**-1*x**-1
|
81 |
+
assert (y*x*y**-1).inverse() == y*x**-1*y**-1
|
82 |
+
assert (y**2*x**-1).inverse() == x*y**-2
|
83 |
+
|
84 |
+
|
85 |
+
def test_FreeGroupElm_type_error():
|
86 |
+
raises(TypeError, lambda: 2/x)
|
87 |
+
raises(TypeError, lambda: x**2 + y**2)
|
88 |
+
raises(TypeError, lambda: x/2)
|
89 |
+
|
90 |
+
|
91 |
+
def test_FreeGroupElm_methods():
|
92 |
+
assert (x**0).order() == 1
|
93 |
+
assert (y**2).order() is oo
|
94 |
+
assert (x**-1*y).commutator(x) == y**-1*x**-1*y*x
|
95 |
+
assert len(x**2*y**-1) == 3
|
96 |
+
assert len(x**-1*y**3*z) == 5
|
97 |
+
|
98 |
+
|
99 |
+
def test_FreeGroupElm_eliminate_word():
|
100 |
+
w = x**5*y*x**2*y**-4*x
|
101 |
+
assert w.eliminate_word( x, x**2 ) == x**10*y*x**4*y**-4*x**2
|
102 |
+
w3 = x**2*y**3*x**-1*y
|
103 |
+
assert w3.eliminate_word(x, x**2) == x**4*y**3*x**-2*y
|
104 |
+
assert w3.eliminate_word(x, y) == y**5
|
105 |
+
assert w3.eliminate_word(x, y**4) == y**8
|
106 |
+
assert w3.eliminate_word(y, x**-1) == x**-3
|
107 |
+
assert w3.eliminate_word(x, y*z) == y*z*y*z*y**3*z**-1
|
108 |
+
assert (y**-3).eliminate_word(y, x**-1*z**-1) == z*x*z*x*z*x
|
109 |
+
#assert w3.eliminate_word(x, y*x) == y*x*y*x**2*y*x*y*x*y*x*z**3
|
110 |
+
#assert w3.eliminate_word(x, x*y) == x*y*x**2*y*x*y*x*y*x*y*z**3
|
111 |
+
|
112 |
+
|
113 |
+
def test_FreeGroupElm_array_form():
|
114 |
+
assert (x*z).array_form == ((Symbol('x'), 1), (Symbol('z'), 1))
|
115 |
+
assert (x**2*z*y*x**-2).array_form == \
|
116 |
+
((Symbol('x'), 2), (Symbol('z'), 1), (Symbol('y'), 1), (Symbol('x'), -2))
|
117 |
+
assert (x**-2*y**-1).array_form == ((Symbol('x'), -2), (Symbol('y'), -1))
|
118 |
+
|
119 |
+
|
120 |
+
def test_FreeGroupElm_letter_form():
|
121 |
+
assert (x**3).letter_form == (Symbol('x'), Symbol('x'), Symbol('x'))
|
122 |
+
assert (x**2*z**-2*x).letter_form == \
|
123 |
+
(Symbol('x'), Symbol('x'), -Symbol('z'), -Symbol('z'), Symbol('x'))
|
124 |
+
|
125 |
+
|
126 |
+
def test_FreeGroupElm_ext_rep():
|
127 |
+
assert (x**2*z**-2*x).ext_rep == \
|
128 |
+
(Symbol('x'), 2, Symbol('z'), -2, Symbol('x'), 1)
|
129 |
+
assert (x**-2*y**-1).ext_rep == (Symbol('x'), -2, Symbol('y'), -1)
|
130 |
+
assert (x*z).ext_rep == (Symbol('x'), 1, Symbol('z'), 1)
|
131 |
+
|
132 |
+
|
133 |
+
def test_FreeGroupElm__mul__pow__():
|
134 |
+
x1 = x.group.dtype(((Symbol('x'), 1),))
|
135 |
+
assert x**2 == x1*x
|
136 |
+
|
137 |
+
assert (x**2*y*x**-2)**4 == x**2*y**4*x**-2
|
138 |
+
assert (x**2)**2 == x**4
|
139 |
+
assert (x**-1)**-1 == x
|
140 |
+
assert (x**-1)**0 == F.identity
|
141 |
+
assert (y**2)**-2 == y**-4
|
142 |
+
|
143 |
+
assert x**2*x**-1 == x
|
144 |
+
assert x**2*y**2*y**-1 == x**2*y
|
145 |
+
assert x*x**-1 == F.identity
|
146 |
+
|
147 |
+
assert x/x == F.identity
|
148 |
+
assert x/x**2 == x**-1
|
149 |
+
assert (x**2*y)/(x**2*y**-1) == x**2*y**2*x**-2
|
150 |
+
assert (x**2*y)/(y**-1*x**2) == x**2*y*x**-2*y
|
151 |
+
|
152 |
+
assert x*(x**-1*y*z*y**-1) == y*z*y**-1
|
153 |
+
assert x**2*(x**-2*y**-1*z**2*y) == y**-1*z**2*y
|
154 |
+
|
155 |
+
|
156 |
+
def test_FreeGroupElm__len__():
|
157 |
+
assert len(x**5*y*x**2*y**-4*x) == 13
|
158 |
+
assert len(x**17) == 17
|
159 |
+
assert len(y**0) == 0
|
160 |
+
|
161 |
+
|
162 |
+
def test_FreeGroupElm_comparison():
|
163 |
+
assert not (x*y == y*x)
|
164 |
+
assert x**0 == y**0
|
165 |
+
|
166 |
+
assert x**2 < y**3
|
167 |
+
assert not x**3 < y**2
|
168 |
+
assert x*y < x**2*y
|
169 |
+
assert x**2*y**2 < y**4
|
170 |
+
assert not y**4 < y**-4
|
171 |
+
assert not y**4 < x**-4
|
172 |
+
assert y**-2 < y**2
|
173 |
+
|
174 |
+
assert x**2 <= y**2
|
175 |
+
assert x**2 <= x**2
|
176 |
+
|
177 |
+
assert not y*z > z*y
|
178 |
+
assert x > x**-1
|
179 |
+
|
180 |
+
assert not x**2 >= y**2
|
181 |
+
|
182 |
+
|
183 |
+
def test_FreeGroupElm_syllables():
|
184 |
+
w = x**5*y*x**2*y**-4*x
|
185 |
+
assert w.number_syllables() == 5
|
186 |
+
assert w.exponent_syllable(2) == 2
|
187 |
+
assert w.generator_syllable(3) == Symbol('y')
|
188 |
+
assert w.sub_syllables(1, 2) == y
|
189 |
+
assert w.sub_syllables(3, 3) == F.identity
|
190 |
+
|
191 |
+
|
192 |
+
def test_FreeGroup_exponents():
|
193 |
+
w1 = x**2*y**3
|
194 |
+
assert w1.exponent_sum(x) == 2
|
195 |
+
assert w1.exponent_sum(x**-1) == -2
|
196 |
+
assert w1.generator_count(x) == 2
|
197 |
+
|
198 |
+
w2 = x**2*y**4*x**-3
|
199 |
+
assert w2.exponent_sum(x) == -1
|
200 |
+
assert w2.generator_count(x) == 5
|
201 |
+
|
202 |
+
|
203 |
+
def test_FreeGroup_generators():
|
204 |
+
assert (x**2*y**4*z**-1).contains_generators() == {x, y, z}
|
205 |
+
assert (x**-1*y**3).contains_generators() == {x, y}
|
206 |
+
|
207 |
+
|
208 |
+
def test_FreeGroupElm_words():
|
209 |
+
w = x**5*y*x**2*y**-4*x
|
210 |
+
assert w.subword(2, 6) == x**3*y
|
211 |
+
assert w.subword(3, 2) == F.identity
|
212 |
+
assert w.subword(6, 10) == x**2*y**-2
|
213 |
+
|
214 |
+
assert w.substituted_word(0, 7, y**-1) == y**-1*x*y**-4*x
|
215 |
+
assert w.substituted_word(0, 7, y**2*x) == y**2*x**2*y**-4*x
|
llmeval-env/lib/python3.10/site-packages/sympy/combinatorics/tests/test_generators.py
ADDED
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from sympy.combinatorics.generators import symmetric, cyclic, alternating, \
|
2 |
+
dihedral, rubik
|
3 |
+
from sympy.combinatorics.permutations import Permutation
|
4 |
+
from sympy.testing.pytest import raises
|
5 |
+
|
6 |
+
def test_generators():
|
7 |
+
|
8 |
+
assert list(cyclic(6)) == [
|
9 |
+
Permutation([0, 1, 2, 3, 4, 5]),
|
10 |
+
Permutation([1, 2, 3, 4, 5, 0]),
|
11 |
+
Permutation([2, 3, 4, 5, 0, 1]),
|
12 |
+
Permutation([3, 4, 5, 0, 1, 2]),
|
13 |
+
Permutation([4, 5, 0, 1, 2, 3]),
|
14 |
+
Permutation([5, 0, 1, 2, 3, 4])]
|
15 |
+
|
16 |
+
assert list(cyclic(10)) == [
|
17 |
+
Permutation([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]),
|
18 |
+
Permutation([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]),
|
19 |
+
Permutation([2, 3, 4, 5, 6, 7, 8, 9, 0, 1]),
|
20 |
+
Permutation([3, 4, 5, 6, 7, 8, 9, 0, 1, 2]),
|
21 |
+
Permutation([4, 5, 6, 7, 8, 9, 0, 1, 2, 3]),
|
22 |
+
Permutation([5, 6, 7, 8, 9, 0, 1, 2, 3, 4]),
|
23 |
+
Permutation([6, 7, 8, 9, 0, 1, 2, 3, 4, 5]),
|
24 |
+
Permutation([7, 8, 9, 0, 1, 2, 3, 4, 5, 6]),
|
25 |
+
Permutation([8, 9, 0, 1, 2, 3, 4, 5, 6, 7]),
|
26 |
+
Permutation([9, 0, 1, 2, 3, 4, 5, 6, 7, 8])]
|
27 |
+
|
28 |
+
assert list(alternating(4)) == [
|
29 |
+
Permutation([0, 1, 2, 3]),
|
30 |
+
Permutation([0, 2, 3, 1]),
|
31 |
+
Permutation([0, 3, 1, 2]),
|
32 |
+
Permutation([1, 0, 3, 2]),
|
33 |
+
Permutation([1, 2, 0, 3]),
|
34 |
+
Permutation([1, 3, 2, 0]),
|
35 |
+
Permutation([2, 0, 1, 3]),
|
36 |
+
Permutation([2, 1, 3, 0]),
|
37 |
+
Permutation([2, 3, 0, 1]),
|
38 |
+
Permutation([3, 0, 2, 1]),
|
39 |
+
Permutation([3, 1, 0, 2]),
|
40 |
+
Permutation([3, 2, 1, 0])]
|
41 |
+
|
42 |
+
assert list(symmetric(3)) == [
|
43 |
+
Permutation([0, 1, 2]),
|
44 |
+
Permutation([0, 2, 1]),
|
45 |
+
Permutation([1, 0, 2]),
|
46 |
+
Permutation([1, 2, 0]),
|
47 |
+
Permutation([2, 0, 1]),
|
48 |
+
Permutation([2, 1, 0])]
|
49 |
+
|
50 |
+
assert list(symmetric(4)) == [
|
51 |
+
Permutation([0, 1, 2, 3]),
|
52 |
+
Permutation([0, 1, 3, 2]),
|
53 |
+
Permutation([0, 2, 1, 3]),
|
54 |
+
Permutation([0, 2, 3, 1]),
|
55 |
+
Permutation([0, 3, 1, 2]),
|
56 |
+
Permutation([0, 3, 2, 1]),
|
57 |
+
Permutation([1, 0, 2, 3]),
|
58 |
+
Permutation([1, 0, 3, 2]),
|
59 |
+
Permutation([1, 2, 0, 3]),
|
60 |
+
Permutation([1, 2, 3, 0]),
|
61 |
+
Permutation([1, 3, 0, 2]),
|
62 |
+
Permutation([1, 3, 2, 0]),
|
63 |
+
Permutation([2, 0, 1, 3]),
|
64 |
+
Permutation([2, 0, 3, 1]),
|
65 |
+
Permutation([2, 1, 0, 3]),
|
66 |
+
Permutation([2, 1, 3, 0]),
|
67 |
+
Permutation([2, 3, 0, 1]),
|
68 |
+
Permutation([2, 3, 1, 0]),
|
69 |
+
Permutation([3, 0, 1, 2]),
|
70 |
+
Permutation([3, 0, 2, 1]),
|
71 |
+
Permutation([3, 1, 0, 2]),
|
72 |
+
Permutation([3, 1, 2, 0]),
|
73 |
+
Permutation([3, 2, 0, 1]),
|
74 |
+
Permutation([3, 2, 1, 0])]
|
75 |
+
|
76 |
+
assert list(dihedral(1)) == [
|
77 |
+
Permutation([0, 1]), Permutation([1, 0])]
|
78 |
+
|
79 |
+
assert list(dihedral(2)) == [
|
80 |
+
Permutation([0, 1, 2, 3]),
|
81 |
+
Permutation([1, 0, 3, 2]),
|
82 |
+
Permutation([2, 3, 0, 1]),
|
83 |
+
Permutation([3, 2, 1, 0])]
|
84 |
+
|
85 |
+
assert list(dihedral(3)) == [
|
86 |
+
Permutation([0, 1, 2]),
|
87 |
+
Permutation([2, 1, 0]),
|
88 |
+
Permutation([1, 2, 0]),
|
89 |
+
Permutation([0, 2, 1]),
|
90 |
+
Permutation([2, 0, 1]),
|
91 |
+
Permutation([1, 0, 2])]
|
92 |
+
|
93 |
+
assert list(dihedral(5)) == [
|
94 |
+
Permutation([0, 1, 2, 3, 4]),
|
95 |
+
Permutation([4, 3, 2, 1, 0]),
|
96 |
+
Permutation([1, 2, 3, 4, 0]),
|
97 |
+
Permutation([0, 4, 3, 2, 1]),
|
98 |
+
Permutation([2, 3, 4, 0, 1]),
|
99 |
+
Permutation([1, 0, 4, 3, 2]),
|
100 |
+
Permutation([3, 4, 0, 1, 2]),
|
101 |
+
Permutation([2, 1, 0, 4, 3]),
|
102 |
+
Permutation([4, 0, 1, 2, 3]),
|
103 |
+
Permutation([3, 2, 1, 0, 4])]
|
104 |
+
|
105 |
+
raises(ValueError, lambda: rubik(1))
|
llmeval-env/lib/python3.10/site-packages/sympy/combinatorics/tests/test_group_constructs.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from sympy.combinatorics.group_constructs import DirectProduct
|
2 |
+
from sympy.combinatorics.named_groups import CyclicGroup, DihedralGroup
|
3 |
+
|
4 |
+
|
5 |
+
def test_direct_product_n():
|
6 |
+
C = CyclicGroup(4)
|
7 |
+
D = DihedralGroup(4)
|
8 |
+
G = DirectProduct(C, C, C)
|
9 |
+
assert G.order() == 64
|
10 |
+
assert G.degree == 12
|
11 |
+
assert len(G.orbits()) == 3
|
12 |
+
assert G.is_abelian is True
|
13 |
+
H = DirectProduct(D, C)
|
14 |
+
assert H.order() == 32
|
15 |
+
assert H.is_abelian is False
|
llmeval-env/lib/python3.10/site-packages/sympy/combinatorics/tests/test_pc_groups.py
ADDED
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from sympy.combinatorics.permutations import Permutation
|
2 |
+
from sympy.combinatorics.named_groups import SymmetricGroup, AlternatingGroup, DihedralGroup
|
3 |
+
from sympy.matrices import Matrix
|
4 |
+
|
5 |
+
def test_pc_presentation():
|
6 |
+
Groups = [SymmetricGroup(3), SymmetricGroup(4), SymmetricGroup(9).sylow_subgroup(3),
|
7 |
+
SymmetricGroup(9).sylow_subgroup(2), SymmetricGroup(8).sylow_subgroup(2), DihedralGroup(10)]
|
8 |
+
|
9 |
+
S = SymmetricGroup(125).sylow_subgroup(5)
|
10 |
+
G = S.derived_series()[2]
|
11 |
+
Groups.append(G)
|
12 |
+
|
13 |
+
G = SymmetricGroup(25).sylow_subgroup(5)
|
14 |
+
Groups.append(G)
|
15 |
+
|
16 |
+
S = SymmetricGroup(11**2).sylow_subgroup(11)
|
17 |
+
G = S.derived_series()[2]
|
18 |
+
Groups.append(G)
|
19 |
+
|
20 |
+
for G in Groups:
|
21 |
+
PcGroup = G.polycyclic_group()
|
22 |
+
collector = PcGroup.collector
|
23 |
+
pc_presentation = collector.pc_presentation
|
24 |
+
|
25 |
+
pcgs = PcGroup.pcgs
|
26 |
+
free_group = collector.free_group
|
27 |
+
free_to_perm = {}
|
28 |
+
for s, g in zip(free_group.symbols, pcgs):
|
29 |
+
free_to_perm[s] = g
|
30 |
+
|
31 |
+
for k, v in pc_presentation.items():
|
32 |
+
k_array = k.array_form
|
33 |
+
if v != ():
|
34 |
+
v_array = v.array_form
|
35 |
+
|
36 |
+
lhs = Permutation()
|
37 |
+
for gen in k_array:
|
38 |
+
s = gen[0]
|
39 |
+
e = gen[1]
|
40 |
+
lhs = lhs*free_to_perm[s]**e
|
41 |
+
|
42 |
+
if v == ():
|
43 |
+
assert lhs.is_identity
|
44 |
+
continue
|
45 |
+
|
46 |
+
rhs = Permutation()
|
47 |
+
for gen in v_array:
|
48 |
+
s = gen[0]
|
49 |
+
e = gen[1]
|
50 |
+
rhs = rhs*free_to_perm[s]**e
|
51 |
+
|
52 |
+
assert lhs == rhs
|
53 |
+
|
54 |
+
|
55 |
+
def test_exponent_vector():
|
56 |
+
|
57 |
+
Groups = [SymmetricGroup(3), SymmetricGroup(4), SymmetricGroup(9).sylow_subgroup(3),
|
58 |
+
SymmetricGroup(9).sylow_subgroup(2), SymmetricGroup(8).sylow_subgroup(2)]
|
59 |
+
|
60 |
+
for G in Groups:
|
61 |
+
PcGroup = G.polycyclic_group()
|
62 |
+
collector = PcGroup.collector
|
63 |
+
|
64 |
+
pcgs = PcGroup.pcgs
|
65 |
+
# free_group = collector.free_group
|
66 |
+
|
67 |
+
for gen in G.generators:
|
68 |
+
exp = collector.exponent_vector(gen)
|
69 |
+
g = Permutation()
|
70 |
+
for i in range(len(exp)):
|
71 |
+
g = g*pcgs[i]**exp[i] if exp[i] else g
|
72 |
+
assert g == gen
|
73 |
+
|
74 |
+
|
75 |
+
def test_induced_pcgs():
|
76 |
+
G = [SymmetricGroup(9).sylow_subgroup(3), SymmetricGroup(20).sylow_subgroup(2), AlternatingGroup(4),
|
77 |
+
DihedralGroup(4), DihedralGroup(10), DihedralGroup(9), SymmetricGroup(3), SymmetricGroup(4)]
|
78 |
+
|
79 |
+
for g in G:
|
80 |
+
PcGroup = g.polycyclic_group()
|
81 |
+
collector = PcGroup.collector
|
82 |
+
gens = list(g.generators)
|
83 |
+
ipcgs = collector.induced_pcgs(gens)
|
84 |
+
m = []
|
85 |
+
for i in ipcgs:
|
86 |
+
m.append(collector.exponent_vector(i))
|
87 |
+
assert Matrix(m).is_upper
|
llmeval-env/lib/python3.10/site-packages/sympy/combinatorics/tests/test_util.py
ADDED
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from sympy.combinatorics.named_groups import SymmetricGroup, DihedralGroup,\
|
2 |
+
AlternatingGroup
|
3 |
+
from sympy.combinatorics.permutations import Permutation
|
4 |
+
from sympy.combinatorics.util import _check_cycles_alt_sym, _strip,\
|
5 |
+
_distribute_gens_by_base, _strong_gens_from_distr,\
|
6 |
+
_orbits_transversals_from_bsgs, _handle_precomputed_bsgs, _base_ordering,\
|
7 |
+
_remove_gens
|
8 |
+
from sympy.combinatorics.testutil import _verify_bsgs
|
9 |
+
|
10 |
+
|
11 |
+
def test_check_cycles_alt_sym():
|
12 |
+
perm1 = Permutation([[0, 1, 2, 3, 4, 5, 6], [7], [8], [9]])
|
13 |
+
perm2 = Permutation([[0, 1, 2, 3, 4, 5], [6, 7, 8, 9]])
|
14 |
+
perm3 = Permutation([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
|
15 |
+
assert _check_cycles_alt_sym(perm1) is True
|
16 |
+
assert _check_cycles_alt_sym(perm2) is False
|
17 |
+
assert _check_cycles_alt_sym(perm3) is False
|
18 |
+
|
19 |
+
|
20 |
+
def test_strip():
|
21 |
+
D = DihedralGroup(5)
|
22 |
+
D.schreier_sims()
|
23 |
+
member = Permutation([4, 0, 1, 2, 3])
|
24 |
+
not_member1 = Permutation([0, 1, 4, 3, 2])
|
25 |
+
not_member2 = Permutation([3, 1, 4, 2, 0])
|
26 |
+
identity = Permutation([0, 1, 2, 3, 4])
|
27 |
+
res1 = _strip(member, D.base, D.basic_orbits, D.basic_transversals)
|
28 |
+
res2 = _strip(not_member1, D.base, D.basic_orbits, D.basic_transversals)
|
29 |
+
res3 = _strip(not_member2, D.base, D.basic_orbits, D.basic_transversals)
|
30 |
+
assert res1[0] == identity
|
31 |
+
assert res1[1] == len(D.base) + 1
|
32 |
+
assert res2[0] == not_member1
|
33 |
+
assert res2[1] == len(D.base) + 1
|
34 |
+
assert res3[0] != identity
|
35 |
+
assert res3[1] == 2
|
36 |
+
|
37 |
+
|
38 |
+
def test_distribute_gens_by_base():
|
39 |
+
base = [0, 1, 2]
|
40 |
+
gens = [Permutation([0, 1, 2, 3]), Permutation([0, 1, 3, 2]),
|
41 |
+
Permutation([0, 2, 3, 1]), Permutation([3, 2, 1, 0])]
|
42 |
+
assert _distribute_gens_by_base(base, gens) == [gens,
|
43 |
+
[Permutation([0, 1, 2, 3]),
|
44 |
+
Permutation([0, 1, 3, 2]),
|
45 |
+
Permutation([0, 2, 3, 1])],
|
46 |
+
[Permutation([0, 1, 2, 3]),
|
47 |
+
Permutation([0, 1, 3, 2])]]
|
48 |
+
|
49 |
+
|
50 |
+
def test_strong_gens_from_distr():
|
51 |
+
strong_gens_distr = [[Permutation([0, 2, 1]), Permutation([1, 2, 0]),
|
52 |
+
Permutation([1, 0, 2])], [Permutation([0, 2, 1])]]
|
53 |
+
assert _strong_gens_from_distr(strong_gens_distr) == \
|
54 |
+
[Permutation([0, 2, 1]),
|
55 |
+
Permutation([1, 2, 0]),
|
56 |
+
Permutation([1, 0, 2])]
|
57 |
+
|
58 |
+
|
59 |
+
def test_orbits_transversals_from_bsgs():
|
60 |
+
S = SymmetricGroup(4)
|
61 |
+
S.schreier_sims()
|
62 |
+
base = S.base
|
63 |
+
strong_gens = S.strong_gens
|
64 |
+
strong_gens_distr = _distribute_gens_by_base(base, strong_gens)
|
65 |
+
result = _orbits_transversals_from_bsgs(base, strong_gens_distr)
|
66 |
+
orbits = result[0]
|
67 |
+
transversals = result[1]
|
68 |
+
base_len = len(base)
|
69 |
+
for i in range(base_len):
|
70 |
+
for el in orbits[i]:
|
71 |
+
assert transversals[i][el](base[i]) == el
|
72 |
+
for j in range(i):
|
73 |
+
assert transversals[i][el](base[j]) == base[j]
|
74 |
+
order = 1
|
75 |
+
for i in range(base_len):
|
76 |
+
order *= len(orbits[i])
|
77 |
+
assert S.order() == order
|
78 |
+
|
79 |
+
|
80 |
+
def test_handle_precomputed_bsgs():
|
81 |
+
A = AlternatingGroup(5)
|
82 |
+
A.schreier_sims()
|
83 |
+
base = A.base
|
84 |
+
strong_gens = A.strong_gens
|
85 |
+
result = _handle_precomputed_bsgs(base, strong_gens)
|
86 |
+
strong_gens_distr = _distribute_gens_by_base(base, strong_gens)
|
87 |
+
assert strong_gens_distr == result[2]
|
88 |
+
transversals = result[0]
|
89 |
+
orbits = result[1]
|
90 |
+
base_len = len(base)
|
91 |
+
for i in range(base_len):
|
92 |
+
for el in orbits[i]:
|
93 |
+
assert transversals[i][el](base[i]) == el
|
94 |
+
for j in range(i):
|
95 |
+
assert transversals[i][el](base[j]) == base[j]
|
96 |
+
order = 1
|
97 |
+
for i in range(base_len):
|
98 |
+
order *= len(orbits[i])
|
99 |
+
assert A.order() == order
|
100 |
+
|
101 |
+
|
102 |
+
def test_base_ordering():
|
103 |
+
base = [2, 4, 5]
|
104 |
+
degree = 7
|
105 |
+
assert _base_ordering(base, degree) == [3, 4, 0, 5, 1, 2, 6]
|
106 |
+
|
107 |
+
|
108 |
+
def test_remove_gens():
|
109 |
+
S = SymmetricGroup(10)
|
110 |
+
base, strong_gens = S.schreier_sims_incremental()
|
111 |
+
new_gens = _remove_gens(base, strong_gens)
|
112 |
+
assert _verify_bsgs(S, base, new_gens) is True
|
113 |
+
A = AlternatingGroup(7)
|
114 |
+
base, strong_gens = A.schreier_sims_incremental()
|
115 |
+
new_gens = _remove_gens(base, strong_gens)
|
116 |
+
assert _verify_bsgs(A, base, new_gens) is True
|
117 |
+
D = DihedralGroup(2)
|
118 |
+
base, strong_gens = D.schreier_sims_incremental()
|
119 |
+
new_gens = _remove_gens(base, strong_gens)
|
120 |
+
assert _verify_bsgs(D, base, new_gens) is True
|
llmeval-env/lib/python3.10/site-packages/sympy/logic/algorithms/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (195 Bytes). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/logic/algorithms/__pycache__/dpll.cpython-310.pyc
ADDED
Binary file (8.03 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/logic/algorithms/__pycache__/dpll2.cpython-310.pyc
ADDED
Binary file (17.6 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/logic/algorithms/__pycache__/minisat22_wrapper.cpython-310.pyc
ADDED
Binary file (1.95 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/logic/algorithms/__pycache__/pycosat_wrapper.cpython-310.pyc
ADDED
Binary file (1.42 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/logic/algorithms/pycosat_wrapper.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from sympy.assumptions.cnf import EncodedCNF
|
2 |
+
|
3 |
+
|
4 |
+
def pycosat_satisfiable(expr, all_models=False):
|
5 |
+
import pycosat
|
6 |
+
if not isinstance(expr, EncodedCNF):
|
7 |
+
exprs = EncodedCNF()
|
8 |
+
exprs.add_prop(expr)
|
9 |
+
expr = exprs
|
10 |
+
|
11 |
+
# Return UNSAT when False (encoded as 0) is present in the CNF
|
12 |
+
if {0} in expr.data:
|
13 |
+
if all_models:
|
14 |
+
return (f for f in [False])
|
15 |
+
return False
|
16 |
+
|
17 |
+
if not all_models:
|
18 |
+
r = pycosat.solve(expr.data)
|
19 |
+
result = (r != "UNSAT")
|
20 |
+
if not result:
|
21 |
+
return result
|
22 |
+
return {expr.symbols[abs(lit) - 1]: lit > 0 for lit in r}
|
23 |
+
else:
|
24 |
+
r = pycosat.itersolve(expr.data)
|
25 |
+
result = (r != "UNSAT")
|
26 |
+
if not result:
|
27 |
+
return result
|
28 |
+
|
29 |
+
# Make solutions SymPy compatible by creating a generator
|
30 |
+
def _gen(results):
|
31 |
+
satisfiable = False
|
32 |
+
try:
|
33 |
+
while True:
|
34 |
+
sol = next(results)
|
35 |
+
yield {expr.symbols[abs(lit) - 1]: lit > 0 for lit in sol}
|
36 |
+
satisfiable = True
|
37 |
+
except StopIteration:
|
38 |
+
if not satisfiable:
|
39 |
+
yield False
|
40 |
+
|
41 |
+
return _gen(r)
|
llmeval-env/lib/python3.10/site-packages/sympy/series/__init__.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""A module that handles series: find a limit, order the series etc.
|
2 |
+
"""
|
3 |
+
from .order import Order
|
4 |
+
from .limits import limit, Limit
|
5 |
+
from .gruntz import gruntz
|
6 |
+
from .series import series
|
7 |
+
from .approximants import approximants
|
8 |
+
from .residues import residue
|
9 |
+
from .sequences import SeqPer, SeqFormula, sequence, SeqAdd, SeqMul
|
10 |
+
from .fourier import fourier_series
|
11 |
+
from .formal import fps
|
12 |
+
from .limitseq import difference_delta, limit_seq
|
13 |
+
|
14 |
+
from sympy.core.singleton import S
|
15 |
+
EmptySequence = S.EmptySequence
|
16 |
+
|
17 |
+
O = Order
|
18 |
+
|
19 |
+
__all__ = ['Order', 'O', 'limit', 'Limit', 'gruntz', 'series', 'approximants',
|
20 |
+
'residue', 'EmptySequence', 'SeqPer', 'SeqFormula', 'sequence',
|
21 |
+
'SeqAdd', 'SeqMul', 'fourier_series', 'fps', 'difference_delta',
|
22 |
+
'limit_seq'
|
23 |
+
]
|
llmeval-env/lib/python3.10/site-packages/sympy/series/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (945 Bytes). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/series/__pycache__/acceleration.cpython-310.pyc
ADDED
Binary file (3.83 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/series/__pycache__/approximants.cpython-310.pyc
ADDED
Binary file (3.43 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/series/__pycache__/aseries.cpython-310.pyc
ADDED
Binary file (493 Bytes). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/series/__pycache__/formal.cpython-310.pyc
ADDED
Binary file (51.5 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/series/__pycache__/fourier.cpython-310.pyc
ADDED
Binary file (24.2 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/series/__pycache__/gruntz.cpython-310.pyc
ADDED
Binary file (21.4 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/series/__pycache__/kauers.cpython-310.pyc
ADDED
Binary file (1.92 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/series/__pycache__/limits.cpython-310.pyc
ADDED
Binary file (9.3 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/series/__pycache__/limitseq.cpython-310.pyc
ADDED
Binary file (7.26 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/series/__pycache__/order.cpython-310.pyc
ADDED
Binary file (15.7 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/series/__pycache__/residues.cpython-310.pyc
ADDED
Binary file (1.75 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/series/__pycache__/sequences.cpython-310.pyc
ADDED
Binary file (35.2 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/series/__pycache__/series.cpython-310.pyc
ADDED
Binary file (2.11 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/series/__pycache__/series_class.cpython-310.pyc
ADDED
Binary file (3.73 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/series/approximants.py
ADDED
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from sympy.core.singleton import S
|
2 |
+
from sympy.core.symbol import Symbol
|
3 |
+
from sympy.polys.polytools import lcm
|
4 |
+
from sympy.utilities import public
|
5 |
+
|
6 |
+
@public
|
7 |
+
def approximants(l, X=Symbol('x'), simplify=False):
|
8 |
+
"""
|
9 |
+
Return a generator for consecutive Pade approximants for a series.
|
10 |
+
It can also be used for computing the rational generating function of a
|
11 |
+
series when possible, since the last approximant returned by the generator
|
12 |
+
will be the generating function (if any).
|
13 |
+
|
14 |
+
Explanation
|
15 |
+
===========
|
16 |
+
|
17 |
+
The input list can contain more complex expressions than integer or rational
|
18 |
+
numbers; symbols may also be involved in the computation. An example below
|
19 |
+
show how to compute the generating function of the whole Pascal triangle.
|
20 |
+
|
21 |
+
The generator can be asked to apply the sympy.simplify function on each
|
22 |
+
generated term, which will make the computation slower; however it may be
|
23 |
+
useful when symbols are involved in the expressions.
|
24 |
+
|
25 |
+
Examples
|
26 |
+
========
|
27 |
+
|
28 |
+
>>> from sympy.series import approximants
|
29 |
+
>>> from sympy import lucas, fibonacci, symbols, binomial
|
30 |
+
>>> g = [lucas(k) for k in range(16)]
|
31 |
+
>>> [e for e in approximants(g)]
|
32 |
+
[2, -4/(x - 2), (5*x - 2)/(3*x - 1), (x - 2)/(x**2 + x - 1)]
|
33 |
+
|
34 |
+
>>> h = [fibonacci(k) for k in range(16)]
|
35 |
+
>>> [e for e in approximants(h)]
|
36 |
+
[x, -x/(x - 1), (x**2 - x)/(2*x - 1), -x/(x**2 + x - 1)]
|
37 |
+
|
38 |
+
>>> x, t = symbols("x,t")
|
39 |
+
>>> p=[sum(binomial(k,i)*x**i for i in range(k+1)) for k in range(16)]
|
40 |
+
>>> y = approximants(p, t)
|
41 |
+
>>> for k in range(3): print(next(y))
|
42 |
+
1
|
43 |
+
(x + 1)/((-x - 1)*(t*(x + 1) + (x + 1)/(-x - 1)))
|
44 |
+
nan
|
45 |
+
|
46 |
+
>>> y = approximants(p, t, simplify=True)
|
47 |
+
>>> for k in range(3): print(next(y))
|
48 |
+
1
|
49 |
+
-1/(t*(x + 1) - 1)
|
50 |
+
nan
|
51 |
+
|
52 |
+
See Also
|
53 |
+
========
|
54 |
+
|
55 |
+
sympy.concrete.guess.guess_generating_function_rational
|
56 |
+
mpmath.pade
|
57 |
+
"""
|
58 |
+
from sympy.simplify import simplify as simp
|
59 |
+
from sympy.simplify.radsimp import denom
|
60 |
+
p1, q1 = [S.One], [S.Zero]
|
61 |
+
p2, q2 = [S.Zero], [S.One]
|
62 |
+
while len(l):
|
63 |
+
b = 0
|
64 |
+
while l[b]==0:
|
65 |
+
b += 1
|
66 |
+
if b == len(l):
|
67 |
+
return
|
68 |
+
m = [S.One/l[b]]
|
69 |
+
for k in range(b+1, len(l)):
|
70 |
+
s = 0
|
71 |
+
for j in range(b, k):
|
72 |
+
s -= l[j+1] * m[b-j-1]
|
73 |
+
m.append(s/l[b])
|
74 |
+
l = m
|
75 |
+
a, l[0] = l[0], 0
|
76 |
+
p = [0] * max(len(p2), b+len(p1))
|
77 |
+
q = [0] * max(len(q2), b+len(q1))
|
78 |
+
for k in range(len(p2)):
|
79 |
+
p[k] = a*p2[k]
|
80 |
+
for k in range(b, b+len(p1)):
|
81 |
+
p[k] += p1[k-b]
|
82 |
+
for k in range(len(q2)):
|
83 |
+
q[k] = a*q2[k]
|
84 |
+
for k in range(b, b+len(q1)):
|
85 |
+
q[k] += q1[k-b]
|
86 |
+
while p[-1]==0: p.pop()
|
87 |
+
while q[-1]==0: q.pop()
|
88 |
+
p1, p2 = p2, p
|
89 |
+
q1, q2 = q2, q
|
90 |
+
|
91 |
+
# yield result
|
92 |
+
c = 1
|
93 |
+
for x in p:
|
94 |
+
c = lcm(c, denom(x))
|
95 |
+
for x in q:
|
96 |
+
c = lcm(c, denom(x))
|
97 |
+
out = ( sum(c*e*X**k for k, e in enumerate(p))
|
98 |
+
/ sum(c*e*X**k for k, e in enumerate(q)) )
|
99 |
+
if simplify:
|
100 |
+
yield(simp(out))
|
101 |
+
else:
|
102 |
+
yield out
|
103 |
+
return
|
llmeval-env/lib/python3.10/site-packages/sympy/series/aseries.py
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from sympy.core.sympify import sympify
|
2 |
+
|
3 |
+
|
4 |
+
def aseries(expr, x=None, n=6, bound=0, hir=False):
|
5 |
+
"""
|
6 |
+
See the docstring of Expr.aseries() for complete details of this wrapper.
|
7 |
+
|
8 |
+
"""
|
9 |
+
expr = sympify(expr)
|
10 |
+
return expr.aseries(x, n, bound, hir)
|
llmeval-env/lib/python3.10/site-packages/sympy/series/benchmarks/__init__.py
ADDED
File without changes
|
llmeval-env/lib/python3.10/site-packages/sympy/series/benchmarks/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (196 Bytes). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/series/benchmarks/__pycache__/bench_limit.cpython-310.pyc
ADDED
Binary file (502 Bytes). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/series/benchmarks/__pycache__/bench_order.cpython-310.pyc
ADDED
Binary file (658 Bytes). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/series/benchmarks/bench_limit.py
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from sympy.core.numbers import oo
|
2 |
+
from sympy.core.symbol import Symbol
|
3 |
+
from sympy.series.limits import limit
|
4 |
+
|
5 |
+
x = Symbol('x')
|
6 |
+
|
7 |
+
|
8 |
+
def timeit_limit_1x():
|
9 |
+
limit(1/x, x, oo)
|
llmeval-env/lib/python3.10/site-packages/sympy/series/benchmarks/bench_order.py
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from sympy.core.add import Add
|
2 |
+
from sympy.core.symbol import Symbol
|
3 |
+
from sympy.series.order import O
|
4 |
+
|
5 |
+
x = Symbol('x')
|
6 |
+
l = [x**i for i in range(1000)]
|
7 |
+
l.append(O(x**1001))
|
8 |
+
|
9 |
+
def timeit_order_1x():
|
10 |
+
Add(*l)
|
llmeval-env/lib/python3.10/site-packages/sympy/series/kauers.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
def finite_diff(expression, variable, increment=1):
|
2 |
+
"""
|
3 |
+
Takes as input a polynomial expression and the variable used to construct
|
4 |
+
it and returns the difference between function's value when the input is
|
5 |
+
incremented to 1 and the original function value. If you want an increment
|
6 |
+
other than one supply it as a third argument.
|
7 |
+
|
8 |
+
Examples
|
9 |
+
========
|
10 |
+
|
11 |
+
>>> from sympy.abc import x, y, z
|
12 |
+
>>> from sympy.series.kauers import finite_diff
|
13 |
+
>>> finite_diff(x**2, x)
|
14 |
+
2*x + 1
|
15 |
+
>>> finite_diff(y**3 + 2*y**2 + 3*y + 4, y)
|
16 |
+
3*y**2 + 7*y + 6
|
17 |
+
>>> finite_diff(x**2 + 3*x + 8, x, 2)
|
18 |
+
4*x + 10
|
19 |
+
>>> finite_diff(z**3 + 8*z, z, 3)
|
20 |
+
9*z**2 + 27*z + 51
|
21 |
+
"""
|
22 |
+
expression = expression.expand()
|
23 |
+
expression2 = expression.subs(variable, variable + increment)
|
24 |
+
expression2 = expression2.expand()
|
25 |
+
return expression2 - expression
|
26 |
+
|
27 |
+
def finite_diff_kauers(sum):
|
28 |
+
"""
|
29 |
+
Takes as input a Sum instance and returns the difference between the sum
|
30 |
+
with the upper index incremented by 1 and the original sum. For example,
|
31 |
+
if S(n) is a sum, then finite_diff_kauers will return S(n + 1) - S(n).
|
32 |
+
|
33 |
+
Examples
|
34 |
+
========
|
35 |
+
|
36 |
+
>>> from sympy.series.kauers import finite_diff_kauers
|
37 |
+
>>> from sympy import Sum
|
38 |
+
>>> from sympy.abc import x, y, m, n, k
|
39 |
+
>>> finite_diff_kauers(Sum(k, (k, 1, n)))
|
40 |
+
n + 1
|
41 |
+
>>> finite_diff_kauers(Sum(1/k, (k, 1, n)))
|
42 |
+
1/(n + 1)
|
43 |
+
>>> finite_diff_kauers(Sum((x*y**2), (x, 1, n), (y, 1, m)))
|
44 |
+
(m + 1)**2*(n + 1)
|
45 |
+
>>> finite_diff_kauers(Sum((x*y), (x, 1, m), (y, 1, n)))
|
46 |
+
(m + 1)*(n + 1)
|
47 |
+
"""
|
48 |
+
function = sum.function
|
49 |
+
for l in sum.limits:
|
50 |
+
function = function.subs(l[0], l[- 1] + 1)
|
51 |
+
return function
|
llmeval-env/lib/python3.10/site-packages/sympy/series/order.py
ADDED
@@ -0,0 +1,517 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from sympy.core import S, sympify, Expr, Dummy, Add, Mul
|
2 |
+
from sympy.core.cache import cacheit
|
3 |
+
from sympy.core.containers import Tuple
|
4 |
+
from sympy.core.function import Function, PoleError, expand_power_base, expand_log
|
5 |
+
from sympy.core.sorting import default_sort_key
|
6 |
+
from sympy.functions.elementary.exponential import exp, log
|
7 |
+
from sympy.sets.sets import Complement
|
8 |
+
from sympy.utilities.iterables import uniq, is_sequence
|
9 |
+
|
10 |
+
|
11 |
+
class Order(Expr):
|
12 |
+
r""" Represents the limiting behavior of some function.
|
13 |
+
|
14 |
+
Explanation
|
15 |
+
===========
|
16 |
+
|
17 |
+
The order of a function characterizes the function based on the limiting
|
18 |
+
behavior of the function as it goes to some limit. Only taking the limit
|
19 |
+
point to be a number is currently supported. This is expressed in
|
20 |
+
big O notation [1]_.
|
21 |
+
|
22 |
+
The formal definition for the order of a function `g(x)` about a point `a`
|
23 |
+
is such that `g(x) = O(f(x))` as `x \rightarrow a` if and only if there
|
24 |
+
exists a `\delta > 0` and an `M > 0` such that `|g(x)| \leq M|f(x)|` for
|
25 |
+
`|x-a| < \delta`. This is equivalent to `\limsup_{x \rightarrow a}
|
26 |
+
|g(x)/f(x)| < \infty`.
|
27 |
+
|
28 |
+
Let's illustrate it on the following example by taking the expansion of
|
29 |
+
`\sin(x)` about 0:
|
30 |
+
|
31 |
+
.. math ::
|
32 |
+
\sin(x) = x - x^3/3! + O(x^5)
|
33 |
+
|
34 |
+
where in this case `O(x^5) = x^5/5! - x^7/7! + \cdots`. By the definition
|
35 |
+
of `O`, there is a `\delta > 0` and an `M` such that:
|
36 |
+
|
37 |
+
.. math ::
|
38 |
+
|x^5/5! - x^7/7! + ....| <= M|x^5| \text{ for } |x| < \delta
|
39 |
+
|
40 |
+
or by the alternate definition:
|
41 |
+
|
42 |
+
.. math ::
|
43 |
+
\lim_{x \rightarrow 0} | (x^5/5! - x^7/7! + ....) / x^5| < \infty
|
44 |
+
|
45 |
+
which surely is true, because
|
46 |
+
|
47 |
+
.. math ::
|
48 |
+
\lim_{x \rightarrow 0} | (x^5/5! - x^7/7! + ....) / x^5| = 1/5!
|
49 |
+
|
50 |
+
|
51 |
+
As it is usually used, the order of a function can be intuitively thought
|
52 |
+
of representing all terms of powers greater than the one specified. For
|
53 |
+
example, `O(x^3)` corresponds to any terms proportional to `x^3,
|
54 |
+
x^4,\ldots` and any higher power. For a polynomial, this leaves terms
|
55 |
+
proportional to `x^2`, `x` and constants.
|
56 |
+
|
57 |
+
Examples
|
58 |
+
========
|
59 |
+
|
60 |
+
>>> from sympy import O, oo, cos, pi
|
61 |
+
>>> from sympy.abc import x, y
|
62 |
+
|
63 |
+
>>> O(x + x**2)
|
64 |
+
O(x)
|
65 |
+
>>> O(x + x**2, (x, 0))
|
66 |
+
O(x)
|
67 |
+
>>> O(x + x**2, (x, oo))
|
68 |
+
O(x**2, (x, oo))
|
69 |
+
|
70 |
+
>>> O(1 + x*y)
|
71 |
+
O(1, x, y)
|
72 |
+
>>> O(1 + x*y, (x, 0), (y, 0))
|
73 |
+
O(1, x, y)
|
74 |
+
>>> O(1 + x*y, (x, oo), (y, oo))
|
75 |
+
O(x*y, (x, oo), (y, oo))
|
76 |
+
|
77 |
+
>>> O(1) in O(1, x)
|
78 |
+
True
|
79 |
+
>>> O(1, x) in O(1)
|
80 |
+
False
|
81 |
+
>>> O(x) in O(1, x)
|
82 |
+
True
|
83 |
+
>>> O(x**2) in O(x)
|
84 |
+
True
|
85 |
+
|
86 |
+
>>> O(x)*x
|
87 |
+
O(x**2)
|
88 |
+
>>> O(x) - O(x)
|
89 |
+
O(x)
|
90 |
+
>>> O(cos(x))
|
91 |
+
O(1)
|
92 |
+
>>> O(cos(x), (x, pi/2))
|
93 |
+
O(x - pi/2, (x, pi/2))
|
94 |
+
|
95 |
+
References
|
96 |
+
==========
|
97 |
+
|
98 |
+
.. [1] `Big O notation <https://en.wikipedia.org/wiki/Big_O_notation>`_
|
99 |
+
|
100 |
+
Notes
|
101 |
+
=====
|
102 |
+
|
103 |
+
In ``O(f(x), x)`` the expression ``f(x)`` is assumed to have a leading
|
104 |
+
term. ``O(f(x), x)`` is automatically transformed to
|
105 |
+
``O(f(x).as_leading_term(x),x)``.
|
106 |
+
|
107 |
+
``O(expr*f(x), x)`` is ``O(f(x), x)``
|
108 |
+
|
109 |
+
``O(expr, x)`` is ``O(1)``
|
110 |
+
|
111 |
+
``O(0, x)`` is 0.
|
112 |
+
|
113 |
+
Multivariate O is also supported:
|
114 |
+
|
115 |
+
``O(f(x, y), x, y)`` is transformed to
|
116 |
+
``O(f(x, y).as_leading_term(x,y).as_leading_term(y), x, y)``
|
117 |
+
|
118 |
+
In the multivariate case, it is assumed the limits w.r.t. the various
|
119 |
+
symbols commute.
|
120 |
+
|
121 |
+
If no symbols are passed then all symbols in the expression are used
|
122 |
+
and the limit point is assumed to be zero.
|
123 |
+
|
124 |
+
"""
|
125 |
+
|
126 |
+
is_Order = True
|
127 |
+
|
128 |
+
__slots__ = ()
|
129 |
+
|
130 |
+
@cacheit
|
131 |
+
def __new__(cls, expr, *args, **kwargs):
|
132 |
+
expr = sympify(expr)
|
133 |
+
|
134 |
+
if not args:
|
135 |
+
if expr.is_Order:
|
136 |
+
variables = expr.variables
|
137 |
+
point = expr.point
|
138 |
+
else:
|
139 |
+
variables = list(expr.free_symbols)
|
140 |
+
point = [S.Zero]*len(variables)
|
141 |
+
else:
|
142 |
+
args = list(args if is_sequence(args) else [args])
|
143 |
+
variables, point = [], []
|
144 |
+
if is_sequence(args[0]):
|
145 |
+
for a in args:
|
146 |
+
v, p = list(map(sympify, a))
|
147 |
+
variables.append(v)
|
148 |
+
point.append(p)
|
149 |
+
else:
|
150 |
+
variables = list(map(sympify, args))
|
151 |
+
point = [S.Zero]*len(variables)
|
152 |
+
|
153 |
+
if not all(v.is_symbol for v in variables):
|
154 |
+
raise TypeError('Variables are not symbols, got %s' % variables)
|
155 |
+
|
156 |
+
if len(list(uniq(variables))) != len(variables):
|
157 |
+
raise ValueError('Variables are supposed to be unique symbols, got %s' % variables)
|
158 |
+
|
159 |
+
if expr.is_Order:
|
160 |
+
expr_vp = dict(expr.args[1:])
|
161 |
+
new_vp = dict(expr_vp)
|
162 |
+
vp = dict(zip(variables, point))
|
163 |
+
for v, p in vp.items():
|
164 |
+
if v in new_vp.keys():
|
165 |
+
if p != new_vp[v]:
|
166 |
+
raise NotImplementedError(
|
167 |
+
"Mixing Order at different points is not supported.")
|
168 |
+
else:
|
169 |
+
new_vp[v] = p
|
170 |
+
if set(expr_vp.keys()) == set(new_vp.keys()):
|
171 |
+
return expr
|
172 |
+
else:
|
173 |
+
variables = list(new_vp.keys())
|
174 |
+
point = [new_vp[v] for v in variables]
|
175 |
+
|
176 |
+
if expr is S.NaN:
|
177 |
+
return S.NaN
|
178 |
+
|
179 |
+
if any(x in p.free_symbols for x in variables for p in point):
|
180 |
+
raise ValueError('Got %s as a point.' % point)
|
181 |
+
|
182 |
+
if variables:
|
183 |
+
if any(p != point[0] for p in point):
|
184 |
+
raise NotImplementedError(
|
185 |
+
"Multivariable orders at different points are not supported.")
|
186 |
+
if point[0] in (S.Infinity, S.Infinity*S.ImaginaryUnit):
|
187 |
+
s = {k: 1/Dummy() for k in variables}
|
188 |
+
rs = {1/v: 1/k for k, v in s.items()}
|
189 |
+
ps = [S.Zero for p in point]
|
190 |
+
elif point[0] in (S.NegativeInfinity, S.NegativeInfinity*S.ImaginaryUnit):
|
191 |
+
s = {k: -1/Dummy() for k in variables}
|
192 |
+
rs = {-1/v: -1/k for k, v in s.items()}
|
193 |
+
ps = [S.Zero for p in point]
|
194 |
+
elif point[0] is not S.Zero:
|
195 |
+
s = {k: Dummy() + point[0] for k in variables}
|
196 |
+
rs = {(v - point[0]).together(): k - point[0] for k, v in s.items()}
|
197 |
+
ps = [S.Zero for p in point]
|
198 |
+
else:
|
199 |
+
s = ()
|
200 |
+
rs = ()
|
201 |
+
ps = list(point)
|
202 |
+
|
203 |
+
expr = expr.subs(s)
|
204 |
+
|
205 |
+
if expr.is_Add:
|
206 |
+
expr = expr.factor()
|
207 |
+
|
208 |
+
if s:
|
209 |
+
args = tuple([r[0] for r in rs.items()])
|
210 |
+
else:
|
211 |
+
args = tuple(variables)
|
212 |
+
|
213 |
+
if len(variables) > 1:
|
214 |
+
# XXX: better way? We need this expand() to
|
215 |
+
# workaround e.g: expr = x*(x + y).
|
216 |
+
# (x*(x + y)).as_leading_term(x, y) currently returns
|
217 |
+
# x*y (wrong order term!). That's why we want to deal with
|
218 |
+
# expand()'ed expr (handled in "if expr.is_Add" branch below).
|
219 |
+
expr = expr.expand()
|
220 |
+
|
221 |
+
old_expr = None
|
222 |
+
while old_expr != expr:
|
223 |
+
old_expr = expr
|
224 |
+
if expr.is_Add:
|
225 |
+
lst = expr.extract_leading_order(args)
|
226 |
+
expr = Add(*[f.expr for (e, f) in lst])
|
227 |
+
|
228 |
+
elif expr:
|
229 |
+
try:
|
230 |
+
expr = expr.as_leading_term(*args)
|
231 |
+
except PoleError:
|
232 |
+
if isinstance(expr, Function) or\
|
233 |
+
all(isinstance(arg, Function) for arg in expr.args):
|
234 |
+
# It is not possible to simplify an expression
|
235 |
+
# containing only functions (which raise error on
|
236 |
+
# call to leading term) further
|
237 |
+
pass
|
238 |
+
else:
|
239 |
+
orders = []
|
240 |
+
pts = tuple(zip(args, ps))
|
241 |
+
for arg in expr.args:
|
242 |
+
try:
|
243 |
+
lt = arg.as_leading_term(*args)
|
244 |
+
except PoleError:
|
245 |
+
lt = arg
|
246 |
+
if lt not in args:
|
247 |
+
order = Order(lt)
|
248 |
+
else:
|
249 |
+
order = Order(lt, *pts)
|
250 |
+
orders.append(order)
|
251 |
+
if expr.is_Add:
|
252 |
+
new_expr = Order(Add(*orders), *pts)
|
253 |
+
if new_expr.is_Add:
|
254 |
+
new_expr = Order(Add(*[a.expr for a in new_expr.args]), *pts)
|
255 |
+
expr = new_expr.expr
|
256 |
+
elif expr.is_Mul:
|
257 |
+
expr = Mul(*[a.expr for a in orders])
|
258 |
+
elif expr.is_Pow:
|
259 |
+
e = expr.exp
|
260 |
+
b = expr.base
|
261 |
+
expr = exp(e * log(b))
|
262 |
+
|
263 |
+
# It would probably be better to handle this somewhere
|
264 |
+
# else. This is needed for a testcase in which there is a
|
265 |
+
# symbol with the assumptions zero=True.
|
266 |
+
if expr.is_zero:
|
267 |
+
expr = S.Zero
|
268 |
+
else:
|
269 |
+
expr = expr.as_independent(*args, as_Add=False)[1]
|
270 |
+
|
271 |
+
expr = expand_power_base(expr)
|
272 |
+
expr = expand_log(expr)
|
273 |
+
|
274 |
+
if len(args) == 1:
|
275 |
+
# The definition of O(f(x)) symbol explicitly stated that
|
276 |
+
# the argument of f(x) is irrelevant. That's why we can
|
277 |
+
# combine some power exponents (only "on top" of the
|
278 |
+
# expression tree for f(x)), e.g.:
|
279 |
+
# x**p * (-x)**q -> x**(p+q) for real p, q.
|
280 |
+
x = args[0]
|
281 |
+
margs = list(Mul.make_args(
|
282 |
+
expr.as_independent(x, as_Add=False)[1]))
|
283 |
+
|
284 |
+
for i, t in enumerate(margs):
|
285 |
+
if t.is_Pow:
|
286 |
+
b, q = t.args
|
287 |
+
if b in (x, -x) and q.is_real and not q.has(x):
|
288 |
+
margs[i] = x**q
|
289 |
+
elif b.is_Pow and not b.exp.has(x):
|
290 |
+
b, r = b.args
|
291 |
+
if b in (x, -x) and r.is_real:
|
292 |
+
margs[i] = x**(r*q)
|
293 |
+
elif b.is_Mul and b.args[0] is S.NegativeOne:
|
294 |
+
b = -b
|
295 |
+
if b.is_Pow and not b.exp.has(x):
|
296 |
+
b, r = b.args
|
297 |
+
if b in (x, -x) and r.is_real:
|
298 |
+
margs[i] = x**(r*q)
|
299 |
+
|
300 |
+
expr = Mul(*margs)
|
301 |
+
|
302 |
+
expr = expr.subs(rs)
|
303 |
+
|
304 |
+
if expr.is_Order:
|
305 |
+
expr = expr.expr
|
306 |
+
|
307 |
+
if not expr.has(*variables) and not expr.is_zero:
|
308 |
+
expr = S.One
|
309 |
+
|
310 |
+
# create Order instance:
|
311 |
+
vp = dict(zip(variables, point))
|
312 |
+
variables.sort(key=default_sort_key)
|
313 |
+
point = [vp[v] for v in variables]
|
314 |
+
args = (expr,) + Tuple(*zip(variables, point))
|
315 |
+
obj = Expr.__new__(cls, *args)
|
316 |
+
return obj
|
317 |
+
|
318 |
+
def _eval_nseries(self, x, n, logx, cdir=0):
|
319 |
+
return self
|
320 |
+
|
321 |
+
@property
|
322 |
+
def expr(self):
|
323 |
+
return self.args[0]
|
324 |
+
|
325 |
+
@property
|
326 |
+
def variables(self):
|
327 |
+
if self.args[1:]:
|
328 |
+
return tuple(x[0] for x in self.args[1:])
|
329 |
+
else:
|
330 |
+
return ()
|
331 |
+
|
332 |
+
@property
|
333 |
+
def point(self):
|
334 |
+
if self.args[1:]:
|
335 |
+
return tuple(x[1] for x in self.args[1:])
|
336 |
+
else:
|
337 |
+
return ()
|
338 |
+
|
339 |
+
@property
|
340 |
+
def free_symbols(self):
|
341 |
+
return self.expr.free_symbols | set(self.variables)
|
342 |
+
|
343 |
+
def _eval_power(b, e):
|
344 |
+
if e.is_Number and e.is_nonnegative:
|
345 |
+
return b.func(b.expr ** e, *b.args[1:])
|
346 |
+
if e == O(1):
|
347 |
+
return b
|
348 |
+
return
|
349 |
+
|
350 |
+
def as_expr_variables(self, order_symbols):
|
351 |
+
if order_symbols is None:
|
352 |
+
order_symbols = self.args[1:]
|
353 |
+
else:
|
354 |
+
if (not all(o[1] == order_symbols[0][1] for o in order_symbols) and
|
355 |
+
not all(p == self.point[0] for p in self.point)): # pragma: no cover
|
356 |
+
raise NotImplementedError('Order at points other than 0 '
|
357 |
+
'or oo not supported, got %s as a point.' % self.point)
|
358 |
+
if order_symbols and order_symbols[0][1] != self.point[0]:
|
359 |
+
raise NotImplementedError(
|
360 |
+
"Multiplying Order at different points is not supported.")
|
361 |
+
order_symbols = dict(order_symbols)
|
362 |
+
for s, p in dict(self.args[1:]).items():
|
363 |
+
if s not in order_symbols.keys():
|
364 |
+
order_symbols[s] = p
|
365 |
+
order_symbols = sorted(order_symbols.items(), key=lambda x: default_sort_key(x[0]))
|
366 |
+
return self.expr, tuple(order_symbols)
|
367 |
+
|
368 |
+
def removeO(self):
|
369 |
+
return S.Zero
|
370 |
+
|
371 |
+
def getO(self):
|
372 |
+
return self
|
373 |
+
|
374 |
+
@cacheit
|
375 |
+
def contains(self, expr):
|
376 |
+
r"""
|
377 |
+
Return True if expr belongs to Order(self.expr, \*self.variables).
|
378 |
+
Return False if self belongs to expr.
|
379 |
+
Return None if the inclusion relation cannot be determined
|
380 |
+
(e.g. when self and expr have different symbols).
|
381 |
+
"""
|
382 |
+
expr = sympify(expr)
|
383 |
+
if expr.is_zero:
|
384 |
+
return True
|
385 |
+
if expr is S.NaN:
|
386 |
+
return False
|
387 |
+
point = self.point[0] if self.point else S.Zero
|
388 |
+
if expr.is_Order:
|
389 |
+
if (any(p != point for p in expr.point) or
|
390 |
+
any(p != point for p in self.point)):
|
391 |
+
return None
|
392 |
+
if expr.expr == self.expr:
|
393 |
+
# O(1) + O(1), O(1) + O(1, x), etc.
|
394 |
+
return all(x in self.args[1:] for x in expr.args[1:])
|
395 |
+
if expr.expr.is_Add:
|
396 |
+
return all(self.contains(x) for x in expr.expr.args)
|
397 |
+
if self.expr.is_Add and point.is_zero:
|
398 |
+
return any(self.func(x, *self.args[1:]).contains(expr)
|
399 |
+
for x in self.expr.args)
|
400 |
+
if self.variables and expr.variables:
|
401 |
+
common_symbols = tuple(
|
402 |
+
[s for s in self.variables if s in expr.variables])
|
403 |
+
elif self.variables:
|
404 |
+
common_symbols = self.variables
|
405 |
+
else:
|
406 |
+
common_symbols = expr.variables
|
407 |
+
if not common_symbols:
|
408 |
+
return None
|
409 |
+
if (self.expr.is_Pow and len(self.variables) == 1
|
410 |
+
and self.variables == expr.variables):
|
411 |
+
symbol = self.variables[0]
|
412 |
+
other = expr.expr.as_independent(symbol, as_Add=False)[1]
|
413 |
+
if (other.is_Pow and other.base == symbol and
|
414 |
+
self.expr.base == symbol):
|
415 |
+
if point.is_zero:
|
416 |
+
rv = (self.expr.exp - other.exp).is_nonpositive
|
417 |
+
if point.is_infinite:
|
418 |
+
rv = (self.expr.exp - other.exp).is_nonnegative
|
419 |
+
if rv is not None:
|
420 |
+
return rv
|
421 |
+
|
422 |
+
from sympy.simplify.powsimp import powsimp
|
423 |
+
r = None
|
424 |
+
ratio = self.expr/expr.expr
|
425 |
+
ratio = powsimp(ratio, deep=True, combine='exp')
|
426 |
+
for s in common_symbols:
|
427 |
+
from sympy.series.limits import Limit
|
428 |
+
l = Limit(ratio, s, point).doit(heuristics=False)
|
429 |
+
if not isinstance(l, Limit):
|
430 |
+
l = l != 0
|
431 |
+
else:
|
432 |
+
l = None
|
433 |
+
if r is None:
|
434 |
+
r = l
|
435 |
+
else:
|
436 |
+
if r != l:
|
437 |
+
return
|
438 |
+
return r
|
439 |
+
|
440 |
+
if self.expr.is_Pow and len(self.variables) == 1:
|
441 |
+
symbol = self.variables[0]
|
442 |
+
other = expr.as_independent(symbol, as_Add=False)[1]
|
443 |
+
if (other.is_Pow and other.base == symbol and
|
444 |
+
self.expr.base == symbol):
|
445 |
+
if point.is_zero:
|
446 |
+
rv = (self.expr.exp - other.exp).is_nonpositive
|
447 |
+
if point.is_infinite:
|
448 |
+
rv = (self.expr.exp - other.exp).is_nonnegative
|
449 |
+
if rv is not None:
|
450 |
+
return rv
|
451 |
+
|
452 |
+
obj = self.func(expr, *self.args[1:])
|
453 |
+
return self.contains(obj)
|
454 |
+
|
455 |
+
def __contains__(self, other):
|
456 |
+
result = self.contains(other)
|
457 |
+
if result is None:
|
458 |
+
raise TypeError('contains did not evaluate to a bool')
|
459 |
+
return result
|
460 |
+
|
461 |
+
def _eval_subs(self, old, new):
|
462 |
+
if old in self.variables:
|
463 |
+
newexpr = self.expr.subs(old, new)
|
464 |
+
i = self.variables.index(old)
|
465 |
+
newvars = list(self.variables)
|
466 |
+
newpt = list(self.point)
|
467 |
+
if new.is_symbol:
|
468 |
+
newvars[i] = new
|
469 |
+
else:
|
470 |
+
syms = new.free_symbols
|
471 |
+
if len(syms) == 1 or old in syms:
|
472 |
+
if old in syms:
|
473 |
+
var = self.variables[i]
|
474 |
+
else:
|
475 |
+
var = syms.pop()
|
476 |
+
# First, try to substitute self.point in the "new"
|
477 |
+
# expr to see if this is a fixed point.
|
478 |
+
# E.g. O(y).subs(y, sin(x))
|
479 |
+
point = new.subs(var, self.point[i])
|
480 |
+
if point != self.point[i]:
|
481 |
+
from sympy.solvers.solveset import solveset
|
482 |
+
d = Dummy()
|
483 |
+
sol = solveset(old - new.subs(var, d), d)
|
484 |
+
if isinstance(sol, Complement):
|
485 |
+
e1 = sol.args[0]
|
486 |
+
e2 = sol.args[1]
|
487 |
+
sol = set(e1) - set(e2)
|
488 |
+
res = [dict(zip((d, ), sol))]
|
489 |
+
point = d.subs(res[0]).limit(old, self.point[i])
|
490 |
+
newvars[i] = var
|
491 |
+
newpt[i] = point
|
492 |
+
elif old not in syms:
|
493 |
+
del newvars[i], newpt[i]
|
494 |
+
if not syms and new == self.point[i]:
|
495 |
+
newvars.extend(syms)
|
496 |
+
newpt.extend([S.Zero]*len(syms))
|
497 |
+
else:
|
498 |
+
return
|
499 |
+
return Order(newexpr, *zip(newvars, newpt))
|
500 |
+
|
501 |
+
def _eval_conjugate(self):
|
502 |
+
expr = self.expr._eval_conjugate()
|
503 |
+
if expr is not None:
|
504 |
+
return self.func(expr, *self.args[1:])
|
505 |
+
|
506 |
+
def _eval_derivative(self, x):
|
507 |
+
return self.func(self.expr.diff(x), *self.args[1:]) or self
|
508 |
+
|
509 |
+
def _eval_transpose(self):
|
510 |
+
expr = self.expr._eval_transpose()
|
511 |
+
if expr is not None:
|
512 |
+
return self.func(expr, *self.args[1:])
|
513 |
+
|
514 |
+
def __neg__(self):
|
515 |
+
return self
|
516 |
+
|
517 |
+
O = Order
|
llmeval-env/lib/python3.10/site-packages/sympy/series/residues.py
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
This module implements the Residue function and related tools for working
|
3 |
+
with residues.
|
4 |
+
"""
|
5 |
+
|
6 |
+
from sympy.core.mul import Mul
|
7 |
+
from sympy.core.singleton import S
|
8 |
+
from sympy.core.sympify import sympify
|
9 |
+
from sympy.utilities.timeutils import timethis
|
10 |
+
|
11 |
+
|
12 |
+
@timethis('residue')
|
13 |
+
def residue(expr, x, x0):
|
14 |
+
"""
|
15 |
+
Finds the residue of ``expr`` at the point x=x0.
|
16 |
+
|
17 |
+
The residue is defined as the coefficient of ``1/(x-x0)`` in the power series
|
18 |
+
expansion about ``x=x0``.
|
19 |
+
|
20 |
+
Examples
|
21 |
+
========
|
22 |
+
|
23 |
+
>>> from sympy import Symbol, residue, sin
|
24 |
+
>>> x = Symbol("x")
|
25 |
+
>>> residue(1/x, x, 0)
|
26 |
+
1
|
27 |
+
>>> residue(1/x**2, x, 0)
|
28 |
+
0
|
29 |
+
>>> residue(2/sin(x), x, 0)
|
30 |
+
2
|
31 |
+
|
32 |
+
This function is essential for the Residue Theorem [1].
|
33 |
+
|
34 |
+
References
|
35 |
+
==========
|
36 |
+
|
37 |
+
.. [1] https://en.wikipedia.org/wiki/Residue_theorem
|
38 |
+
"""
|
39 |
+
# The current implementation uses series expansion to
|
40 |
+
# calculate it. A more general implementation is explained in
|
41 |
+
# the section 5.6 of the Bronstein's book {M. Bronstein:
|
42 |
+
# Symbolic Integration I, Springer Verlag (2005)}. For purely
|
43 |
+
# rational functions, the algorithm is much easier. See
|
44 |
+
# sections 2.4, 2.5, and 2.7 (this section actually gives an
|
45 |
+
# algorithm for computing any Laurent series coefficient for
|
46 |
+
# a rational function). The theory in section 2.4 will help to
|
47 |
+
# understand why the resultant works in the general algorithm.
|
48 |
+
# For the definition of a resultant, see section 1.4 (and any
|
49 |
+
# previous sections for more review).
|
50 |
+
|
51 |
+
from sympy.series.order import Order
|
52 |
+
from sympy.simplify.radsimp import collect
|
53 |
+
expr = sympify(expr)
|
54 |
+
if x0 != 0:
|
55 |
+
expr = expr.subs(x, x + x0)
|
56 |
+
for n in (0, 1, 2, 4, 8, 16, 32):
|
57 |
+
s = expr.nseries(x, n=n)
|
58 |
+
if not s.has(Order) or s.getn() >= 0:
|
59 |
+
break
|
60 |
+
s = collect(s.removeO(), x)
|
61 |
+
if s.is_Add:
|
62 |
+
args = s.args
|
63 |
+
else:
|
64 |
+
args = [s]
|
65 |
+
res = S.Zero
|
66 |
+
for arg in args:
|
67 |
+
c, m = arg.as_coeff_mul(x)
|
68 |
+
m = Mul(*m)
|
69 |
+
if not (m in (S.One, x) or (m.is_Pow and m.exp.is_Integer)):
|
70 |
+
raise NotImplementedError('term of unexpected form: %s' % m)
|
71 |
+
if m == 1/x:
|
72 |
+
res += c
|
73 |
+
return res
|
llmeval-env/lib/python3.10/site-packages/sympy/series/tests/__init__.py
ADDED
File without changes
|
llmeval-env/lib/python3.10/site-packages/sympy/series/tests/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (191 Bytes). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/series/tests/__pycache__/test_approximants.cpython-310.pyc
ADDED
Binary file (1.93 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/series/tests/__pycache__/test_aseries.cpython-310.pyc
ADDED
Binary file (2.79 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/series/tests/__pycache__/test_demidovich.cpython-310.pyc
ADDED
Binary file (6.28 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/series/tests/__pycache__/test_formal.cpython-310.pyc
ADDED
Binary file (24.7 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/series/tests/__pycache__/test_fourier.cpython-310.pyc
ADDED
Binary file (7.14 kB). View file
|
|