ZTWHHH commited on
Commit
e7eec0f
Β·
verified Β·
1 Parent(s): b4f881b

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. openflamingo/lib/python3.10/site-packages/sympy/crypto/tests/__init__.py +0 -0
  2. openflamingo/lib/python3.10/site-packages/sympy/crypto/tests/__pycache__/__init__.cpython-310.pyc +0 -0
  3. openflamingo/lib/python3.10/site-packages/sympy/crypto/tests/__pycache__/test_crypto.cpython-310.pyc +0 -0
  4. openflamingo/lib/python3.10/site-packages/sympy/crypto/tests/test_crypto.py +562 -0
  5. openflamingo/lib/python3.10/site-packages/sympy/series/__pycache__/limits.cpython-310.pyc +0 -0
  6. openflamingo/lib/python3.10/site-packages/sympy/series/benchmarks/__pycache__/__init__.cpython-310.pyc +0 -0
  7. openflamingo/lib/python3.10/site-packages/sympy/series/benchmarks/__pycache__/bench_order.cpython-310.pyc +0 -0
  8. openflamingo/lib/python3.10/site-packages/sympy/series/benchmarks/bench_order.py +10 -0
  9. openflamingo/lib/python3.10/site-packages/sympy/sets/__pycache__/conditionset.cpython-310.pyc +0 -0
  10. openflamingo/lib/python3.10/site-packages/sympy/sets/__pycache__/contains.cpython-310.pyc +0 -0
  11. openflamingo/lib/python3.10/site-packages/sympy/sets/__pycache__/ordinals.cpython-310.pyc +0 -0
  12. openflamingo/lib/python3.10/site-packages/sympy/sets/__pycache__/setexpr.cpython-310.pyc +0 -0
  13. openflamingo/lib/python3.10/site-packages/sympy/sets/handlers/intersection.py +533 -0
  14. openflamingo/lib/python3.10/site-packages/sympy/sets/handlers/issubset.py +144 -0
  15. openflamingo/lib/python3.10/site-packages/sympy/sets/handlers/power.py +107 -0
  16. openflamingo/lib/python3.10/site-packages/sympy/sets/handlers/union.py +147 -0
  17. openflamingo/lib/python3.10/site-packages/sympy/sets/tests/__pycache__/test_setexpr.cpython-310.pyc +0 -0
  18. openflamingo/lib/python3.10/site-packages/sympy/sets/tests/__pycache__/test_sets.cpython-310.pyc +0 -0
  19. phi4/lib/python3.10/site-packages/fsspec/__pycache__/__init__.cpython-310.pyc +0 -0
  20. phi4/lib/python3.10/site-packages/fsspec/__pycache__/_version.cpython-310.pyc +0 -0
  21. phi4/lib/python3.10/site-packages/fsspec/__pycache__/archive.cpython-310.pyc +0 -0
  22. phi4/lib/python3.10/site-packages/fsspec/__pycache__/asyn.cpython-310.pyc +0 -0
  23. phi4/lib/python3.10/site-packages/fsspec/__pycache__/caching.cpython-310.pyc +0 -0
  24. phi4/lib/python3.10/site-packages/fsspec/__pycache__/callbacks.cpython-310.pyc +0 -0
  25. phi4/lib/python3.10/site-packages/fsspec/__pycache__/compression.cpython-310.pyc +0 -0
  26. phi4/lib/python3.10/site-packages/fsspec/__pycache__/config.cpython-310.pyc +0 -0
  27. phi4/lib/python3.10/site-packages/fsspec/__pycache__/conftest.cpython-310.pyc +0 -0
  28. phi4/lib/python3.10/site-packages/fsspec/__pycache__/core.cpython-310.pyc +0 -0
  29. phi4/lib/python3.10/site-packages/fsspec/__pycache__/dircache.cpython-310.pyc +0 -0
  30. phi4/lib/python3.10/site-packages/fsspec/__pycache__/exceptions.cpython-310.pyc +0 -0
  31. phi4/lib/python3.10/site-packages/fsspec/__pycache__/fuse.cpython-310.pyc +0 -0
  32. phi4/lib/python3.10/site-packages/fsspec/__pycache__/generic.cpython-310.pyc +0 -0
  33. phi4/lib/python3.10/site-packages/fsspec/__pycache__/gui.cpython-310.pyc +0 -0
  34. phi4/lib/python3.10/site-packages/fsspec/__pycache__/json.cpython-310.pyc +0 -0
  35. phi4/lib/python3.10/site-packages/fsspec/__pycache__/mapping.cpython-310.pyc +0 -0
  36. phi4/lib/python3.10/site-packages/fsspec/__pycache__/parquet.cpython-310.pyc +0 -0
  37. phi4/lib/python3.10/site-packages/fsspec/__pycache__/registry.cpython-310.pyc +0 -0
  38. phi4/lib/python3.10/site-packages/fsspec/__pycache__/spec.cpython-310.pyc +0 -0
  39. phi4/lib/python3.10/site-packages/fsspec/__pycache__/transaction.cpython-310.pyc +0 -0
  40. phi4/lib/python3.10/site-packages/fsspec/__pycache__/utils.cpython-310.pyc +0 -0
  41. phi4/lib/python3.10/site-packages/fsspec/implementations/__pycache__/__init__.cpython-310.pyc +0 -0
  42. phi4/lib/python3.10/site-packages/fsspec/implementations/__pycache__/cached.cpython-310.pyc +0 -0
  43. phi4/lib/python3.10/site-packages/fsspec/implementations/__pycache__/dask.cpython-310.pyc +0 -0
  44. phi4/lib/python3.10/site-packages/fsspec/tests/abstract/__init__.py +289 -0
  45. phi4/lib/python3.10/site-packages/fsspec/tests/abstract/__pycache__/__init__.cpython-310.pyc +0 -0
  46. phi4/lib/python3.10/site-packages/fsspec/tests/abstract/__pycache__/common.cpython-310.pyc +0 -0
  47. phi4/lib/python3.10/site-packages/fsspec/tests/abstract/__pycache__/copy.cpython-310.pyc +0 -0
  48. phi4/lib/python3.10/site-packages/fsspec/tests/abstract/__pycache__/get.cpython-310.pyc +0 -0
  49. phi4/lib/python3.10/site-packages/fsspec/tests/abstract/__pycache__/mv.cpython-310.pyc +0 -0
  50. phi4/lib/python3.10/site-packages/fsspec/tests/abstract/__pycache__/open.cpython-310.pyc +0 -0
openflamingo/lib/python3.10/site-packages/sympy/crypto/tests/__init__.py ADDED
File without changes
openflamingo/lib/python3.10/site-packages/sympy/crypto/tests/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (176 Bytes). View file
 
openflamingo/lib/python3.10/site-packages/sympy/crypto/tests/__pycache__/test_crypto.cpython-310.pyc ADDED
Binary file (20.9 kB). View file
 
openflamingo/lib/python3.10/site-packages/sympy/crypto/tests/test_crypto.py ADDED
@@ -0,0 +1,562 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sympy.core import symbols
2
+ from sympy.crypto.crypto import (cycle_list,
3
+ encipher_shift, encipher_affine, encipher_substitution,
4
+ check_and_join, encipher_vigenere, decipher_vigenere,
5
+ encipher_hill, decipher_hill, encipher_bifid5, encipher_bifid6,
6
+ bifid5_square, bifid6_square, bifid5, bifid6,
7
+ decipher_bifid5, decipher_bifid6, encipher_kid_rsa,
8
+ decipher_kid_rsa, kid_rsa_private_key, kid_rsa_public_key,
9
+ decipher_rsa, rsa_private_key, rsa_public_key, encipher_rsa,
10
+ lfsr_connection_polynomial, lfsr_autocorrelation, lfsr_sequence,
11
+ encode_morse, decode_morse, elgamal_private_key, elgamal_public_key,
12
+ encipher_elgamal, decipher_elgamal, dh_private_key, dh_public_key,
13
+ dh_shared_key, decipher_shift, decipher_affine, encipher_bifid,
14
+ decipher_bifid, bifid_square, padded_key, uniq, decipher_gm,
15
+ encipher_gm, gm_public_key, gm_private_key, encipher_bg, decipher_bg,
16
+ bg_private_key, bg_public_key, encipher_rot13, decipher_rot13,
17
+ encipher_atbash, decipher_atbash, NonInvertibleCipherWarning,
18
+ encipher_railfence, decipher_railfence)
19
+ from sympy.external.gmpy import gcd
20
+ from sympy.matrices import Matrix
21
+ from sympy.ntheory import isprime, is_primitive_root
22
+ from sympy.polys.domains import FF
23
+
24
+ from sympy.testing.pytest import raises, warns
25
+
26
+ from sympy.core.random import randrange
27
+
28
+ def test_encipher_railfence():
29
+ assert encipher_railfence("hello world",2) == "hlowrdel ol"
30
+ assert encipher_railfence("hello world",3) == "horel ollwd"
31
+ assert encipher_railfence("hello world",4) == "hwe olordll"
32
+
33
+ def test_decipher_railfence():
34
+ assert decipher_railfence("hlowrdel ol",2) == "hello world"
35
+ assert decipher_railfence("horel ollwd",3) == "hello world"
36
+ assert decipher_railfence("hwe olordll",4) == "hello world"
37
+
38
+
39
+ def test_cycle_list():
40
+ assert cycle_list(3, 4) == [3, 0, 1, 2]
41
+ assert cycle_list(-1, 4) == [3, 0, 1, 2]
42
+ assert cycle_list(1, 4) == [1, 2, 3, 0]
43
+
44
+
45
+ def test_encipher_shift():
46
+ assert encipher_shift("ABC", 0) == "ABC"
47
+ assert encipher_shift("ABC", 1) == "BCD"
48
+ assert encipher_shift("ABC", -1) == "ZAB"
49
+ assert decipher_shift("ZAB", -1) == "ABC"
50
+
51
+ def test_encipher_rot13():
52
+ assert encipher_rot13("ABC") == "NOP"
53
+ assert encipher_rot13("NOP") == "ABC"
54
+ assert decipher_rot13("ABC") == "NOP"
55
+ assert decipher_rot13("NOP") == "ABC"
56
+
57
+
58
+ def test_encipher_affine():
59
+ assert encipher_affine("ABC", (1, 0)) == "ABC"
60
+ assert encipher_affine("ABC", (1, 1)) == "BCD"
61
+ assert encipher_affine("ABC", (-1, 0)) == "AZY"
62
+ assert encipher_affine("ABC", (-1, 1), symbols="ABCD") == "BAD"
63
+ assert encipher_affine("123", (-1, 1), symbols="1234") == "214"
64
+ assert encipher_affine("ABC", (3, 16)) == "QTW"
65
+ assert decipher_affine("QTW", (3, 16)) == "ABC"
66
+
67
+ def test_encipher_atbash():
68
+ assert encipher_atbash("ABC") == "ZYX"
69
+ assert encipher_atbash("ZYX") == "ABC"
70
+ assert decipher_atbash("ABC") == "ZYX"
71
+ assert decipher_atbash("ZYX") == "ABC"
72
+
73
+ def test_encipher_substitution():
74
+ assert encipher_substitution("ABC", "BAC", "ABC") == "BAC"
75
+ assert encipher_substitution("123", "1243", "1234") == "124"
76
+
77
+
78
+ def test_check_and_join():
79
+ assert check_and_join("abc") == "abc"
80
+ assert check_and_join(uniq("aaabc")) == "abc"
81
+ assert check_and_join("ab c".split()) == "abc"
82
+ assert check_and_join("abc", "a", filter=True) == "a"
83
+ raises(ValueError, lambda: check_and_join('ab', 'a'))
84
+
85
+
86
+ def test_encipher_vigenere():
87
+ assert encipher_vigenere("ABC", "ABC") == "ACE"
88
+ assert encipher_vigenere("ABC", "ABC", symbols="ABCD") == "ACA"
89
+ assert encipher_vigenere("ABC", "AB", symbols="ABCD") == "ACC"
90
+ assert encipher_vigenere("AB", "ABC", symbols="ABCD") == "AC"
91
+ assert encipher_vigenere("A", "ABC", symbols="ABCD") == "A"
92
+
93
+
94
+ def test_decipher_vigenere():
95
+ assert decipher_vigenere("ABC", "ABC") == "AAA"
96
+ assert decipher_vigenere("ABC", "ABC", symbols="ABCD") == "AAA"
97
+ assert decipher_vigenere("ABC", "AB", symbols="ABCD") == "AAC"
98
+ assert decipher_vigenere("AB", "ABC", symbols="ABCD") == "AA"
99
+ assert decipher_vigenere("A", "ABC", symbols="ABCD") == "A"
100
+
101
+
102
+ def test_encipher_hill():
103
+ A = Matrix(2, 2, [1, 2, 3, 5])
104
+ assert encipher_hill("ABCD", A) == "CFIV"
105
+ A = Matrix(2, 2, [1, 0, 0, 1])
106
+ assert encipher_hill("ABCD", A) == "ABCD"
107
+ assert encipher_hill("ABCD", A, symbols="ABCD") == "ABCD"
108
+ A = Matrix(2, 2, [1, 2, 3, 5])
109
+ assert encipher_hill("ABCD", A, symbols="ABCD") == "CBAB"
110
+ assert encipher_hill("AB", A, symbols="ABCD") == "CB"
111
+ # message length, n, does not need to be a multiple of k;
112
+ # it is padded
113
+ assert encipher_hill("ABA", A) == "CFGC"
114
+ assert encipher_hill("ABA", A, pad="Z") == "CFYV"
115
+
116
+
117
+ def test_decipher_hill():
118
+ A = Matrix(2, 2, [1, 2, 3, 5])
119
+ assert decipher_hill("CFIV", A) == "ABCD"
120
+ A = Matrix(2, 2, [1, 0, 0, 1])
121
+ assert decipher_hill("ABCD", A) == "ABCD"
122
+ assert decipher_hill("ABCD", A, symbols="ABCD") == "ABCD"
123
+ A = Matrix(2, 2, [1, 2, 3, 5])
124
+ assert decipher_hill("CBAB", A, symbols="ABCD") == "ABCD"
125
+ assert decipher_hill("CB", A, symbols="ABCD") == "AB"
126
+ # n does not need to be a multiple of k
127
+ assert decipher_hill("CFA", A) == "ABAA"
128
+
129
+
130
+ def test_encipher_bifid5():
131
+ assert encipher_bifid5("AB", "AB") == "AB"
132
+ assert encipher_bifid5("AB", "CD") == "CO"
133
+ assert encipher_bifid5("ab", "c") == "CH"
134
+ assert encipher_bifid5("a bc", "b") == "BAC"
135
+
136
+
137
+ def test_bifid5_square():
138
+ A = bifid5
139
+ f = lambda i, j: symbols(A[5*i + j])
140
+ M = Matrix(5, 5, f)
141
+ assert bifid5_square("") == M
142
+
143
+
144
+ def test_decipher_bifid5():
145
+ assert decipher_bifid5("AB", "AB") == "AB"
146
+ assert decipher_bifid5("CO", "CD") == "AB"
147
+ assert decipher_bifid5("ch", "c") == "AB"
148
+ assert decipher_bifid5("b ac", "b") == "ABC"
149
+
150
+
151
+ def test_encipher_bifid6():
152
+ assert encipher_bifid6("AB", "AB") == "AB"
153
+ assert encipher_bifid6("AB", "CD") == "CP"
154
+ assert encipher_bifid6("ab", "c") == "CI"
155
+ assert encipher_bifid6("a bc", "b") == "BAC"
156
+
157
+
158
+ def test_decipher_bifid6():
159
+ assert decipher_bifid6("AB", "AB") == "AB"
160
+ assert decipher_bifid6("CP", "CD") == "AB"
161
+ assert decipher_bifid6("ci", "c") == "AB"
162
+ assert decipher_bifid6("b ac", "b") == "ABC"
163
+
164
+
165
+ def test_bifid6_square():
166
+ A = bifid6
167
+ f = lambda i, j: symbols(A[6*i + j])
168
+ M = Matrix(6, 6, f)
169
+ assert bifid6_square("") == M
170
+
171
+
172
+ def test_rsa_public_key():
173
+ assert rsa_public_key(2, 3, 1) == (6, 1)
174
+ assert rsa_public_key(5, 3, 3) == (15, 3)
175
+
176
+ with warns(NonInvertibleCipherWarning):
177
+ assert rsa_public_key(2, 2, 1) == (4, 1)
178
+ assert rsa_public_key(8, 8, 8) is False
179
+
180
+
181
+ def test_rsa_private_key():
182
+ assert rsa_private_key(2, 3, 1) == (6, 1)
183
+ assert rsa_private_key(5, 3, 3) == (15, 3)
184
+ assert rsa_private_key(23,29,5) == (667,493)
185
+
186
+ with warns(NonInvertibleCipherWarning):
187
+ assert rsa_private_key(2, 2, 1) == (4, 1)
188
+ assert rsa_private_key(8, 8, 8) is False
189
+
190
+
191
+ def test_rsa_large_key():
192
+ # Sample from
193
+ # http://www.herongyang.com/Cryptography/JCE-Public-Key-RSA-Private-Public-Key-Pair-Sample.html
194
+ p = int('101565610013301240713207239558950144682174355406589305284428666'\
195
+ '903702505233009')
196
+ q = int('894687191887545488935455605955948413812376003053143521429242133'\
197
+ '12069293984003')
198
+ e = int('65537')
199
+ d = int('893650581832704239530398858744759129594796235440844479456143566'\
200
+ '6999402846577625762582824202269399672579058991442587406384754958587'\
201
+ '400493169361356902030209')
202
+ assert rsa_public_key(p, q, e) == (p*q, e)
203
+ assert rsa_private_key(p, q, e) == (p*q, d)
204
+
205
+
206
+ def test_encipher_rsa():
207
+ puk = rsa_public_key(2, 3, 1)
208
+ assert encipher_rsa(2, puk) == 2
209
+ puk = rsa_public_key(5, 3, 3)
210
+ assert encipher_rsa(2, puk) == 8
211
+
212
+ with warns(NonInvertibleCipherWarning):
213
+ puk = rsa_public_key(2, 2, 1)
214
+ assert encipher_rsa(2, puk) == 2
215
+
216
+
217
+ def test_decipher_rsa():
218
+ prk = rsa_private_key(2, 3, 1)
219
+ assert decipher_rsa(2, prk) == 2
220
+ prk = rsa_private_key(5, 3, 3)
221
+ assert decipher_rsa(8, prk) == 2
222
+
223
+ with warns(NonInvertibleCipherWarning):
224
+ prk = rsa_private_key(2, 2, 1)
225
+ assert decipher_rsa(2, prk) == 2
226
+
227
+
228
+ def test_mutltiprime_rsa_full_example():
229
+ # Test example from
230
+ # https://iopscience.iop.org/article/10.1088/1742-6596/995/1/012030
231
+ puk = rsa_public_key(2, 3, 5, 7, 11, 13, 7)
232
+ prk = rsa_private_key(2, 3, 5, 7, 11, 13, 7)
233
+ assert puk == (30030, 7)
234
+ assert prk == (30030, 823)
235
+
236
+ msg = 10
237
+ encrypted = encipher_rsa(2 * msg - 15, puk)
238
+ assert encrypted == 18065
239
+ decrypted = (decipher_rsa(encrypted, prk) + 15) / 2
240
+ assert decrypted == msg
241
+
242
+ # Test example from
243
+ # https://www.scirp.org/pdf/JCC_2018032215502008.pdf
244
+ puk1 = rsa_public_key(53, 41, 43, 47, 41)
245
+ prk1 = rsa_private_key(53, 41, 43, 47, 41)
246
+ puk2 = rsa_public_key(53, 41, 43, 47, 97)
247
+ prk2 = rsa_private_key(53, 41, 43, 47, 97)
248
+
249
+ assert puk1 == (4391633, 41)
250
+ assert prk1 == (4391633, 294041)
251
+ assert puk2 == (4391633, 97)
252
+ assert prk2 == (4391633, 455713)
253
+
254
+ msg = 12321
255
+ encrypted = encipher_rsa(encipher_rsa(msg, puk1), puk2)
256
+ assert encrypted == 1081588
257
+ decrypted = decipher_rsa(decipher_rsa(encrypted, prk2), prk1)
258
+ assert decrypted == msg
259
+
260
+
261
+ def test_rsa_crt_extreme():
262
+ p = int(
263
+ '10177157607154245068023861503693082120906487143725062283406501' \
264
+ '54082258226204046999838297167140821364638180697194879500245557' \
265
+ '65445186962893346463841419427008800341257468600224049986260471' \
266
+ '92257248163014468841725476918639415726709736077813632961290911' \
267
+ '0256421232977833028677441206049309220354796014376698325101693')
268
+
269
+ q = int(
270
+ '28752342353095132872290181526607275886182793241660805077850801' \
271
+ '75689512797754286972952273553128181861830576836289738668745250' \
272
+ '34028199691128870676414118458442900035778874482624765513861643' \
273
+ '27966696316822188398336199002306588703902894100476186823849595' \
274
+ '103239410527279605442148285816149368667083114802852804976893')
275
+
276
+ r = int(
277
+ '17698229259868825776879500736350186838850961935956310134378261' \
278
+ '89771862186717463067541369694816245225291921138038800171125596' \
279
+ '07315449521981157084370187887650624061033066022458512942411841' \
280
+ '18747893789972315277160085086164119879536041875335384844820566' \
281
+ '0287479617671726408053319619892052000850883994343378882717849')
282
+
283
+ s = int(
284
+ '68925428438585431029269182233502611027091755064643742383515623' \
285
+ '64321310582896893395529367074942808353187138794422745718419645' \
286
+ '28291231865157212604266903677599180789896916456120289112752835' \
287
+ '98502265889669730331688206825220074713977607415178738015831030' \
288
+ '364290585369150502819743827343552098197095520550865360159439'
289
+ )
290
+
291
+ t = int(
292
+ '69035483433453632820551311892368908779778144568711455301541094' \
293
+ '31487047642322695357696860925747923189635033183069823820910521' \
294
+ '71172909106797748883261493224162414050106920442445896819806600' \
295
+ '15448444826108008217972129130625571421904893252804729877353352' \
296
+ '739420480574842850202181462656251626522910618936534699566291'
297
+ )
298
+
299
+ e = 65537
300
+ puk = rsa_public_key(p, q, r, s, t, e)
301
+ prk = rsa_private_key(p, q, r, s, t, e)
302
+
303
+ plaintext = 1000
304
+ ciphertext_1 = encipher_rsa(plaintext, puk)
305
+ ciphertext_2 = encipher_rsa(plaintext, puk, [p, q, r, s, t])
306
+ assert ciphertext_1 == ciphertext_2
307
+ assert decipher_rsa(ciphertext_1, prk) == \
308
+ decipher_rsa(ciphertext_1, prk, [p, q, r, s, t])
309
+
310
+
311
+ def test_rsa_exhaustive():
312
+ p, q = 61, 53
313
+ e = 17
314
+ puk = rsa_public_key(p, q, e, totient='Carmichael')
315
+ prk = rsa_private_key(p, q, e, totient='Carmichael')
316
+
317
+ for msg in range(puk[0]):
318
+ encrypted = encipher_rsa(msg, puk)
319
+ decrypted = decipher_rsa(encrypted, prk)
320
+ try:
321
+ assert decrypted == msg
322
+ except AssertionError:
323
+ raise AssertionError(
324
+ "The RSA is not correctly decrypted " \
325
+ "(Original : {}, Encrypted : {}, Decrypted : {})" \
326
+ .format(msg, encrypted, decrypted)
327
+ )
328
+
329
+
330
+ def test_rsa_multiprime_exhanstive():
331
+ primes = [3, 5, 7, 11]
332
+ e = 7
333
+ args = primes + [e]
334
+ puk = rsa_public_key(*args, totient='Carmichael')
335
+ prk = rsa_private_key(*args, totient='Carmichael')
336
+ n = puk[0]
337
+
338
+ for msg in range(n):
339
+ encrypted = encipher_rsa(msg, puk)
340
+ decrypted = decipher_rsa(encrypted, prk)
341
+ try:
342
+ assert decrypted == msg
343
+ except AssertionError:
344
+ raise AssertionError(
345
+ "The RSA is not correctly decrypted " \
346
+ "(Original : {}, Encrypted : {}, Decrypted : {})" \
347
+ .format(msg, encrypted, decrypted)
348
+ )
349
+
350
+
351
+ def test_rsa_multipower_exhanstive():
352
+ primes = [5, 5, 7]
353
+ e = 7
354
+ args = primes + [e]
355
+ puk = rsa_public_key(*args, multipower=True)
356
+ prk = rsa_private_key(*args, multipower=True)
357
+ n = puk[0]
358
+
359
+ for msg in range(n):
360
+ if gcd(msg, n) != 1:
361
+ continue
362
+
363
+ encrypted = encipher_rsa(msg, puk)
364
+ decrypted = decipher_rsa(encrypted, prk)
365
+ try:
366
+ assert decrypted == msg
367
+ except AssertionError:
368
+ raise AssertionError(
369
+ "The RSA is not correctly decrypted " \
370
+ "(Original : {}, Encrypted : {}, Decrypted : {})" \
371
+ .format(msg, encrypted, decrypted)
372
+ )
373
+
374
+
375
+ def test_kid_rsa_public_key():
376
+ assert kid_rsa_public_key(1, 2, 1, 1) == (5, 2)
377
+ assert kid_rsa_public_key(1, 2, 2, 1) == (8, 3)
378
+ assert kid_rsa_public_key(1, 2, 1, 2) == (7, 2)
379
+
380
+
381
+ def test_kid_rsa_private_key():
382
+ assert kid_rsa_private_key(1, 2, 1, 1) == (5, 3)
383
+ assert kid_rsa_private_key(1, 2, 2, 1) == (8, 3)
384
+ assert kid_rsa_private_key(1, 2, 1, 2) == (7, 4)
385
+
386
+
387
+ def test_encipher_kid_rsa():
388
+ assert encipher_kid_rsa(1, (5, 2)) == 2
389
+ assert encipher_kid_rsa(1, (8, 3)) == 3
390
+ assert encipher_kid_rsa(1, (7, 2)) == 2
391
+
392
+
393
+ def test_decipher_kid_rsa():
394
+ assert decipher_kid_rsa(2, (5, 3)) == 1
395
+ assert decipher_kid_rsa(3, (8, 3)) == 1
396
+ assert decipher_kid_rsa(2, (7, 4)) == 1
397
+
398
+
399
+ def test_encode_morse():
400
+ assert encode_morse('ABC') == '.-|-...|-.-.'
401
+ assert encode_morse('SMS ') == '...|--|...||'
402
+ assert encode_morse('SMS\n') == '...|--|...||'
403
+ assert encode_morse('') == ''
404
+ assert encode_morse(' ') == '||'
405
+ assert encode_morse(' ', sep='`') == '``'
406
+ assert encode_morse(' ', sep='``') == '````'
407
+ assert encode_morse('!@#$%^&*()_+') == '-.-.--|.--.-.|...-..-|-.--.|-.--.-|..--.-|.-.-.'
408
+ assert encode_morse('12345') == '.----|..---|...--|....-|.....'
409
+ assert encode_morse('67890') == '-....|--...|---..|----.|-----'
410
+
411
+
412
+ def test_decode_morse():
413
+ assert decode_morse('-.-|.|-.--') == 'KEY'
414
+ assert decode_morse('.-.|..-|-.||') == 'RUN'
415
+ raises(KeyError, lambda: decode_morse('.....----'))
416
+
417
+
418
+ def test_lfsr_sequence():
419
+ raises(TypeError, lambda: lfsr_sequence(1, [1], 1))
420
+ raises(TypeError, lambda: lfsr_sequence([1], 1, 1))
421
+ F = FF(2)
422
+ assert lfsr_sequence([F(1)], [F(1)], 2) == [F(1), F(1)]
423
+ assert lfsr_sequence([F(0)], [F(1)], 2) == [F(1), F(0)]
424
+ F = FF(3)
425
+ assert lfsr_sequence([F(1)], [F(1)], 2) == [F(1), F(1)]
426
+ assert lfsr_sequence([F(0)], [F(2)], 2) == [F(2), F(0)]
427
+ assert lfsr_sequence([F(1)], [F(2)], 2) == [F(2), F(2)]
428
+
429
+
430
+ def test_lfsr_autocorrelation():
431
+ raises(TypeError, lambda: lfsr_autocorrelation(1, 2, 3))
432
+ F = FF(2)
433
+ s = lfsr_sequence([F(1), F(0)], [F(0), F(1)], 5)
434
+ assert lfsr_autocorrelation(s, 2, 0) == 1
435
+ assert lfsr_autocorrelation(s, 2, 1) == -1
436
+
437
+
438
+ def test_lfsr_connection_polynomial():
439
+ F = FF(2)
440
+ x = symbols("x")
441
+ s = lfsr_sequence([F(1), F(0)], [F(0), F(1)], 5)
442
+ assert lfsr_connection_polynomial(s) == x**2 + 1
443
+ s = lfsr_sequence([F(1), F(1)], [F(0), F(1)], 5)
444
+ assert lfsr_connection_polynomial(s) == x**2 + x + 1
445
+
446
+
447
+ def test_elgamal_private_key():
448
+ a, b, _ = elgamal_private_key(digit=100)
449
+ assert isprime(a)
450
+ assert is_primitive_root(b, a)
451
+ assert len(bin(a)) >= 102
452
+
453
+
454
+ def test_elgamal():
455
+ dk = elgamal_private_key(5)
456
+ ek = elgamal_public_key(dk)
457
+ P = ek[0]
458
+ assert P - 1 == decipher_elgamal(encipher_elgamal(P - 1, ek), dk)
459
+ raises(ValueError, lambda: encipher_elgamal(P, dk))
460
+ raises(ValueError, lambda: encipher_elgamal(-1, dk))
461
+
462
+
463
+ def test_dh_private_key():
464
+ p, g, _ = dh_private_key(digit = 100)
465
+ assert isprime(p)
466
+ assert is_primitive_root(g, p)
467
+ assert len(bin(p)) >= 102
468
+
469
+
470
+ def test_dh_public_key():
471
+ p1, g1, a = dh_private_key(digit = 100)
472
+ p2, g2, ga = dh_public_key((p1, g1, a))
473
+ assert p1 == p2
474
+ assert g1 == g2
475
+ assert ga == pow(g1, a, p1)
476
+
477
+
478
+ def test_dh_shared_key():
479
+ prk = dh_private_key(digit = 100)
480
+ p, _, ga = dh_public_key(prk)
481
+ b = randrange(2, p)
482
+ sk = dh_shared_key((p, _, ga), b)
483
+ assert sk == pow(ga, b, p)
484
+ raises(ValueError, lambda: dh_shared_key((1031, 14, 565), 2000))
485
+
486
+
487
+ def test_padded_key():
488
+ assert padded_key('b', 'ab') == 'ba'
489
+ raises(ValueError, lambda: padded_key('ab', 'ace'))
490
+ raises(ValueError, lambda: padded_key('ab', 'abba'))
491
+
492
+
493
+ def test_bifid():
494
+ raises(ValueError, lambda: encipher_bifid('abc', 'b', 'abcde'))
495
+ assert encipher_bifid('abc', 'b', 'abcd') == 'bdb'
496
+ raises(ValueError, lambda: decipher_bifid('bdb', 'b', 'abcde'))
497
+ assert encipher_bifid('bdb', 'b', 'abcd') == 'abc'
498
+ raises(ValueError, lambda: bifid_square('abcde'))
499
+ assert bifid5_square("B") == \
500
+ bifid5_square('BACDEFGHIKLMNOPQRSTUVWXYZ')
501
+ assert bifid6_square('B0') == \
502
+ bifid6_square('B0ACDEFGHIJKLMNOPQRSTUVWXYZ123456789')
503
+
504
+
505
+ def test_encipher_decipher_gm():
506
+ ps = [131, 137, 139, 149, 151, 157, 163, 167,
507
+ 173, 179, 181, 191, 193, 197, 199]
508
+ qs = [89, 97, 101, 103, 107, 109, 113, 127,
509
+ 131, 137, 139, 149, 151, 157, 47]
510
+ messages = [
511
+ 0, 32855, 34303, 14805, 1280, 75859, 38368,
512
+ 724, 60356, 51675, 76697, 61854, 18661,
513
+ ]
514
+ for p, q in zip(ps, qs):
515
+ pri = gm_private_key(p, q)
516
+ for msg in messages:
517
+ pub = gm_public_key(p, q)
518
+ enc = encipher_gm(msg, pub)
519
+ dec = decipher_gm(enc, pri)
520
+ assert dec == msg
521
+
522
+
523
+ def test_gm_private_key():
524
+ raises(ValueError, lambda: gm_public_key(13, 15))
525
+ raises(ValueError, lambda: gm_public_key(0, 0))
526
+ raises(ValueError, lambda: gm_public_key(0, 5))
527
+ assert 17, 19 == gm_public_key(17, 19)
528
+
529
+
530
+ def test_gm_public_key():
531
+ assert 323 == gm_public_key(17, 19)[1]
532
+ assert 15 == gm_public_key(3, 5)[1]
533
+ raises(ValueError, lambda: gm_public_key(15, 19))
534
+
535
+ def test_encipher_decipher_bg():
536
+ ps = [67, 7, 71, 103, 11, 43, 107, 47,
537
+ 79, 19, 83, 23, 59, 127, 31]
538
+ qs = qs = [7, 71, 103, 11, 43, 107, 47,
539
+ 79, 19, 83, 23, 59, 127, 31, 67]
540
+ messages = [
541
+ 0, 328, 343, 148, 1280, 758, 383,
542
+ 724, 603, 516, 766, 618, 186,
543
+ ]
544
+
545
+ for p, q in zip(ps, qs):
546
+ pri = bg_private_key(p, q)
547
+ for msg in messages:
548
+ pub = bg_public_key(p, q)
549
+ enc = encipher_bg(msg, pub)
550
+ dec = decipher_bg(enc, pri)
551
+ assert dec == msg
552
+
553
+ def test_bg_private_key():
554
+ raises(ValueError, lambda: bg_private_key(8, 16))
555
+ raises(ValueError, lambda: bg_private_key(8, 8))
556
+ raises(ValueError, lambda: bg_private_key(13, 17))
557
+ assert 23, 31 == bg_private_key(23, 31)
558
+
559
+ def test_bg_public_key():
560
+ assert 5293 == bg_public_key(67, 79)
561
+ assert 713 == bg_public_key(23, 31)
562
+ raises(ValueError, lambda: bg_private_key(13, 17))
openflamingo/lib/python3.10/site-packages/sympy/series/__pycache__/limits.cpython-310.pyc ADDED
Binary file (9.31 kB). View file
 
openflamingo/lib/python3.10/site-packages/sympy/series/benchmarks/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (181 Bytes). View file
 
openflamingo/lib/python3.10/site-packages/sympy/series/benchmarks/__pycache__/bench_order.cpython-310.pyc ADDED
Binary file (643 Bytes). View file
 
openflamingo/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)
openflamingo/lib/python3.10/site-packages/sympy/sets/__pycache__/conditionset.cpython-310.pyc ADDED
Binary file (7.59 kB). View file
 
openflamingo/lib/python3.10/site-packages/sympy/sets/__pycache__/contains.cpython-310.pyc ADDED
Binary file (2.18 kB). View file
 
openflamingo/lib/python3.10/site-packages/sympy/sets/__pycache__/ordinals.cpython-310.pyc ADDED
Binary file (8.43 kB). View file
 
openflamingo/lib/python3.10/site-packages/sympy/sets/__pycache__/setexpr.cpython-310.pyc ADDED
Binary file (3.4 kB). View file
 
openflamingo/lib/python3.10/site-packages/sympy/sets/handlers/intersection.py ADDED
@@ -0,0 +1,533 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sympy.core.basic import _aresame
2
+ from sympy.core.function import Lambda, expand_complex
3
+ from sympy.core.mul import Mul
4
+ from sympy.core.numbers import ilcm, Float
5
+ from sympy.core.relational import Eq
6
+ from sympy.core.singleton import S
7
+ from sympy.core.symbol import (Dummy, symbols)
8
+ from sympy.core.sorting import ordered
9
+ from sympy.functions.elementary.complexes import sign
10
+ from sympy.functions.elementary.integers import floor, ceiling
11
+ from sympy.sets.fancysets import ComplexRegion
12
+ from sympy.sets.sets import (FiniteSet, Intersection, Interval, Set, Union)
13
+ from sympy.multipledispatch import Dispatcher
14
+ from sympy.sets.conditionset import ConditionSet
15
+ from sympy.sets.fancysets import (Integers, Naturals, Reals, Range,
16
+ ImageSet, Rationals)
17
+ from sympy.sets.sets import EmptySet, UniversalSet, imageset, ProductSet
18
+ from sympy.simplify.radsimp import numer
19
+
20
+
21
+ intersection_sets = Dispatcher('intersection_sets')
22
+
23
+
24
+ @intersection_sets.register(ConditionSet, ConditionSet)
25
+ def _(a, b):
26
+ return None
27
+
28
+ @intersection_sets.register(ConditionSet, Set)
29
+ def _(a, b):
30
+ return ConditionSet(a.sym, a.condition, Intersection(a.base_set, b))
31
+
32
+ @intersection_sets.register(Naturals, Integers)
33
+ def _(a, b):
34
+ return a
35
+
36
+ @intersection_sets.register(Naturals, Naturals)
37
+ def _(a, b):
38
+ return a if a is S.Naturals else b
39
+
40
+ @intersection_sets.register(Interval, Naturals)
41
+ def _(a, b):
42
+ return intersection_sets(b, a)
43
+
44
+ @intersection_sets.register(ComplexRegion, Set)
45
+ def _(self, other):
46
+ if other.is_ComplexRegion:
47
+ # self in rectangular form
48
+ if (not self.polar) and (not other.polar):
49
+ return ComplexRegion(Intersection(self.sets, other.sets))
50
+
51
+ # self in polar form
52
+ elif self.polar and other.polar:
53
+ r1, theta1 = self.a_interval, self.b_interval
54
+ r2, theta2 = other.a_interval, other.b_interval
55
+ new_r_interval = Intersection(r1, r2)
56
+ new_theta_interval = Intersection(theta1, theta2)
57
+
58
+ # 0 and 2*Pi means the same
59
+ if ((2*S.Pi in theta1 and S.Zero in theta2) or
60
+ (2*S.Pi in theta2 and S.Zero in theta1)):
61
+ new_theta_interval = Union(new_theta_interval,
62
+ FiniteSet(0))
63
+ return ComplexRegion(new_r_interval*new_theta_interval,
64
+ polar=True)
65
+
66
+
67
+ if other.is_subset(S.Reals):
68
+ new_interval = []
69
+ x = symbols("x", cls=Dummy, real=True)
70
+
71
+ # self in rectangular form
72
+ if not self.polar:
73
+ for element in self.psets:
74
+ if S.Zero in element.args[1]:
75
+ new_interval.append(element.args[0])
76
+ new_interval = Union(*new_interval)
77
+ return Intersection(new_interval, other)
78
+
79
+ # self in polar form
80
+ elif self.polar:
81
+ for element in self.psets:
82
+ if S.Zero in element.args[1]:
83
+ new_interval.append(element.args[0])
84
+ if S.Pi in element.args[1]:
85
+ new_interval.append(ImageSet(Lambda(x, -x), element.args[0]))
86
+ if S.Zero in element.args[0]:
87
+ new_interval.append(FiniteSet(0))
88
+ new_interval = Union(*new_interval)
89
+ return Intersection(new_interval, other)
90
+
91
+ @intersection_sets.register(Integers, Reals)
92
+ def _(a, b):
93
+ return a
94
+
95
+ @intersection_sets.register(Range, Interval)
96
+ def _(a, b):
97
+ # Check that there are no symbolic arguments
98
+ if not all(i.is_number for i in a.args + b.args[:2]):
99
+ return
100
+
101
+ # In case of null Range, return an EmptySet.
102
+ if a.size == 0:
103
+ return S.EmptySet
104
+
105
+ # trim down to self's size, and represent
106
+ # as a Range with step 1.
107
+ start = ceiling(max(b.inf, a.inf))
108
+ if start not in b:
109
+ start += 1
110
+ end = floor(min(b.sup, a.sup))
111
+ if end not in b:
112
+ end -= 1
113
+ return intersection_sets(a, Range(start, end + 1))
114
+
115
+ @intersection_sets.register(Range, Naturals)
116
+ def _(a, b):
117
+ return intersection_sets(a, Interval(b.inf, S.Infinity))
118
+
119
+ @intersection_sets.register(Range, Range)
120
+ def _(a, b):
121
+ # Check that there are no symbolic range arguments
122
+ if not all(all(v.is_number for v in r.args) for r in [a, b]):
123
+ return None
124
+
125
+ # non-overlap quick exits
126
+ if not b:
127
+ return S.EmptySet
128
+ if not a:
129
+ return S.EmptySet
130
+ if b.sup < a.inf:
131
+ return S.EmptySet
132
+ if b.inf > a.sup:
133
+ return S.EmptySet
134
+
135
+ # work with finite end at the start
136
+ r1 = a
137
+ if r1.start.is_infinite:
138
+ r1 = r1.reversed
139
+ r2 = b
140
+ if r2.start.is_infinite:
141
+ r2 = r2.reversed
142
+
143
+ # If both ends are infinite then it means that one Range is just the set
144
+ # of all integers (the step must be 1).
145
+ if r1.start.is_infinite:
146
+ return b
147
+ if r2.start.is_infinite:
148
+ return a
149
+
150
+ from sympy.solvers.diophantine.diophantine import diop_linear
151
+
152
+ # this equation represents the values of the Range;
153
+ # it's a linear equation
154
+ eq = lambda r, i: r.start + i*r.step
155
+
156
+ # we want to know when the two equations might
157
+ # have integer solutions so we use the diophantine
158
+ # solver
159
+ va, vb = diop_linear(eq(r1, Dummy('a')) - eq(r2, Dummy('b')))
160
+
161
+ # check for no solution
162
+ no_solution = va is None and vb is None
163
+ if no_solution:
164
+ return S.EmptySet
165
+
166
+ # there is a solution
167
+ # -------------------
168
+
169
+ # find the coincident point, c
170
+ a0 = va.as_coeff_Add()[0]
171
+ c = eq(r1, a0)
172
+
173
+ # find the first point, if possible, in each range
174
+ # since c may not be that point
175
+ def _first_finite_point(r1, c):
176
+ if c == r1.start:
177
+ return c
178
+ # st is the signed step we need to take to
179
+ # get from c to r1.start
180
+ st = sign(r1.start - c)*step
181
+ # use Range to calculate the first point:
182
+ # we want to get as close as possible to
183
+ # r1.start; the Range will not be null since
184
+ # it will at least contain c
185
+ s1 = Range(c, r1.start + st, st)[-1]
186
+ if s1 == r1.start:
187
+ pass
188
+ else:
189
+ # if we didn't hit r1.start then, if the
190
+ # sign of st didn't match the sign of r1.step
191
+ # we are off by one and s1 is not in r1
192
+ if sign(r1.step) != sign(st):
193
+ s1 -= st
194
+ if s1 not in r1:
195
+ return
196
+ return s1
197
+
198
+ # calculate the step size of the new Range
199
+ step = abs(ilcm(r1.step, r2.step))
200
+ s1 = _first_finite_point(r1, c)
201
+ if s1 is None:
202
+ return S.EmptySet
203
+ s2 = _first_finite_point(r2, c)
204
+ if s2 is None:
205
+ return S.EmptySet
206
+
207
+ # replace the corresponding start or stop in
208
+ # the original Ranges with these points; the
209
+ # result must have at least one point since
210
+ # we know that s1 and s2 are in the Ranges
211
+ def _updated_range(r, first):
212
+ st = sign(r.step)*step
213
+ if r.start.is_finite:
214
+ rv = Range(first, r.stop, st)
215
+ else:
216
+ rv = Range(r.start, first + st, st)
217
+ return rv
218
+ r1 = _updated_range(a, s1)
219
+ r2 = _updated_range(b, s2)
220
+
221
+ # work with them both in the increasing direction
222
+ if sign(r1.step) < 0:
223
+ r1 = r1.reversed
224
+ if sign(r2.step) < 0:
225
+ r2 = r2.reversed
226
+
227
+ # return clipped Range with positive step; it
228
+ # can't be empty at this point
229
+ start = max(r1.start, r2.start)
230
+ stop = min(r1.stop, r2.stop)
231
+ return Range(start, stop, step)
232
+
233
+
234
+ @intersection_sets.register(Range, Integers)
235
+ def _(a, b):
236
+ return a
237
+
238
+
239
+ @intersection_sets.register(Range, Rationals)
240
+ def _(a, b):
241
+ return a
242
+
243
+
244
+ @intersection_sets.register(ImageSet, Set)
245
+ def _(self, other):
246
+ from sympy.solvers.diophantine import diophantine
247
+
248
+ # Only handle the straight-forward univariate case
249
+ if (len(self.lamda.variables) > 1
250
+ or self.lamda.signature != self.lamda.variables):
251
+ return None
252
+ base_set = self.base_sets[0]
253
+
254
+ # Intersection between ImageSets with Integers as base set
255
+ # For {f(n) : n in Integers} & {g(m) : m in Integers} we solve the
256
+ # diophantine equations f(n)=g(m).
257
+ # If the solutions for n are {h(t) : t in Integers} then we return
258
+ # {f(h(t)) : t in integers}.
259
+ # If the solutions for n are {n_1, n_2, ..., n_k} then we return
260
+ # {f(n_i) : 1 <= i <= k}.
261
+ if base_set is S.Integers:
262
+ gm = None
263
+ if isinstance(other, ImageSet) and other.base_sets == (S.Integers,):
264
+ gm = other.lamda.expr
265
+ var = other.lamda.variables[0]
266
+ # Symbol of second ImageSet lambda must be distinct from first
267
+ m = Dummy('m')
268
+ gm = gm.subs(var, m)
269
+ elif other is S.Integers:
270
+ m = gm = Dummy('m')
271
+ if gm is not None:
272
+ fn = self.lamda.expr
273
+ n = self.lamda.variables[0]
274
+ try:
275
+ solns = list(diophantine(fn - gm, syms=(n, m), permute=True))
276
+ except (TypeError, NotImplementedError):
277
+ # TypeError if equation not polynomial with rational coeff.
278
+ # NotImplementedError if correct format but no solver.
279
+ return
280
+ # 3 cases are possible for solns:
281
+ # - empty set,
282
+ # - one or more parametric (infinite) solutions,
283
+ # - a finite number of (non-parametric) solution couples.
284
+ # Among those, there is one type of solution set that is
285
+ # not helpful here: multiple parametric solutions.
286
+ if len(solns) == 0:
287
+ return S.EmptySet
288
+ elif any(s.free_symbols for tupl in solns for s in tupl):
289
+ if len(solns) == 1:
290
+ soln, solm = solns[0]
291
+ (t,) = soln.free_symbols
292
+ expr = fn.subs(n, soln.subs(t, n)).expand()
293
+ return imageset(Lambda(n, expr), S.Integers)
294
+ else:
295
+ return
296
+ else:
297
+ return FiniteSet(*(fn.subs(n, s[0]) for s in solns))
298
+
299
+ if other == S.Reals:
300
+ from sympy.solvers.solvers import denoms, solve_linear
301
+
302
+ def _solution_union(exprs, sym):
303
+ # return a union of linear solutions to i in expr;
304
+ # if i cannot be solved, use a ConditionSet for solution
305
+ sols = []
306
+ for i in exprs:
307
+ x, xis = solve_linear(i, 0, [sym])
308
+ if x == sym:
309
+ sols.append(FiniteSet(xis))
310
+ else:
311
+ sols.append(ConditionSet(sym, Eq(i, 0)))
312
+ return Union(*sols)
313
+
314
+ f = self.lamda.expr
315
+ n = self.lamda.variables[0]
316
+
317
+ n_ = Dummy(n.name, real=True)
318
+ f_ = f.subs(n, n_)
319
+
320
+ re, im = f_.as_real_imag()
321
+ im = expand_complex(im)
322
+
323
+ re = re.subs(n_, n)
324
+ im = im.subs(n_, n)
325
+ ifree = im.free_symbols
326
+ lam = Lambda(n, re)
327
+ if im.is_zero:
328
+ # allow re-evaluation
329
+ # of self in this case to make
330
+ # the result canonical
331
+ pass
332
+ elif im.is_zero is False:
333
+ return S.EmptySet
334
+ elif ifree != {n}:
335
+ return None
336
+ else:
337
+ # univarite imaginary part in same variable;
338
+ # use numer instead of as_numer_denom to keep
339
+ # this as fast as possible while still handling
340
+ # simple cases
341
+ base_set &= _solution_union(
342
+ Mul.make_args(numer(im)), n)
343
+ # exclude values that make denominators 0
344
+ base_set -= _solution_union(denoms(f), n)
345
+ return imageset(lam, base_set)
346
+
347
+ elif isinstance(other, Interval):
348
+ from sympy.solvers.solveset import (invert_real, invert_complex,
349
+ solveset)
350
+
351
+ f = self.lamda.expr
352
+ n = self.lamda.variables[0]
353
+ new_inf, new_sup = None, None
354
+ new_lopen, new_ropen = other.left_open, other.right_open
355
+
356
+ if f.is_real:
357
+ inverter = invert_real
358
+ else:
359
+ inverter = invert_complex
360
+
361
+ g1, h1 = inverter(f, other.inf, n)
362
+ g2, h2 = inverter(f, other.sup, n)
363
+
364
+ if all(isinstance(i, FiniteSet) for i in (h1, h2)):
365
+ if g1 == n:
366
+ if len(h1) == 1:
367
+ new_inf = h1.args[0]
368
+ if g2 == n:
369
+ if len(h2) == 1:
370
+ new_sup = h2.args[0]
371
+ # TODO: Design a technique to handle multiple-inverse
372
+ # functions
373
+
374
+ # Any of the new boundary values cannot be determined
375
+ if any(i is None for i in (new_sup, new_inf)):
376
+ return
377
+
378
+
379
+ range_set = S.EmptySet
380
+
381
+ if all(i.is_real for i in (new_sup, new_inf)):
382
+ # this assumes continuity of underlying function
383
+ # however fixes the case when it is decreasing
384
+ if new_inf > new_sup:
385
+ new_inf, new_sup = new_sup, new_inf
386
+ new_interval = Interval(new_inf, new_sup, new_lopen, new_ropen)
387
+ range_set = base_set.intersect(new_interval)
388
+ else:
389
+ if other.is_subset(S.Reals):
390
+ solutions = solveset(f, n, S.Reals)
391
+ if not isinstance(range_set, (ImageSet, ConditionSet)):
392
+ range_set = solutions.intersect(other)
393
+ else:
394
+ return
395
+
396
+ if range_set is S.EmptySet:
397
+ return S.EmptySet
398
+ elif isinstance(range_set, Range) and range_set.size is not S.Infinity:
399
+ range_set = FiniteSet(*list(range_set))
400
+
401
+ if range_set is not None:
402
+ return imageset(Lambda(n, f), range_set)
403
+ return
404
+ else:
405
+ return
406
+
407
+
408
+ @intersection_sets.register(ProductSet, ProductSet)
409
+ def _(a, b):
410
+ if len(b.args) != len(a.args):
411
+ return S.EmptySet
412
+ return ProductSet(*(i.intersect(j) for i, j in zip(a.sets, b.sets)))
413
+
414
+
415
+ @intersection_sets.register(Interval, Interval)
416
+ def _(a, b):
417
+ # handle (-oo, oo)
418
+ infty = S.NegativeInfinity, S.Infinity
419
+ if a == Interval(*infty):
420
+ l, r = a.left, a.right
421
+ if l.is_real or l in infty or r.is_real or r in infty:
422
+ return b
423
+
424
+ # We can't intersect [0,3] with [x,6] -- we don't know if x>0 or x<0
425
+ if not a._is_comparable(b):
426
+ return None
427
+
428
+ empty = False
429
+
430
+ if a.start <= b.end and b.start <= a.end:
431
+ # Get topology right.
432
+ if a.start < b.start:
433
+ start = b.start
434
+ left_open = b.left_open
435
+ elif a.start > b.start:
436
+ start = a.start
437
+ left_open = a.left_open
438
+ else:
439
+ start = a.start
440
+ if not _aresame(a.start, b.start):
441
+ # For example Integer(2) != Float(2)
442
+ # Prefer the Float boundary because Floats should be
443
+ # contagious in calculations.
444
+ if b.start.has(Float) and not a.start.has(Float):
445
+ start = b.start
446
+ elif a.start.has(Float) and not b.start.has(Float):
447
+ start = a.start
448
+ else:
449
+ #this is to ensure that if Eq(a.start, b.start) but
450
+ #type(a.start) != type(b.start) the order of a and b
451
+ #does not matter for the result
452
+ start = list(ordered([a,b]))[0].start
453
+ left_open = a.left_open or b.left_open
454
+
455
+ if a.end < b.end:
456
+ end = a.end
457
+ right_open = a.right_open
458
+ elif a.end > b.end:
459
+ end = b.end
460
+ right_open = b.right_open
461
+ else:
462
+ # see above for logic with start
463
+ end = a.end
464
+ if not _aresame(a.end, b.end):
465
+ if b.end.has(Float) and not a.end.has(Float):
466
+ end = b.end
467
+ elif a.end.has(Float) and not b.end.has(Float):
468
+ end = a.end
469
+ else:
470
+ end = list(ordered([a,b]))[0].end
471
+ right_open = a.right_open or b.right_open
472
+
473
+ if end - start == 0 and (left_open or right_open):
474
+ empty = True
475
+ else:
476
+ empty = True
477
+
478
+ if empty:
479
+ return S.EmptySet
480
+
481
+ return Interval(start, end, left_open, right_open)
482
+
483
+ @intersection_sets.register(EmptySet, Set)
484
+ def _(a, b):
485
+ return S.EmptySet
486
+
487
+ @intersection_sets.register(UniversalSet, Set)
488
+ def _(a, b):
489
+ return b
490
+
491
+ @intersection_sets.register(FiniteSet, FiniteSet)
492
+ def _(a, b):
493
+ return FiniteSet(*(a._elements & b._elements))
494
+
495
+ @intersection_sets.register(FiniteSet, Set)
496
+ def _(a, b):
497
+ try:
498
+ return FiniteSet(*[el for el in a if el in b])
499
+ except TypeError:
500
+ return None # could not evaluate `el in b` due to symbolic ranges.
501
+
502
+ @intersection_sets.register(Set, Set)
503
+ def _(a, b):
504
+ return None
505
+
506
+ @intersection_sets.register(Integers, Rationals)
507
+ def _(a, b):
508
+ return a
509
+
510
+ @intersection_sets.register(Naturals, Rationals)
511
+ def _(a, b):
512
+ return a
513
+
514
+ @intersection_sets.register(Rationals, Reals)
515
+ def _(a, b):
516
+ return a
517
+
518
+ def _intlike_interval(a, b):
519
+ try:
520
+ if b._inf is S.NegativeInfinity and b._sup is S.Infinity:
521
+ return a
522
+ s = Range(max(a.inf, ceiling(b.left)), floor(b.right) + 1)
523
+ return intersection_sets(s, b) # take out endpoints if open interval
524
+ except ValueError:
525
+ return None
526
+
527
+ @intersection_sets.register(Integers, Interval)
528
+ def _(a, b):
529
+ return _intlike_interval(a, b)
530
+
531
+ @intersection_sets.register(Naturals, Interval)
532
+ def _(a, b):
533
+ return _intlike_interval(a, b)
openflamingo/lib/python3.10/site-packages/sympy/sets/handlers/issubset.py ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sympy.core.singleton import S
2
+ from sympy.core.symbol import Symbol
3
+ from sympy.core.logic import fuzzy_and, fuzzy_bool, fuzzy_not, fuzzy_or
4
+ from sympy.core.relational import Eq
5
+ from sympy.sets.sets import FiniteSet, Interval, Set, Union, ProductSet
6
+ from sympy.sets.fancysets import Complexes, Reals, Range, Rationals
7
+ from sympy.multipledispatch import Dispatcher
8
+
9
+
10
+ _inf_sets = [S.Naturals, S.Naturals0, S.Integers, S.Rationals, S.Reals, S.Complexes]
11
+
12
+
13
+ is_subset_sets = Dispatcher('is_subset_sets')
14
+
15
+
16
+ @is_subset_sets.register(Set, Set)
17
+ def _(a, b):
18
+ return None
19
+
20
+ @is_subset_sets.register(Interval, Interval)
21
+ def _(a, b):
22
+ # This is correct but can be made more comprehensive...
23
+ if fuzzy_bool(a.start < b.start):
24
+ return False
25
+ if fuzzy_bool(a.end > b.end):
26
+ return False
27
+ if (b.left_open and not a.left_open and fuzzy_bool(Eq(a.start, b.start))):
28
+ return False
29
+ if (b.right_open and not a.right_open and fuzzy_bool(Eq(a.end, b.end))):
30
+ return False
31
+
32
+ @is_subset_sets.register(Interval, FiniteSet)
33
+ def _(a_interval, b_fs):
34
+ # An Interval can only be a subset of a finite set if it is finite
35
+ # which can only happen if it has zero measure.
36
+ if fuzzy_not(a_interval.measure.is_zero):
37
+ return False
38
+
39
+ @is_subset_sets.register(Interval, Union)
40
+ def _(a_interval, b_u):
41
+ if all(isinstance(s, (Interval, FiniteSet)) for s in b_u.args):
42
+ intervals = [s for s in b_u.args if isinstance(s, Interval)]
43
+ if all(fuzzy_bool(a_interval.start < s.start) for s in intervals):
44
+ return False
45
+ if all(fuzzy_bool(a_interval.end > s.end) for s in intervals):
46
+ return False
47
+ if a_interval.measure.is_nonzero:
48
+ no_overlap = lambda s1, s2: fuzzy_or([
49
+ fuzzy_bool(s1.end <= s2.start),
50
+ fuzzy_bool(s1.start >= s2.end),
51
+ ])
52
+ if all(no_overlap(s, a_interval) for s in intervals):
53
+ return False
54
+
55
+ @is_subset_sets.register(Range, Range)
56
+ def _(a, b):
57
+ if a.step == b.step == 1:
58
+ return fuzzy_and([fuzzy_bool(a.start >= b.start),
59
+ fuzzy_bool(a.stop <= b.stop)])
60
+
61
+ @is_subset_sets.register(Range, Interval)
62
+ def _(a_range, b_interval):
63
+ if a_range.step.is_positive:
64
+ if b_interval.left_open and a_range.inf.is_finite:
65
+ cond_left = a_range.inf > b_interval.left
66
+ else:
67
+ cond_left = a_range.inf >= b_interval.left
68
+ if b_interval.right_open and a_range.sup.is_finite:
69
+ cond_right = a_range.sup < b_interval.right
70
+ else:
71
+ cond_right = a_range.sup <= b_interval.right
72
+ return fuzzy_and([cond_left, cond_right])
73
+
74
+ @is_subset_sets.register(Range, FiniteSet)
75
+ def _(a_range, b_finiteset):
76
+ try:
77
+ a_size = a_range.size
78
+ except ValueError:
79
+ # symbolic Range of unknown size
80
+ return None
81
+ if a_size > len(b_finiteset):
82
+ return False
83
+ elif any(arg.has(Symbol) for arg in a_range.args):
84
+ return fuzzy_and(b_finiteset.contains(x) for x in a_range)
85
+ else:
86
+ # Checking A \ B == EmptySet is more efficient than repeated naive
87
+ # membership checks on an arbitrary FiniteSet.
88
+ a_set = set(a_range)
89
+ b_remaining = len(b_finiteset)
90
+ # Symbolic expressions and numbers of unknown type (integer or not) are
91
+ # all counted as "candidates", i.e. *potentially* matching some a in
92
+ # a_range.
93
+ cnt_candidate = 0
94
+ for b in b_finiteset:
95
+ if b.is_Integer:
96
+ a_set.discard(b)
97
+ elif fuzzy_not(b.is_integer):
98
+ pass
99
+ else:
100
+ cnt_candidate += 1
101
+ b_remaining -= 1
102
+ if len(a_set) > b_remaining + cnt_candidate:
103
+ return False
104
+ if len(a_set) == 0:
105
+ return True
106
+ return None
107
+
108
+ @is_subset_sets.register(Interval, Range)
109
+ def _(a_interval, b_range):
110
+ if a_interval.measure.is_extended_nonzero:
111
+ return False
112
+
113
+ @is_subset_sets.register(Interval, Rationals)
114
+ def _(a_interval, b_rationals):
115
+ if a_interval.measure.is_extended_nonzero:
116
+ return False
117
+
118
+ @is_subset_sets.register(Range, Complexes)
119
+ def _(a, b):
120
+ return True
121
+
122
+ @is_subset_sets.register(Complexes, Interval)
123
+ def _(a, b):
124
+ return False
125
+
126
+ @is_subset_sets.register(Complexes, Range)
127
+ def _(a, b):
128
+ return False
129
+
130
+ @is_subset_sets.register(Complexes, Rationals)
131
+ def _(a, b):
132
+ return False
133
+
134
+ @is_subset_sets.register(Rationals, Reals)
135
+ def _(a, b):
136
+ return True
137
+
138
+ @is_subset_sets.register(Rationals, Range)
139
+ def _(a, b):
140
+ return False
141
+
142
+ @is_subset_sets.register(ProductSet, FiniteSet)
143
+ def _(a_ps, b_fs):
144
+ return fuzzy_and(b_fs.contains(x) for x in a_ps)
openflamingo/lib/python3.10/site-packages/sympy/sets/handlers/power.py ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sympy.core import Basic, Expr
2
+ from sympy.core.function import Lambda
3
+ from sympy.core.numbers import oo, Infinity, NegativeInfinity, Zero, Integer
4
+ from sympy.core.singleton import S
5
+ from sympy.core.symbol import symbols
6
+ from sympy.functions.elementary.miscellaneous import (Max, Min)
7
+ from sympy.sets.fancysets import ImageSet
8
+ from sympy.sets.setexpr import set_div
9
+ from sympy.sets.sets import Set, Interval, FiniteSet, Union
10
+ from sympy.multipledispatch import Dispatcher
11
+
12
+
13
+ _x, _y = symbols("x y")
14
+
15
+
16
+ _set_pow = Dispatcher('_set_pow')
17
+
18
+
19
+ @_set_pow.register(Basic, Basic)
20
+ def _(x, y):
21
+ return None
22
+
23
+ @_set_pow.register(Set, Set)
24
+ def _(x, y):
25
+ return ImageSet(Lambda((_x, _y), (_x ** _y)), x, y)
26
+
27
+ @_set_pow.register(Expr, Expr)
28
+ def _(x, y):
29
+ return x**y
30
+
31
+ @_set_pow.register(Interval, Zero)
32
+ def _(x, z):
33
+ return FiniteSet(S.One)
34
+
35
+ @_set_pow.register(Interval, Integer)
36
+ def _(x, exponent):
37
+ """
38
+ Powers in interval arithmetic
39
+ https://en.wikipedia.org/wiki/Interval_arithmetic
40
+ """
41
+ s1 = x.start**exponent
42
+ s2 = x.end**exponent
43
+ if ((s2 > s1) if exponent > 0 else (x.end > -x.start)) == True:
44
+ left_open = x.left_open
45
+ right_open = x.right_open
46
+ # TODO: handle unevaluated condition.
47
+ sleft = s2
48
+ else:
49
+ # TODO: `s2 > s1` could be unevaluated.
50
+ left_open = x.right_open
51
+ right_open = x.left_open
52
+ sleft = s1
53
+
54
+ if x.start.is_positive:
55
+ return Interval(
56
+ Min(s1, s2),
57
+ Max(s1, s2), left_open, right_open)
58
+ elif x.end.is_negative:
59
+ return Interval(
60
+ Min(s1, s2),
61
+ Max(s1, s2), left_open, right_open)
62
+
63
+ # Case where x.start < 0 and x.end > 0:
64
+ if exponent.is_odd:
65
+ if exponent.is_negative:
66
+ if x.start.is_zero:
67
+ return Interval(s2, oo, x.right_open)
68
+ if x.end.is_zero:
69
+ return Interval(-oo, s1, True, x.left_open)
70
+ return Union(Interval(-oo, s1, True, x.left_open), Interval(s2, oo, x.right_open))
71
+ else:
72
+ return Interval(s1, s2, x.left_open, x.right_open)
73
+ elif exponent.is_even:
74
+ if exponent.is_negative:
75
+ if x.start.is_zero:
76
+ return Interval(s2, oo, x.right_open)
77
+ if x.end.is_zero:
78
+ return Interval(s1, oo, x.left_open)
79
+ return Interval(0, oo)
80
+ else:
81
+ return Interval(S.Zero, sleft, S.Zero not in x, left_open)
82
+
83
+ @_set_pow.register(Interval, Infinity)
84
+ def _(b, e):
85
+ # TODO: add logic for open intervals?
86
+ if b.start.is_nonnegative:
87
+ if b.end < 1:
88
+ return FiniteSet(S.Zero)
89
+ if b.start > 1:
90
+ return FiniteSet(S.Infinity)
91
+ return Interval(0, oo)
92
+ elif b.end.is_negative:
93
+ if b.start > -1:
94
+ return FiniteSet(S.Zero)
95
+ if b.end < -1:
96
+ return FiniteSet(-oo, oo)
97
+ return Interval(-oo, oo)
98
+ else:
99
+ if b.start > -1:
100
+ if b.end < 1:
101
+ return FiniteSet(S.Zero)
102
+ return Interval(0, oo)
103
+ return Interval(-oo, oo)
104
+
105
+ @_set_pow.register(Interval, NegativeInfinity)
106
+ def _(b, e):
107
+ return _set_pow(set_div(S.One, b), oo)
openflamingo/lib/python3.10/site-packages/sympy/sets/handlers/union.py ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sympy.core.singleton import S
2
+ from sympy.core.sympify import sympify
3
+ from sympy.functions.elementary.miscellaneous import Min, Max
4
+ from sympy.sets.sets import (EmptySet, FiniteSet, Intersection,
5
+ Interval, ProductSet, Set, Union, UniversalSet)
6
+ from sympy.sets.fancysets import (ComplexRegion, Naturals, Naturals0,
7
+ Integers, Rationals, Reals)
8
+ from sympy.multipledispatch import Dispatcher
9
+
10
+
11
+ union_sets = Dispatcher('union_sets')
12
+
13
+
14
+ @union_sets.register(Naturals0, Naturals)
15
+ def _(a, b):
16
+ return a
17
+
18
+ @union_sets.register(Rationals, Naturals)
19
+ def _(a, b):
20
+ return a
21
+
22
+ @union_sets.register(Rationals, Naturals0)
23
+ def _(a, b):
24
+ return a
25
+
26
+ @union_sets.register(Reals, Naturals)
27
+ def _(a, b):
28
+ return a
29
+
30
+ @union_sets.register(Reals, Naturals0)
31
+ def _(a, b):
32
+ return a
33
+
34
+ @union_sets.register(Reals, Rationals)
35
+ def _(a, b):
36
+ return a
37
+
38
+ @union_sets.register(Integers, Set)
39
+ def _(a, b):
40
+ intersect = Intersection(a, b)
41
+ if intersect == a:
42
+ return b
43
+ elif intersect == b:
44
+ return a
45
+
46
+ @union_sets.register(ComplexRegion, Set)
47
+ def _(a, b):
48
+ if b.is_subset(S.Reals):
49
+ # treat a subset of reals as a complex region
50
+ b = ComplexRegion.from_real(b)
51
+
52
+ if b.is_ComplexRegion:
53
+ # a in rectangular form
54
+ if (not a.polar) and (not b.polar):
55
+ return ComplexRegion(Union(a.sets, b.sets))
56
+ # a in polar form
57
+ elif a.polar and b.polar:
58
+ return ComplexRegion(Union(a.sets, b.sets), polar=True)
59
+ return None
60
+
61
+ @union_sets.register(EmptySet, Set)
62
+ def _(a, b):
63
+ return b
64
+
65
+
66
+ @union_sets.register(UniversalSet, Set)
67
+ def _(a, b):
68
+ return a
69
+
70
+ @union_sets.register(ProductSet, ProductSet)
71
+ def _(a, b):
72
+ if b.is_subset(a):
73
+ return a
74
+ if len(b.sets) != len(a.sets):
75
+ return None
76
+ if len(a.sets) == 2:
77
+ a1, a2 = a.sets
78
+ b1, b2 = b.sets
79
+ if a1 == b1:
80
+ return a1 * Union(a2, b2)
81
+ if a2 == b2:
82
+ return Union(a1, b1) * a2
83
+ return None
84
+
85
+ @union_sets.register(ProductSet, Set)
86
+ def _(a, b):
87
+ if b.is_subset(a):
88
+ return a
89
+ return None
90
+
91
+ @union_sets.register(Interval, Interval)
92
+ def _(a, b):
93
+ if a._is_comparable(b):
94
+ # Non-overlapping intervals
95
+ end = Min(a.end, b.end)
96
+ start = Max(a.start, b.start)
97
+ if (end < start or
98
+ (end == start and (end not in a and end not in b))):
99
+ return None
100
+ else:
101
+ start = Min(a.start, b.start)
102
+ end = Max(a.end, b.end)
103
+
104
+ left_open = ((a.start != start or a.left_open) and
105
+ (b.start != start or b.left_open))
106
+ right_open = ((a.end != end or a.right_open) and
107
+ (b.end != end or b.right_open))
108
+ return Interval(start, end, left_open, right_open)
109
+
110
+ @union_sets.register(Interval, UniversalSet)
111
+ def _(a, b):
112
+ return S.UniversalSet
113
+
114
+ @union_sets.register(Interval, Set)
115
+ def _(a, b):
116
+ # If I have open end points and these endpoints are contained in b
117
+ # But only in case, when endpoints are finite. Because
118
+ # interval does not contain oo or -oo.
119
+ open_left_in_b_and_finite = (a.left_open and
120
+ sympify(b.contains(a.start)) is S.true and
121
+ a.start.is_finite)
122
+ open_right_in_b_and_finite = (a.right_open and
123
+ sympify(b.contains(a.end)) is S.true and
124
+ a.end.is_finite)
125
+ if open_left_in_b_and_finite or open_right_in_b_and_finite:
126
+ # Fill in my end points and return
127
+ open_left = a.left_open and a.start not in b
128
+ open_right = a.right_open and a.end not in b
129
+ new_a = Interval(a.start, a.end, open_left, open_right)
130
+ return {new_a, b}
131
+ return None
132
+
133
+ @union_sets.register(FiniteSet, FiniteSet)
134
+ def _(a, b):
135
+ return FiniteSet(*(a._elements | b._elements))
136
+
137
+ @union_sets.register(FiniteSet, Set)
138
+ def _(a, b):
139
+ # If `b` set contains one of my elements, remove it from `a`
140
+ if any(b.contains(x) == True for x in a):
141
+ return {
142
+ FiniteSet(*[x for x in a if b.contains(x) != True]), b}
143
+ return None
144
+
145
+ @union_sets.register(Set, Set)
146
+ def _(a, b):
147
+ return None
openflamingo/lib/python3.10/site-packages/sympy/sets/tests/__pycache__/test_setexpr.cpython-310.pyc ADDED
Binary file (10 kB). View file
 
openflamingo/lib/python3.10/site-packages/sympy/sets/tests/__pycache__/test_sets.cpython-310.pyc ADDED
Binary file (64.2 kB). View file
 
phi4/lib/python3.10/site-packages/fsspec/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (1.44 kB). View file
 
phi4/lib/python3.10/site-packages/fsspec/__pycache__/_version.cpython-310.pyc ADDED
Binary file (535 Bytes). View file
 
phi4/lib/python3.10/site-packages/fsspec/__pycache__/archive.cpython-310.pyc ADDED
Binary file (2.87 kB). View file
 
phi4/lib/python3.10/site-packages/fsspec/__pycache__/asyn.cpython-310.pyc ADDED
Binary file (29.5 kB). View file
 
phi4/lib/python3.10/site-packages/fsspec/__pycache__/caching.cpython-310.pyc ADDED
Binary file (24.2 kB). View file
 
phi4/lib/python3.10/site-packages/fsspec/__pycache__/callbacks.cpython-310.pyc ADDED
Binary file (10.9 kB). View file
 
phi4/lib/python3.10/site-packages/fsspec/__pycache__/compression.cpython-310.pyc ADDED
Binary file (5.08 kB). View file
 
phi4/lib/python3.10/site-packages/fsspec/__pycache__/config.cpython-310.pyc ADDED
Binary file (3.81 kB). View file
 
phi4/lib/python3.10/site-packages/fsspec/__pycache__/conftest.cpython-310.pyc ADDED
Binary file (1.55 kB). View file
 
phi4/lib/python3.10/site-packages/fsspec/__pycache__/core.cpython-310.pyc ADDED
Binary file (22.4 kB). View file
 
phi4/lib/python3.10/site-packages/fsspec/__pycache__/dircache.cpython-310.pyc ADDED
Binary file (3.4 kB). View file
 
phi4/lib/python3.10/site-packages/fsspec/__pycache__/exceptions.cpython-310.pyc ADDED
Binary file (720 Bytes). View file
 
phi4/lib/python3.10/site-packages/fsspec/__pycache__/fuse.cpython-310.pyc ADDED
Binary file (10.1 kB). View file
 
phi4/lib/python3.10/site-packages/fsspec/__pycache__/generic.cpython-310.pyc ADDED
Binary file (12.7 kB). View file
 
phi4/lib/python3.10/site-packages/fsspec/__pycache__/gui.cpython-310.pyc ADDED
Binary file (14.6 kB). View file
 
phi4/lib/python3.10/site-packages/fsspec/__pycache__/json.cpython-310.pyc ADDED
Binary file (4.57 kB). View file
 
phi4/lib/python3.10/site-packages/fsspec/__pycache__/mapping.cpython-310.pyc ADDED
Binary file (9.05 kB). View file
 
phi4/lib/python3.10/site-packages/fsspec/__pycache__/parquet.cpython-310.pyc ADDED
Binary file (11.2 kB). View file
 
phi4/lib/python3.10/site-packages/fsspec/__pycache__/registry.cpython-310.pyc ADDED
Binary file (9.21 kB). View file
 
phi4/lib/python3.10/site-packages/fsspec/__pycache__/spec.cpython-310.pyc ADDED
Binary file (66 kB). View file
 
phi4/lib/python3.10/site-packages/fsspec/__pycache__/transaction.cpython-310.pyc ADDED
Binary file (3.19 kB). View file
 
phi4/lib/python3.10/site-packages/fsspec/__pycache__/utils.cpython-310.pyc ADDED
Binary file (20 kB). View file
 
phi4/lib/python3.10/site-packages/fsspec/implementations/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (172 Bytes). View file
 
phi4/lib/python3.10/site-packages/fsspec/implementations/__pycache__/cached.cpython-310.pyc ADDED
Binary file (28.8 kB). View file
 
phi4/lib/python3.10/site-packages/fsspec/implementations/__pycache__/dask.cpython-310.pyc ADDED
Binary file (4.74 kB). View file
 
phi4/lib/python3.10/site-packages/fsspec/tests/abstract/__init__.py ADDED
@@ -0,0 +1,289 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from hashlib import md5
3
+
4
+ import pytest
5
+
6
+ from fsspec.implementations.local import LocalFileSystem
7
+ from fsspec.tests.abstract.copy import AbstractCopyTests # noqa: F401
8
+ from fsspec.tests.abstract.get import AbstractGetTests # noqa: F401
9
+ from fsspec.tests.abstract.open import AbstractOpenTests # noqa: F401
10
+ from fsspec.tests.abstract.pipe import AbstractPipeTests # noqa: F401
11
+ from fsspec.tests.abstract.put import AbstractPutTests # noqa: F401
12
+
13
+
14
+ class BaseAbstractFixtures:
15
+ """
16
+ Abstract base class containing fixtures that are used by but never need to
17
+ be overridden in derived filesystem-specific classes to run the abstract
18
+ tests on such filesystems.
19
+ """
20
+
21
+ @pytest.fixture
22
+ def fs_bulk_operations_scenario_0(self, fs, fs_join, fs_path):
23
+ """
24
+ Scenario on remote filesystem that is used for many cp/get/put tests.
25
+
26
+ Cleans up at the end of each test it which it is used.
27
+ """
28
+ source = self._bulk_operations_scenario_0(fs, fs_join, fs_path)
29
+ yield source
30
+ fs.rm(source, recursive=True)
31
+
32
+ @pytest.fixture
33
+ def fs_glob_edge_cases_files(self, fs, fs_join, fs_path):
34
+ """
35
+ Scenario on remote filesystem that is used for glob edge cases cp/get/put tests.
36
+
37
+ Cleans up at the end of each test it which it is used.
38
+ """
39
+ source = self._glob_edge_cases_files(fs, fs_join, fs_path)
40
+ yield source
41
+ fs.rm(source, recursive=True)
42
+
43
+ @pytest.fixture
44
+ def fs_dir_and_file_with_same_name_prefix(self, fs, fs_join, fs_path):
45
+ """
46
+ Scenario on remote filesystem that is used to check cp/get/put on directory
47
+ and file with the same name prefixes.
48
+
49
+ Cleans up at the end of each test it which it is used.
50
+ """
51
+ source = self._dir_and_file_with_same_name_prefix(fs, fs_join, fs_path)
52
+ yield source
53
+ fs.rm(source, recursive=True)
54
+
55
+ @pytest.fixture
56
+ def fs_10_files_with_hashed_names(self, fs, fs_join, fs_path):
57
+ """
58
+ Scenario on remote filesystem that is used to check cp/get/put files order
59
+ when source and destination are lists.
60
+
61
+ Cleans up at the end of each test it which it is used.
62
+ """
63
+ source = self._10_files_with_hashed_names(fs, fs_join, fs_path)
64
+ yield source
65
+ fs.rm(source, recursive=True)
66
+
67
+ @pytest.fixture
68
+ def fs_target(self, fs, fs_join, fs_path):
69
+ """
70
+ Return name of remote directory that does not yet exist to copy into.
71
+
72
+ Cleans up at the end of each test it which it is used.
73
+ """
74
+ target = fs_join(fs_path, "target")
75
+ yield target
76
+ if fs.exists(target):
77
+ fs.rm(target, recursive=True)
78
+
79
+ @pytest.fixture
80
+ def local_bulk_operations_scenario_0(self, local_fs, local_join, local_path):
81
+ """
82
+ Scenario on local filesystem that is used for many cp/get/put tests.
83
+
84
+ Cleans up at the end of each test it which it is used.
85
+ """
86
+ source = self._bulk_operations_scenario_0(local_fs, local_join, local_path)
87
+ yield source
88
+ local_fs.rm(source, recursive=True)
89
+
90
+ @pytest.fixture
91
+ def local_glob_edge_cases_files(self, local_fs, local_join, local_path):
92
+ """
93
+ Scenario on local filesystem that is used for glob edge cases cp/get/put tests.
94
+
95
+ Cleans up at the end of each test it which it is used.
96
+ """
97
+ source = self._glob_edge_cases_files(local_fs, local_join, local_path)
98
+ yield source
99
+ local_fs.rm(source, recursive=True)
100
+
101
+ @pytest.fixture
102
+ def local_dir_and_file_with_same_name_prefix(
103
+ self, local_fs, local_join, local_path
104
+ ):
105
+ """
106
+ Scenario on local filesystem that is used to check cp/get/put on directory
107
+ and file with the same name prefixes.
108
+
109
+ Cleans up at the end of each test it which it is used.
110
+ """
111
+ source = self._dir_and_file_with_same_name_prefix(
112
+ local_fs, local_join, local_path
113
+ )
114
+ yield source
115
+ local_fs.rm(source, recursive=True)
116
+
117
+ @pytest.fixture
118
+ def local_10_files_with_hashed_names(self, local_fs, local_join, local_path):
119
+ """
120
+ Scenario on local filesystem that is used to check cp/get/put files order
121
+ when source and destination are lists.
122
+
123
+ Cleans up at the end of each test it which it is used.
124
+ """
125
+ source = self._10_files_with_hashed_names(local_fs, local_join, local_path)
126
+ yield source
127
+ local_fs.rm(source, recursive=True)
128
+
129
+ @pytest.fixture
130
+ def local_target(self, local_fs, local_join, local_path):
131
+ """
132
+ Return name of local directory that does not yet exist to copy into.
133
+
134
+ Cleans up at the end of each test it which it is used.
135
+ """
136
+ target = local_join(local_path, "target")
137
+ yield target
138
+ if local_fs.exists(target):
139
+ local_fs.rm(target, recursive=True)
140
+
141
+ def _glob_edge_cases_files(self, some_fs, some_join, some_path):
142
+ """
143
+ Scenario that is used for glob edge cases cp/get/put tests.
144
+ Creates the following directory and file structure:
145
+
146
+ πŸ“ source
147
+ β”œβ”€β”€ πŸ“„ file1
148
+ β”œβ”€β”€ πŸ“„ file2
149
+ β”œβ”€β”€ πŸ“ subdir0
150
+ β”‚ β”œβ”€β”€ πŸ“„ subfile1
151
+ β”‚ β”œβ”€β”€ πŸ“„ subfile2
152
+ β”‚ └── πŸ“ nesteddir
153
+ β”‚ └── πŸ“„ nestedfile
154
+ └── πŸ“ subdir1
155
+ β”œβ”€β”€ πŸ“„ subfile1
156
+ β”œβ”€β”€ πŸ“„ subfile2
157
+ └── πŸ“ nesteddir
158
+ └── πŸ“„ nestedfile
159
+ """
160
+ source = some_join(some_path, "source")
161
+ some_fs.touch(some_join(source, "file1"))
162
+ some_fs.touch(some_join(source, "file2"))
163
+
164
+ for subdir_idx in range(2):
165
+ subdir = some_join(source, f"subdir{subdir_idx}")
166
+ nesteddir = some_join(subdir, "nesteddir")
167
+ some_fs.makedirs(nesteddir)
168
+ some_fs.touch(some_join(subdir, "subfile1"))
169
+ some_fs.touch(some_join(subdir, "subfile2"))
170
+ some_fs.touch(some_join(nesteddir, "nestedfile"))
171
+
172
+ return source
173
+
174
+ def _bulk_operations_scenario_0(self, some_fs, some_join, some_path):
175
+ """
176
+ Scenario that is used for many cp/get/put tests. Creates the following
177
+ directory and file structure:
178
+
179
+ πŸ“ source
180
+ β”œβ”€β”€ πŸ“„ file1
181
+ β”œβ”€β”€ πŸ“„ file2
182
+ └── πŸ“ subdir
183
+ β”œβ”€β”€ πŸ“„ subfile1
184
+ β”œβ”€β”€ πŸ“„ subfile2
185
+ └── πŸ“ nesteddir
186
+ └── πŸ“„ nestedfile
187
+ """
188
+ source = some_join(some_path, "source")
189
+ subdir = some_join(source, "subdir")
190
+ nesteddir = some_join(subdir, "nesteddir")
191
+ some_fs.makedirs(nesteddir)
192
+ some_fs.touch(some_join(source, "file1"))
193
+ some_fs.touch(some_join(source, "file2"))
194
+ some_fs.touch(some_join(subdir, "subfile1"))
195
+ some_fs.touch(some_join(subdir, "subfile2"))
196
+ some_fs.touch(some_join(nesteddir, "nestedfile"))
197
+ return source
198
+
199
+ def _dir_and_file_with_same_name_prefix(self, some_fs, some_join, some_path):
200
+ """
201
+ Scenario that is used to check cp/get/put on directory and file with
202
+ the same name prefixes. Creates the following directory and file structure:
203
+
204
+ πŸ“ source
205
+ β”œβ”€β”€ πŸ“„ subdir.txt
206
+ └── πŸ“ subdir
207
+ └── πŸ“„ subfile.txt
208
+ """
209
+ source = some_join(some_path, "source")
210
+ subdir = some_join(source, "subdir")
211
+ file = some_join(source, "subdir.txt")
212
+ subfile = some_join(subdir, "subfile.txt")
213
+ some_fs.makedirs(subdir)
214
+ some_fs.touch(file)
215
+ some_fs.touch(subfile)
216
+ return source
217
+
218
+ def _10_files_with_hashed_names(self, some_fs, some_join, some_path):
219
+ """
220
+ Scenario that is used to check cp/get/put files order when source and
221
+ destination are lists. Creates the following directory and file structure:
222
+
223
+ πŸ“ source
224
+ └── πŸ“„ {hashed([0-9])}.txt
225
+ """
226
+ source = some_join(some_path, "source")
227
+ for i in range(10):
228
+ hashed_i = md5(str(i).encode("utf-8")).hexdigest()
229
+ path = some_join(source, f"{hashed_i}.txt")
230
+ some_fs.pipe(path=path, value=f"{i}".encode())
231
+ return source
232
+
233
+
234
+ class AbstractFixtures(BaseAbstractFixtures):
235
+ """
236
+ Abstract base class containing fixtures that may be overridden in derived
237
+ filesystem-specific classes to run the abstract tests on such filesystems.
238
+
239
+ For any particular filesystem some of these fixtures must be overridden,
240
+ such as ``fs`` and ``fs_path``, and others may be overridden if the
241
+ default functions here are not appropriate, such as ``fs_join``.
242
+ """
243
+
244
+ @pytest.fixture
245
+ def fs(self):
246
+ raise NotImplementedError("This function must be overridden in derived classes")
247
+
248
+ @pytest.fixture
249
+ def fs_join(self):
250
+ """
251
+ Return a function that joins its arguments together into a path.
252
+
253
+ Most fsspec implementations join paths in a platform-dependent way,
254
+ but some will override this to always use a forward slash.
255
+ """
256
+ return os.path.join
257
+
258
+ @pytest.fixture
259
+ def fs_path(self):
260
+ raise NotImplementedError("This function must be overridden in derived classes")
261
+
262
+ @pytest.fixture(scope="class")
263
+ def local_fs(self):
264
+ # Maybe need an option for auto_mkdir=False? This is only relevant
265
+ # for certain implementations.
266
+ return LocalFileSystem(auto_mkdir=True)
267
+
268
+ @pytest.fixture
269
+ def local_join(self):
270
+ """
271
+ Return a function that joins its arguments together into a path, on
272
+ the local filesystem.
273
+ """
274
+ return os.path.join
275
+
276
+ @pytest.fixture
277
+ def local_path(self, tmpdir):
278
+ return tmpdir
279
+
280
+ @pytest.fixture
281
+ def supports_empty_directories(self):
282
+ """
283
+ Return whether this implementation supports empty directories.
284
+ """
285
+ return True
286
+
287
+ @pytest.fixture
288
+ def fs_sanitize_path(self):
289
+ return lambda x: x
phi4/lib/python3.10/site-packages/fsspec/tests/abstract/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (10.3 kB). View file
 
phi4/lib/python3.10/site-packages/fsspec/tests/abstract/__pycache__/common.cpython-310.pyc ADDED
Binary file (1.56 kB). View file
 
phi4/lib/python3.10/site-packages/fsspec/tests/abstract/__pycache__/copy.cpython-310.pyc ADDED
Binary file (10.4 kB). View file
 
phi4/lib/python3.10/site-packages/fsspec/tests/abstract/__pycache__/get.cpython-310.pyc ADDED
Binary file (10.2 kB). View file
 
phi4/lib/python3.10/site-packages/fsspec/tests/abstract/__pycache__/mv.cpython-310.pyc ADDED
Binary file (1.37 kB). View file
 
phi4/lib/python3.10/site-packages/fsspec/tests/abstract/__pycache__/open.cpython-310.pyc ADDED
Binary file (771 Bytes). View file