PyPyNum 1.14.0__py3-none-any.whl → 1.14.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {PyPyNum-1.14.0.dist-info → PyPyNum-1.14.1.dist-info}/METADATA +48 -50
- {PyPyNum-1.14.0.dist-info → PyPyNum-1.14.1.dist-info}/RECORD +13 -13
- pypynum/Matrix.py +10 -1
- pypynum/README.md +47 -49
- pypynum/__init__.py +3 -3
- pypynum/dists.py +1 -1
- pypynum/maths.py +2 -2
- pypynum/multiprec.py +44 -12
- pypynum/sequence.py +43 -0
- pypynum/this.py +20 -1
- pypynum/tools.py +58 -32
- {PyPyNum-1.14.0.dist-info → PyPyNum-1.14.1.dist-info}/WHEEL +0 -0
- {PyPyNum-1.14.0.dist-info → PyPyNum-1.14.1.dist-info}/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: PyPyNum
|
|
3
|
-
Version: 1.14.
|
|
3
|
+
Version: 1.14.1
|
|
4
4
|
Summary: PyPyNum is a Python library for math & science computations, covering algebra, calculus, stats, with data structures like matrices, vectors, tensors. It offers numerical tools, programs, and supports computational ops, functions, processing, simulation, & visualization in data science & ML, crucial for research, engineering, & data processing.
|
|
5
5
|
Home-page: https://github.com/PythonSJL/PyPyNum
|
|
6
6
|
Author: Shen Jiayi
|
|
@@ -234,7 +234,7 @@ processing.</font><font color = red>[Python>=3.4]</font>
|
|
|
234
234
|
[](https://pepy.tech/project/pypynum)
|
|
235
235
|
[](https://pepy.tech/project/pypynum)
|
|
236
236
|
|
|
237
|
-
## Version -> 1.14.
|
|
237
|
+
## Version -> 1.14.1 | PyPI -> https://pypi.org/project/PyPyNum/ | Gitee -> https://www.gitee.com/PythonSJL/PyPyNum | GitHub -> https://github.com/PythonSJL/PyPyNum
|
|
238
238
|
|
|
239
239
|

|
|
240
240
|
|
|
@@ -298,16 +298,15 @@ The logo cannot be displayed on PyPI, it can be viewed in Gitee or GitHub.
|
|
|
298
298
|
### The Zen of PyPyNum (Preview)
|
|
299
299
|
|
|
300
300
|
```
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
Clarity
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
Sparse code wins over bloated ones.
|
|
301
|
+
The Zen of PyPyNum, by Shen Jiayi
|
|
302
|
+
|
|
303
|
+
In this mathematical sanctuary, we weave our algorithms with pure Python threads.
|
|
304
|
+
Precision outweighs approximation.
|
|
305
|
+
Elegance in mathematics transcends the bulky algorithms.
|
|
306
|
+
Clarity in logic illuminates the darkest problems.
|
|
307
|
+
Simplicity in form is the pinnacle of sophistication.
|
|
308
|
+
Flat hierarchies in our code mirror the linear nature of functions.
|
|
309
|
+
Sparse code, like a minimal polynomial, retains essence without redundancy.
|
|
311
310
|
```
|
|
312
311
|
|
|
313
312
|
```
|
|
@@ -321,7 +320,7 @@ Python interpreter and run it!
|
|
|
321
320
|
```
|
|
322
321
|
|
|
323
322
|
```
|
|
324
|
-
|
|
323
|
+
September 5, 2024
|
|
325
324
|
```
|
|
326
325
|
|
|
327
326
|
### Functional changes compared to the previous version
|
|
@@ -329,47 +328,39 @@ Python interpreter and run it!
|
|
|
329
328
|
```
|
|
330
329
|
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
331
330
|
|
|
332
|
-
|
|
331
|
+
< Fixed the display issue of multi precision complex numbers >
|
|
333
332
|
|
|
334
333
|
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
335
334
|
|
|
336
|
-
|
|
335
|
+
< Updated the Zen content of the project >
|
|
337
336
|
|
|
337
|
+
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
338
338
|
|
|
339
|
-
|
|
340
|
-
|
|
339
|
+
< The following two function names have removed the 'generate' prefix >
|
|
340
|
+
|
|
341
|
+
generate_primes(limit: int) -> list
|
|
342
|
+
generate_semiprimes(limit: int) -> list
|
|
343
|
+
|
|
344
|
+
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
345
|
+
|
|
346
|
+
<<< Newly added functions and classes >>>
|
|
347
|
+
|
|
348
|
+
PyPyNum
|
|
349
|
+
├── Matrix
|
|
341
350
|
│ └── FUNCTION
|
|
342
|
-
│
|
|
343
|
-
|
|
344
|
-
│ ├── bessel_iv(v: typing.Union[int, float], x: typing.Union[int, float, complex]) -> typing.Union[int, float, complex]
|
|
345
|
-
│ ├── bessel_j0(x: typing.Union[int, float, complex]) -> typing.Union[int, float, complex]
|
|
346
|
-
│ ├── bessel_j1(x: typing.Union[int, float, complex]) -> typing.Union[int, float, complex]
|
|
347
|
-
│ └── bessel_jv(v: typing.Union[int, float], x: typing.Union[int, float, complex]) -> typing.Union[int, float, complex]
|
|
348
|
-
├── crandom
|
|
351
|
+
│ └── triu_indices(n: int, k: int, m: int) -> tuple # Returns the indices of the upper triangular part of a matrix
|
|
352
|
+
├── multiprec
|
|
349
353
|
│ └── FUNCTION
|
|
350
|
-
│ ├──
|
|
351
|
-
|
|
352
|
-
│ ├── random_polar(mod: typing.Union[int, float], angle: typing.Union[int, float]) -> complex
|
|
353
|
-
│ ├── random_rect(real: typing.Union[int, float], imag: typing.Union[int, float]) -> complex
|
|
354
|
-
│ ├── uniform_polar(left: typing.Union[int, float], right: typing.Union[int, float], mod: typing.Union[int, float], angle: typing.Union[int, float]) -> complex
|
|
355
|
-
│ └── uniform_rect(left: typing.Union[int, float], right: typing.Union[int, float], real: typing.Union[int, float], imag: typing.Union[int, float]) -> complex
|
|
356
|
-
├── dataproc
|
|
357
|
-
│ ├── CLASS
|
|
358
|
-
│ │ └── Series(object)/__init__(self: Any, data: typing.Any, index: typing.Any) -> None
|
|
359
|
-
├── maths
|
|
354
|
+
│ ├── mp_euler_gamma(sigfigs: int) -> decimal.Decimal # Returns the Euler-Mascheroni constant with specified significant figures
|
|
355
|
+
├── sequence
|
|
360
356
|
│ └── FUNCTION
|
|
361
|
-
│ ├──
|
|
362
|
-
├──
|
|
357
|
+
│ ├── bell_triangle(n: int) -> list # Returns the first n rows of the Bell triangle
|
|
358
|
+
│ ├── pascal_triangle(n: int) -> list # Returns the first n rows of Pascal's triangle
|
|
359
|
+
│ ├── stirling1(n: int) -> list # Returns the first n rows of Stirling numbers of the first kind
|
|
360
|
+
│ └── stirling2(n: int) -> list # Returns the first n rows of Stirling numbers of the second kind
|
|
361
|
+
├── tools
|
|
363
362
|
│ └── FUNCTION
|
|
364
|
-
│
|
|
365
|
-
│ ├── split_float(s: str) -> tuple
|
|
366
|
-
|
|
367
|
-
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
368
|
-
|
|
369
|
-
Tip: The second type of Bessel
|
|
370
|
-
function has not been
|
|
371
|
-
implemented yet, but will be
|
|
372
|
-
added in future versions.
|
|
363
|
+
│ └── twinprimes(limit: int) -> list # Returns all twin prime pairs up to and including the specified limit
|
|
373
364
|
|
|
374
365
|
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
375
366
|
```
|
|
@@ -484,7 +475,8 @@ PyPyNum
|
|
|
484
475
|
│ ├── rank_decomp(matrix: pypynum.Matrix.Matrix) -> tuple
|
|
485
476
|
│ ├── rotate90(matrix: pypynum.Matrix.Matrix, times: int) -> pypynum.Matrix.Matrix
|
|
486
477
|
│ ├── svd(matrix: pypynum.Matrix.Matrix) -> tuple
|
|
487
|
-
│
|
|
478
|
+
│ ├── tril_indices(n: int, k: int, m: int) -> tuple
|
|
479
|
+
│ └── triu_indices(n: int, k: int, m: int) -> tuple
|
|
488
480
|
├── NeuralN
|
|
489
481
|
│ ├── CLASS
|
|
490
482
|
│ │ └── NeuralNetwork(object)/__init__(self: Any, _input: Any, _hidden: Any, _output: Any) -> Any
|
|
@@ -735,6 +727,7 @@ PyPyNum
|
|
|
735
727
|
│ ├── mp_cos(x: typing.Union[int, float, str, decimal.Decimal], sigfigs: int) -> decimal.Decimal
|
|
736
728
|
│ ├── mp_cosh(x: typing.Union[int, float, str, decimal.Decimal], sigfigs: int) -> decimal.Decimal
|
|
737
729
|
│ ├── mp_e(sigfigs: int, method: str) -> decimal.Decimal
|
|
730
|
+
│ ├── mp_euler_gamma(sigfigs: int) -> decimal.Decimal
|
|
738
731
|
│ ├── mp_exp(x: typing.Union[int, float, str, decimal.Decimal], sigfigs: int, builtin: bool) -> decimal.Decimal
|
|
739
732
|
│ ├── mp_fresnel_c(x: typing.Union[int, float, str, decimal.Decimal], sigfigs: int) -> decimal.Decimal
|
|
740
733
|
│ ├── mp_fresnel_s(x: typing.Union[int, float, str, decimal.Decimal], sigfigs: int) -> decimal.Decimal
|
|
@@ -800,12 +793,16 @@ PyPyNum
|
|
|
800
793
|
│ ├── CLASS
|
|
801
794
|
│ └── FUNCTION
|
|
802
795
|
│ ├── arithmetic_sequence(a1: typing.Union[int, float], an: typing.Union[int, float], d: typing.Union[int, float], n: typing.Union[int, float], s: typing.Union[int, float]) -> dict
|
|
796
|
+
│ ├── bell_triangle(n: int) -> list
|
|
803
797
|
│ ├── bernoulli(n: int, single: bool) -> list
|
|
804
798
|
│ ├── catalan(n: int, single: bool) -> typing.Union[int, list]
|
|
805
799
|
│ ├── farey(n: int) -> list
|
|
806
800
|
│ ├── fibonacci(n: int, single: bool) -> typing.Union[int, list]
|
|
807
801
|
│ ├── geometric_sequence(a1: typing.Union[int, float], an: typing.Union[int, float], r: typing.Union[int, float], n: typing.Union[int, float], s: typing.Union[int, float]) -> dict
|
|
808
|
-
│
|
|
802
|
+
│ ├── pascal_triangle(n: int) -> list
|
|
803
|
+
│ ├── recaman(n: int, single: bool) -> typing.Union[int, list]
|
|
804
|
+
│ ├── stirling1(n: int) -> list
|
|
805
|
+
│ └── stirling2(n: int) -> list
|
|
809
806
|
├── stattest
|
|
810
807
|
│ ├── CLASS
|
|
811
808
|
│ └── FUNCTION
|
|
@@ -827,15 +824,16 @@ PyPyNum
|
|
|
827
824
|
│ ├── classify(array: typing.Union[list, tuple]) -> dict
|
|
828
825
|
│ ├── dedup(iterable: typing.Union[list, tuple, str]) -> typing.Union[list, tuple, str]
|
|
829
826
|
│ ├── frange(start: typing.Union[int, float], stop: typing.Union[int, float], step: float) -> list
|
|
830
|
-
│ ├── generate_primes(limit: int) -> list
|
|
831
|
-
│ ├── generate_semiprimes(limit: int) -> list
|
|
832
827
|
│ ├── geomspace(start: typing.Union[int, float], stop: typing.Union[int, float], number: int) -> list
|
|
833
828
|
│ ├── levenshtein_distance(s1: str, s2: str) -> int
|
|
834
829
|
│ ├── linspace(start: typing.Union[int, float], stop: typing.Union[int, float], number: int) -> list
|
|
835
830
|
│ ├── magic_square(n: Any) -> Any
|
|
836
831
|
│ ├── primality(n: int, iter_num: int) -> bool
|
|
837
832
|
│ ├── prime_factors(integer: int, dictionary: bool, pollard_rho: bool) -> typing.Union[list, dict]
|
|
838
|
-
│
|
|
833
|
+
│ ├── primes(limit: int) -> list
|
|
834
|
+
│ ├── semiprimes(limit: int) -> list
|
|
835
|
+
│ ├── split(iterable: typing.Union[list, tuple, str], key: typing.Union[list, tuple], retain: bool) -> list
|
|
836
|
+
│ └── twinprimes(limit: int) -> list
|
|
839
837
|
├── types
|
|
840
838
|
│ ├── CLASS
|
|
841
839
|
│ └── FUNCTION
|
|
@@ -4,16 +4,16 @@ pypynum/Geometry.py,sha256=bJCuif-wHO-t7oHFEE7ntzIdQwzUEbT3mcKgmBV6Wps,13982
|
|
|
4
4
|
pypynum/Graph.py,sha256=m9iTCNYRCZmAexDzwJ8Y6J7v1aweT-6TZkqh4fOtZDE,10131
|
|
5
5
|
pypynum/Group.py,sha256=kzUR_r10ubOB2o51rKKdQPHRsgdTGL2yoY7yseKInZc,4263
|
|
6
6
|
pypynum/Logic.py,sha256=IJAv59ECHU0HmG9lYCAQ_puqeL6Zor3-IDIVH48KBWE,11000
|
|
7
|
-
pypynum/Matrix.py,sha256=
|
|
7
|
+
pypynum/Matrix.py,sha256=C84xfnTsg9N8FJXYzSORLHoRsch04PBbvMgPmjVFLuE,20612
|
|
8
8
|
pypynum/NeuralN.py,sha256=iSOvC9JW1h4AFGokGGOTkKie5hAYN_YT9H4f3apI9b8,3275
|
|
9
9
|
pypynum/PyPyNum.png,sha256=t96tJPWfHxT8kcXm_qZI2z5W36TgOqjCU9qdgbmlFws,11623
|
|
10
10
|
pypynum/Quaternion.py,sha256=-BW_crP_i-veHN0_pD3Z1dipFNUX198oZDrUYTsoZw0,8017
|
|
11
|
-
pypynum/README.md,sha256=
|
|
11
|
+
pypynum/README.md,sha256=ZGKsMqWmWtoUADcjjrURWUbwWaqN4CuiXDjTvVBKj-g,76730
|
|
12
12
|
pypynum/Symbolics.py,sha256=u-Dig3OLs6qoLzxMpTAYJGq5uSWDMvgU13TAHKLyjMY,2768
|
|
13
13
|
pypynum/Tensor.py,sha256=gi7OjrGgP5BSJS9Oma1B2EdX9qSpMNIP2BnKLojdT78,3930
|
|
14
14
|
pypynum/Tree.py,sha256=BYnlb2kKNJ8kkuq8BAHIcLvPZw5KHxbvM7YuVGhQVMk,4330
|
|
15
15
|
pypynum/Vector.py,sha256=ee-gkBtyG0l5dLFwAKRTTlnDG05pWpM19RGN7VoPvqE,3212
|
|
16
|
-
pypynum/__init__.py,sha256=
|
|
16
|
+
pypynum/__init__.py,sha256=eyYuIv8qPb8BkFu2aQ18HZ3cc7HEf0O2K8ayZyKJL4E,3008
|
|
17
17
|
pypynum/bessel.py,sha256=4g4XZAw1craezmxkYkvyPt1OlKjJU1JCqn_SZKME3PY,4164
|
|
18
18
|
pypynum/chars.py,sha256=ZOXZn2VzxmpHuvZ87ojhEib3CfTNgysRsFMFITHOA2E,2179
|
|
19
19
|
pypynum/cipher.py,sha256=DaitY3DCoTuzyrXtD8Ap3IYDLhlMc7-o4AJfLlicvB4,10011
|
|
@@ -21,30 +21,30 @@ pypynum/confs.py,sha256=iFz83iZ1A4BK4LTqo-ZbpAcoxhYWUxtEQKsr_-d8ryw,2869
|
|
|
21
21
|
pypynum/constants.py,sha256=xELv4DIKEqBdwF9tUqCmTQVbgVrlrj385ht5eawvshU,1406
|
|
22
22
|
pypynum/crandom.py,sha256=44GZ7o6y5PwgL-cZLkXUZaAUfiW6aadyRNfMdxTnH30,5111
|
|
23
23
|
pypynum/dataproc.py,sha256=xQJUvndP4APff2wpu2HItDZKWqrRZt72AU9CA8i-7tM,9277
|
|
24
|
-
pypynum/dists.py,sha256=
|
|
24
|
+
pypynum/dists.py,sha256=qyZLsXF1x3QYjsge50wMWrPcFoMHs5yBbHAbg5L9rDw,29698
|
|
25
25
|
pypynum/equations.py,sha256=26XEQBIcL3cyPLO6YFvBK1dlFHw-du3nQG4-cXAFYe0,557
|
|
26
26
|
pypynum/errors.py,sha256=XlK5yazNbNtnbM4toT_bdI41u-q-AUkZsa7dqc5dQb0,264
|
|
27
27
|
pypynum/file.py,sha256=-sg3pndZdiyM8cS6KeIhCvB6NfAovHnLOhEf0XkjidE,3411
|
|
28
28
|
pypynum/image.py,sha256=nhTZmaBVIKhuar-CcwZWb-hRYmkj4b_g7vIlYvEJEEE,12155
|
|
29
29
|
pypynum/interp.py,sha256=X1LN4WiVYkZlyKXvK_KJ2KDgjDiW_-tqgFM4ySQ3yJk,4897
|
|
30
|
-
pypynum/maths.py,sha256=
|
|
31
|
-
pypynum/multiprec.py,sha256=
|
|
30
|
+
pypynum/maths.py,sha256=McuOXRktbjcjZpTfWEoHnmFkeeQVacMoHyThqTIC27E,32808
|
|
31
|
+
pypynum/multiprec.py,sha256=NKZC5kIEg63WuTK5YCATuHP6ArSGHUKQpMHPmZ7GJ0k,19091
|
|
32
32
|
pypynum/numbers.py,sha256=EPzw8zq5U7GQj8URu2VxeVIXS-_XQm2ADmSAIHa816k,11133
|
|
33
33
|
pypynum/plotting.py,sha256=mbIYK5TpY1qvuMJrqz4d8bxJEiZww3AI684vSKV-DgU,7781
|
|
34
34
|
pypynum/polynomial.py,sha256=60hDQG_iRwduFFqawSTzAG6F3eHqfgrSnSGDwBLQB-s,14587
|
|
35
35
|
pypynum/pprinters.py,sha256=Qt9-V5SUyoOqC3lsUU5D5zSSM-MmcnFCUyUtLxhS4pE,2514
|
|
36
36
|
pypynum/random.py,sha256=qy2ISoHQVJ-zOVITplmCGvWEw-EZc18r-hZl8dvDimE,2274
|
|
37
37
|
pypynum/regression.py,sha256=PfTM8glJSi3Jgvc_C_3hQBeVjkbrzSuDqRbEf3s403w,2040
|
|
38
|
-
pypynum/sequence.py,sha256=
|
|
38
|
+
pypynum/sequence.py,sha256=L8xaFGjFy5X4NKS4wkDGx9RSzkrWDZF__rLFdnnNEIA,8443
|
|
39
39
|
pypynum/stattest.py,sha256=W1041KeVsvdcLKFJOK4hQm_DjO5ZjUE8WEmGUe-4_Zk,5507
|
|
40
40
|
pypynum/test.py,sha256=tjJI8YkAqNEtwNeFsixWliZfc3J1qVpgCo4u-Wh9kvw,8826
|
|
41
|
-
pypynum/this.py,sha256=
|
|
42
|
-
pypynum/tools.py,sha256=
|
|
41
|
+
pypynum/this.py,sha256=wT7DwodxqOQ7LoDaUtvskMkAb8CODL_56mtXPy12P54,3411
|
|
42
|
+
pypynum/tools.py,sha256=r94-thFR4MzrGSNpNwdYJV60JBqZoT0aH2T8-ghsgRQ,14305
|
|
43
43
|
pypynum/types.py,sha256=ek9tydfCspsjcvxVFv_rJegnTHl6PHwKPdqjvHfkvDg,246
|
|
44
44
|
pypynum/ufuncs.py,sha256=hb7v4DgJ1eUB16uQ_m-OUfM9e2rIKwPk03shd1cBx0o,3547
|
|
45
45
|
pypynum/utils.py,sha256=OqUFVraYDTSubF9QhZm8WC6A0ppnkhVU0YtAeYN9EyU,21048
|
|
46
46
|
pypynum/zh_cn.py,sha256=VfmCAtL9CZaHuridOswBTGVGPwyu_4v19Leb0niqxtY,13723
|
|
47
|
-
PyPyNum-1.14.
|
|
48
|
-
PyPyNum-1.14.
|
|
49
|
-
PyPyNum-1.14.
|
|
50
|
-
PyPyNum-1.14.
|
|
47
|
+
PyPyNum-1.14.1.dist-info/METADATA,sha256=nncMFGDv-KkzXh5IPLgrtzJZR0craxK4B0iZzoUHSUc,91109
|
|
48
|
+
PyPyNum-1.14.1.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
49
|
+
PyPyNum-1.14.1.dist-info/top_level.txt,sha256=4wW_Xb4bRglmiMsdPAe9f75MkXhNpuN88H17g_Cr5u8,8
|
|
50
|
+
PyPyNum-1.14.1.dist-info/RECORD,,
|
pypynum/Matrix.py
CHANGED
|
@@ -297,11 +297,20 @@ def lu(matrix: Matrix) -> tuple:
|
|
|
297
297
|
return Matrix(L), Matrix(U)
|
|
298
298
|
|
|
299
299
|
|
|
300
|
+
def triu_indices(n: int, k: int = 0, m: int = None) -> tuple:
|
|
301
|
+
if m is None:
|
|
302
|
+
m = n
|
|
303
|
+
if n < 1 or k >= m or m < 1:
|
|
304
|
+
return (), ()
|
|
305
|
+
indices = [(y, x) for y in range(n) for x in range(y + k, m) if x > -1]
|
|
306
|
+
return tuple(zip(*indices))
|
|
307
|
+
|
|
308
|
+
|
|
300
309
|
def tril_indices(n: int, k: int = 0, m: int = None) -> tuple:
|
|
301
310
|
if m is None:
|
|
302
311
|
m = n
|
|
303
312
|
if n < 1 or k <= -n or m < 1:
|
|
304
|
-
return
|
|
313
|
+
return (), ()
|
|
305
314
|
indices = [(y, x) for y in range(n) for x in range(y + k + 1) if x < m]
|
|
306
315
|
return tuple(zip(*indices))
|
|
307
316
|
|
pypynum/README.md
CHANGED
|
@@ -20,7 +20,7 @@ processing.</font><font color = red>[Python>=3.4]</font>
|
|
|
20
20
|
[](https://pepy.tech/project/pypynum)
|
|
21
21
|
[](https://pepy.tech/project/pypynum)
|
|
22
22
|
|
|
23
|
-
## Version -> 1.14.
|
|
23
|
+
## Version -> 1.14.1 | PyPI -> https://pypi.org/project/PyPyNum/ | Gitee -> https://www.gitee.com/PythonSJL/PyPyNum | GitHub -> https://github.com/PythonSJL/PyPyNum
|
|
24
24
|
|
|
25
25
|

|
|
26
26
|
|
|
@@ -84,16 +84,15 @@ The logo cannot be displayed on PyPI, it can be viewed in Gitee or GitHub.
|
|
|
84
84
|
### The Zen of PyPyNum (Preview)
|
|
85
85
|
|
|
86
86
|
```
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
Clarity
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
Sparse code wins over bloated ones.
|
|
87
|
+
The Zen of PyPyNum, by Shen Jiayi
|
|
88
|
+
|
|
89
|
+
In this mathematical sanctuary, we weave our algorithms with pure Python threads.
|
|
90
|
+
Precision outweighs approximation.
|
|
91
|
+
Elegance in mathematics transcends the bulky algorithms.
|
|
92
|
+
Clarity in logic illuminates the darkest problems.
|
|
93
|
+
Simplicity in form is the pinnacle of sophistication.
|
|
94
|
+
Flat hierarchies in our code mirror the linear nature of functions.
|
|
95
|
+
Sparse code, like a minimal polynomial, retains essence without redundancy.
|
|
97
96
|
```
|
|
98
97
|
|
|
99
98
|
```
|
|
@@ -107,7 +106,7 @@ Python interpreter and run it!
|
|
|
107
106
|
```
|
|
108
107
|
|
|
109
108
|
```
|
|
110
|
-
|
|
109
|
+
September 5, 2024
|
|
111
110
|
```
|
|
112
111
|
|
|
113
112
|
### Functional changes compared to the previous version
|
|
@@ -115,47 +114,39 @@ Python interpreter and run it!
|
|
|
115
114
|
```
|
|
116
115
|
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
117
116
|
|
|
118
|
-
|
|
117
|
+
< Fixed the display issue of multi precision complex numbers >
|
|
119
118
|
|
|
120
119
|
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
121
120
|
|
|
122
|
-
|
|
121
|
+
< Updated the Zen content of the project >
|
|
123
122
|
|
|
123
|
+
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
124
124
|
|
|
125
|
-
|
|
126
|
-
|
|
125
|
+
< The following two function names have removed the 'generate' prefix >
|
|
126
|
+
|
|
127
|
+
generate_primes(limit: int) -> list
|
|
128
|
+
generate_semiprimes(limit: int) -> list
|
|
129
|
+
|
|
130
|
+
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
131
|
+
|
|
132
|
+
<<< Newly added functions and classes >>>
|
|
133
|
+
|
|
134
|
+
PyPyNum
|
|
135
|
+
├── Matrix
|
|
127
136
|
│ └── FUNCTION
|
|
128
|
-
│
|
|
129
|
-
|
|
130
|
-
│ ├── bessel_iv(v: typing.Union[int, float], x: typing.Union[int, float, complex]) -> typing.Union[int, float, complex]
|
|
131
|
-
│ ├── bessel_j0(x: typing.Union[int, float, complex]) -> typing.Union[int, float, complex]
|
|
132
|
-
│ ├── bessel_j1(x: typing.Union[int, float, complex]) -> typing.Union[int, float, complex]
|
|
133
|
-
│ └── bessel_jv(v: typing.Union[int, float], x: typing.Union[int, float, complex]) -> typing.Union[int, float, complex]
|
|
134
|
-
├── crandom
|
|
137
|
+
│ └── triu_indices(n: int, k: int, m: int) -> tuple # Returns the indices of the upper triangular part of a matrix
|
|
138
|
+
├── multiprec
|
|
135
139
|
│ └── FUNCTION
|
|
136
|
-
│ ├──
|
|
137
|
-
|
|
138
|
-
│ ├── random_polar(mod: typing.Union[int, float], angle: typing.Union[int, float]) -> complex
|
|
139
|
-
│ ├── random_rect(real: typing.Union[int, float], imag: typing.Union[int, float]) -> complex
|
|
140
|
-
│ ├── uniform_polar(left: typing.Union[int, float], right: typing.Union[int, float], mod: typing.Union[int, float], angle: typing.Union[int, float]) -> complex
|
|
141
|
-
│ └── uniform_rect(left: typing.Union[int, float], right: typing.Union[int, float], real: typing.Union[int, float], imag: typing.Union[int, float]) -> complex
|
|
142
|
-
├── dataproc
|
|
143
|
-
│ ├── CLASS
|
|
144
|
-
│ │ └── Series(object)/__init__(self: Any, data: typing.Any, index: typing.Any) -> None
|
|
145
|
-
├── maths
|
|
140
|
+
│ ├── mp_euler_gamma(sigfigs: int) -> decimal.Decimal # Returns the Euler-Mascheroni constant with specified significant figures
|
|
141
|
+
├── sequence
|
|
146
142
|
│ └── FUNCTION
|
|
147
|
-
│ ├──
|
|
148
|
-
├──
|
|
143
|
+
│ ├── bell_triangle(n: int) -> list # Returns the first n rows of the Bell triangle
|
|
144
|
+
│ ├── pascal_triangle(n: int) -> list # Returns the first n rows of Pascal's triangle
|
|
145
|
+
│ ├── stirling1(n: int) -> list # Returns the first n rows of Stirling numbers of the first kind
|
|
146
|
+
│ └── stirling2(n: int) -> list # Returns the first n rows of Stirling numbers of the second kind
|
|
147
|
+
├── tools
|
|
149
148
|
│ └── FUNCTION
|
|
150
|
-
│
|
|
151
|
-
│ ├── split_float(s: str) -> tuple
|
|
152
|
-
|
|
153
|
-
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
154
|
-
|
|
155
|
-
Tip: The second type of Bessel
|
|
156
|
-
function has not been
|
|
157
|
-
implemented yet, but will be
|
|
158
|
-
added in future versions.
|
|
149
|
+
│ └── twinprimes(limit: int) -> list # Returns all twin prime pairs up to and including the specified limit
|
|
159
150
|
|
|
160
151
|
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
161
152
|
```
|
|
@@ -270,7 +261,8 @@ PyPyNum
|
|
|
270
261
|
│ ├── rank_decomp(matrix: pypynum.Matrix.Matrix) -> tuple
|
|
271
262
|
│ ├── rotate90(matrix: pypynum.Matrix.Matrix, times: int) -> pypynum.Matrix.Matrix
|
|
272
263
|
│ ├── svd(matrix: pypynum.Matrix.Matrix) -> tuple
|
|
273
|
-
│
|
|
264
|
+
│ ├── tril_indices(n: int, k: int, m: int) -> tuple
|
|
265
|
+
│ └── triu_indices(n: int, k: int, m: int) -> tuple
|
|
274
266
|
├── NeuralN
|
|
275
267
|
│ ├── CLASS
|
|
276
268
|
│ │ └── NeuralNetwork(object)/__init__(self: Any, _input: Any, _hidden: Any, _output: Any) -> Any
|
|
@@ -521,6 +513,7 @@ PyPyNum
|
|
|
521
513
|
│ ├── mp_cos(x: typing.Union[int, float, str, decimal.Decimal], sigfigs: int) -> decimal.Decimal
|
|
522
514
|
│ ├── mp_cosh(x: typing.Union[int, float, str, decimal.Decimal], sigfigs: int) -> decimal.Decimal
|
|
523
515
|
│ ├── mp_e(sigfigs: int, method: str) -> decimal.Decimal
|
|
516
|
+
│ ├── mp_euler_gamma(sigfigs: int) -> decimal.Decimal
|
|
524
517
|
│ ├── mp_exp(x: typing.Union[int, float, str, decimal.Decimal], sigfigs: int, builtin: bool) -> decimal.Decimal
|
|
525
518
|
│ ├── mp_fresnel_c(x: typing.Union[int, float, str, decimal.Decimal], sigfigs: int) -> decimal.Decimal
|
|
526
519
|
│ ├── mp_fresnel_s(x: typing.Union[int, float, str, decimal.Decimal], sigfigs: int) -> decimal.Decimal
|
|
@@ -586,12 +579,16 @@ PyPyNum
|
|
|
586
579
|
│ ├── CLASS
|
|
587
580
|
│ └── FUNCTION
|
|
588
581
|
│ ├── arithmetic_sequence(a1: typing.Union[int, float], an: typing.Union[int, float], d: typing.Union[int, float], n: typing.Union[int, float], s: typing.Union[int, float]) -> dict
|
|
582
|
+
│ ├── bell_triangle(n: int) -> list
|
|
589
583
|
│ ├── bernoulli(n: int, single: bool) -> list
|
|
590
584
|
│ ├── catalan(n: int, single: bool) -> typing.Union[int, list]
|
|
591
585
|
│ ├── farey(n: int) -> list
|
|
592
586
|
│ ├── fibonacci(n: int, single: bool) -> typing.Union[int, list]
|
|
593
587
|
│ ├── geometric_sequence(a1: typing.Union[int, float], an: typing.Union[int, float], r: typing.Union[int, float], n: typing.Union[int, float], s: typing.Union[int, float]) -> dict
|
|
594
|
-
│
|
|
588
|
+
│ ├── pascal_triangle(n: int) -> list
|
|
589
|
+
│ ├── recaman(n: int, single: bool) -> typing.Union[int, list]
|
|
590
|
+
│ ├── stirling1(n: int) -> list
|
|
591
|
+
│ └── stirling2(n: int) -> list
|
|
595
592
|
├── stattest
|
|
596
593
|
│ ├── CLASS
|
|
597
594
|
│ └── FUNCTION
|
|
@@ -613,15 +610,16 @@ PyPyNum
|
|
|
613
610
|
│ ├── classify(array: typing.Union[list, tuple]) -> dict
|
|
614
611
|
│ ├── dedup(iterable: typing.Union[list, tuple, str]) -> typing.Union[list, tuple, str]
|
|
615
612
|
│ ├── frange(start: typing.Union[int, float], stop: typing.Union[int, float], step: float) -> list
|
|
616
|
-
│ ├── generate_primes(limit: int) -> list
|
|
617
|
-
│ ├── generate_semiprimes(limit: int) -> list
|
|
618
613
|
│ ├── geomspace(start: typing.Union[int, float], stop: typing.Union[int, float], number: int) -> list
|
|
619
614
|
│ ├── levenshtein_distance(s1: str, s2: str) -> int
|
|
620
615
|
│ ├── linspace(start: typing.Union[int, float], stop: typing.Union[int, float], number: int) -> list
|
|
621
616
|
│ ├── magic_square(n: Any) -> Any
|
|
622
617
|
│ ├── primality(n: int, iter_num: int) -> bool
|
|
623
618
|
│ ├── prime_factors(integer: int, dictionary: bool, pollard_rho: bool) -> typing.Union[list, dict]
|
|
624
|
-
│
|
|
619
|
+
│ ├── primes(limit: int) -> list
|
|
620
|
+
│ ├── semiprimes(limit: int) -> list
|
|
621
|
+
│ ├── split(iterable: typing.Union[list, tuple, str], key: typing.Union[list, tuple], retain: bool) -> list
|
|
622
|
+
│ └── twinprimes(limit: int) -> list
|
|
625
623
|
├── types
|
|
626
624
|
│ ├── CLASS
|
|
627
625
|
│ └── FUNCTION
|
pypynum/__init__.py
CHANGED
|
@@ -20,12 +20,12 @@ Copyright
|
|
|
20
20
|
|
|
21
21
|
- Author: Shen Jiayi
|
|
22
22
|
- Email: 2261748025@qq.com
|
|
23
|
-
- Copyright: 2023
|
|
23
|
+
- Copyright: Copyright (c) 2023, Shen Jiayi. All rights reserved.
|
|
24
24
|
"""
|
|
25
25
|
|
|
26
26
|
__author__ = "Shen Jiayi"
|
|
27
27
|
__email__ = "2261748025@qq.com"
|
|
28
|
-
__copyright__ = "2023
|
|
28
|
+
__copyright__ = "Copyright (c) 2023, Shen Jiayi. All rights reserved."
|
|
29
29
|
|
|
30
30
|
from .Array import array, fill, full, full_like, zeros, zeros_like, ones, ones_like, aslist, asarray, boolarray
|
|
31
31
|
from .bessel import *
|
|
@@ -69,7 +69,7 @@ from .utils import OrderedSet, InfIterator, LinkedList, IntervalSet
|
|
|
69
69
|
from .Vector import vec
|
|
70
70
|
from . import zh_cn
|
|
71
71
|
|
|
72
|
-
__version__ = "1.14.
|
|
72
|
+
__version__ = "1.14.1"
|
|
73
73
|
print("PyPyNum", "Version -> " + __version__, "PyPI -> https://pypi.org/project/PyPyNum/",
|
|
74
74
|
"Gitee -> https://www.gitee.com/PythonSJL/PyPyNum", "GitHub -> https://github.com/PythonSJL/PyPyNum", sep=" | ")
|
|
75
75
|
del math, arr, ite, num, prec, real, geom, ContentError, RandomError, LogicError, InputError, FullError, Union
|
pypynum/dists.py
CHANGED
|
@@ -775,7 +775,7 @@ def vonmises_pdf(x, mu, kappa):
|
|
|
775
775
|
:param kappa: The concentration parameter, must be positive.
|
|
776
776
|
:return: The probability density at x for the von Mises distribution with the given parameters.
|
|
777
777
|
"""
|
|
778
|
-
from .
|
|
778
|
+
from .bessel import bessel_i0
|
|
779
779
|
if not 0 <= mu < 6.283185307179586:
|
|
780
780
|
raise ValueError("mu must be between 0 and 2 * pi")
|
|
781
781
|
if not 0 <= x < 6.283185307179586:
|
pypynum/maths.py
CHANGED
|
@@ -120,7 +120,7 @@ def roll(seq: ite, shift: int) -> ite:
|
|
|
120
120
|
:param shift: integer
|
|
121
121
|
:return:
|
|
122
122
|
"""
|
|
123
|
-
shift
|
|
123
|
+
shift %= len(seq)
|
|
124
124
|
return seq[-shift:] + seq[:-shift]
|
|
125
125
|
|
|
126
126
|
|
|
@@ -945,7 +945,7 @@ def deriv(f, x: float, h: float = 1e-6, method: str = "complex_step", *args, **k
|
|
|
945
945
|
if method == "complex_step":
|
|
946
946
|
return f(x + 1j * h, *args, **kwargs).imag / h
|
|
947
947
|
elif method == "central_difference":
|
|
948
|
-
h
|
|
948
|
+
h /= 2
|
|
949
949
|
return (f(x + h, *args, **kwargs) - f(x - h, *args, **kwargs)) / (2 * h)
|
|
950
950
|
elif method == "forward_difference":
|
|
951
951
|
return (f(x + h, *args, **kwargs) - f(x, *args, **kwargs)) / h
|
pypynum/multiprec.py
CHANGED
|
@@ -18,7 +18,7 @@ def frac2dec(frac: Fraction, sigfigs: int) -> Decimal:
|
|
|
18
18
|
def mp_e(sigfigs: int, method: str = "series") -> Decimal:
|
|
19
19
|
def series_e():
|
|
20
20
|
nonlocal sigfigs
|
|
21
|
-
sigfigs
|
|
21
|
+
sigfigs += 5
|
|
22
22
|
__context.prec = sigfigs
|
|
23
23
|
e = Decimal(0)
|
|
24
24
|
one = Decimal(1)
|
|
@@ -55,7 +55,7 @@ def mp_e(sigfigs: int, method: str = "series") -> Decimal:
|
|
|
55
55
|
def mp_pi(sigfigs: int, method: str = "chudnovsky") -> Decimal:
|
|
56
56
|
def chudnovsky_pi():
|
|
57
57
|
nonlocal sigfigs
|
|
58
|
-
sigfigs
|
|
58
|
+
sigfigs += 5
|
|
59
59
|
__context.prec = sigfigs
|
|
60
60
|
c = 426880 * Decimal(10005).sqrt()
|
|
61
61
|
m = 1
|
|
@@ -77,7 +77,7 @@ def mp_pi(sigfigs: int, method: str = "chudnovsky") -> Decimal:
|
|
|
77
77
|
|
|
78
78
|
def bbp_pi():
|
|
79
79
|
nonlocal sigfigs
|
|
80
|
-
sigfigs
|
|
80
|
+
sigfigs += 5
|
|
81
81
|
__context.prec = sigfigs
|
|
82
82
|
d4 = Decimal(4)
|
|
83
83
|
d2 = Decimal(2)
|
|
@@ -114,7 +114,7 @@ def mp_phi(sigfigs: int, method: str = "algebraic") -> Decimal:
|
|
|
114
114
|
|
|
115
115
|
def newton_phi():
|
|
116
116
|
nonlocal sigfigs
|
|
117
|
-
sigfigs
|
|
117
|
+
sigfigs += 5
|
|
118
118
|
__context.prec = sigfigs
|
|
119
119
|
one = Decimal(1)
|
|
120
120
|
two = Decimal(2)
|
|
@@ -138,7 +138,7 @@ def mp_phi(sigfigs: int, method: str = "algebraic") -> Decimal:
|
|
|
138
138
|
|
|
139
139
|
def mp_sin(x: prec, sigfigs: int) -> Decimal:
|
|
140
140
|
x = Decimal(str(x))
|
|
141
|
-
sigfigs
|
|
141
|
+
sigfigs += 5
|
|
142
142
|
__context.prec = sigfigs
|
|
143
143
|
sin_x = Decimal(0)
|
|
144
144
|
pi = mp_pi(sigfigs + 5)
|
|
@@ -157,7 +157,7 @@ def mp_sin(x: prec, sigfigs: int) -> Decimal:
|
|
|
157
157
|
|
|
158
158
|
def mp_cos(x: prec, sigfigs: int) -> Decimal:
|
|
159
159
|
x = Decimal(str(x))
|
|
160
|
-
sigfigs
|
|
160
|
+
sigfigs += 5
|
|
161
161
|
__context.prec = sigfigs
|
|
162
162
|
cos_x = Decimal(0)
|
|
163
163
|
pi = mp_pi(sigfigs + 5)
|
|
@@ -181,7 +181,7 @@ def mp_ln(x: prec, sigfigs: int, builtin: bool = True) -> Decimal:
|
|
|
181
181
|
x = Decimal(str(x))
|
|
182
182
|
if x <= 0:
|
|
183
183
|
raise ValueError("Natural logarithm is not defined for x <= 0")
|
|
184
|
-
sigfigs
|
|
184
|
+
sigfigs += 5
|
|
185
185
|
__context.prec = sigfigs
|
|
186
186
|
sign = -1
|
|
187
187
|
if x > 1:
|
|
@@ -201,7 +201,7 @@ def mp_ln(x: prec, sigfigs: int, builtin: bool = True) -> Decimal:
|
|
|
201
201
|
|
|
202
202
|
|
|
203
203
|
def mp_log(x: prec, base: prec, sigfigs: int, builtin: bool = True) -> Decimal:
|
|
204
|
-
sigfigs
|
|
204
|
+
sigfigs += 5
|
|
205
205
|
if builtin:
|
|
206
206
|
__context.prec = sigfigs
|
|
207
207
|
x_dec = Decimal(str(x))
|
|
@@ -343,7 +343,7 @@ def mp_acos(x: prec, sigfigs: int) -> Decimal: # FIXME
|
|
|
343
343
|
def mp_fresnel_s(x: prec, sigfigs: int) -> Decimal: # FIXME
|
|
344
344
|
x = Decimal(str(x))
|
|
345
345
|
more = int(x * x)
|
|
346
|
-
sigfigs
|
|
346
|
+
sigfigs += more
|
|
347
347
|
__context.prec = sigfigs
|
|
348
348
|
s_x = Decimal(0)
|
|
349
349
|
p = mp_pi(sigfigs + 5)
|
|
@@ -369,7 +369,7 @@ def mp_fresnel_s(x: prec, sigfigs: int) -> Decimal: # FIXME
|
|
|
369
369
|
def mp_fresnel_c(x: prec, sigfigs: int) -> Decimal: # FIXME
|
|
370
370
|
x = Decimal(str(x))
|
|
371
371
|
more = int(x * x)
|
|
372
|
-
sigfigs
|
|
372
|
+
sigfigs += more
|
|
373
373
|
__context.prec = sigfigs
|
|
374
374
|
c_x = Decimal(0)
|
|
375
375
|
f = -x ** 4 * mp_pi(sigfigs + 5) ** 2 / 4
|
|
@@ -391,6 +391,31 @@ def mp_fresnel_c(x: prec, sigfigs: int) -> Decimal: # FIXME
|
|
|
391
391
|
return +c_x
|
|
392
392
|
|
|
393
393
|
|
|
394
|
+
def mp_euler_gamma(sigfigs: int) -> Decimal:
|
|
395
|
+
sigfigs += 5
|
|
396
|
+
__context.prec = sigfigs
|
|
397
|
+
n = int(sigfigs * 0.6)
|
|
398
|
+
i_n = Decimal(0)
|
|
399
|
+
j_n = Decimal(0)
|
|
400
|
+
k = 1
|
|
401
|
+
n_power_k = n
|
|
402
|
+
fact_k = Decimal(1)
|
|
403
|
+
harmonic_sum = Decimal(0)
|
|
404
|
+
term = Decimal(1)
|
|
405
|
+
eps = Decimal(10) ** -sigfigs
|
|
406
|
+
while abs(term) >= eps:
|
|
407
|
+
term = (n_power_k / fact_k) ** 2
|
|
408
|
+
i_n += term * harmonic_sum
|
|
409
|
+
j_n += term
|
|
410
|
+
n_power_k *= n
|
|
411
|
+
fact_k *= k
|
|
412
|
+
harmonic_sum += Decimal(1) / k
|
|
413
|
+
k += 1
|
|
414
|
+
gamma = i_n / j_n - Decimal(n).ln()
|
|
415
|
+
__context.prec -= 5
|
|
416
|
+
return +gamma
|
|
417
|
+
|
|
418
|
+
|
|
394
419
|
class MPComplex:
|
|
395
420
|
def __init__(self, real, imag, sigfigs=28):
|
|
396
421
|
_setprec(sigfigs)
|
|
@@ -425,6 +450,9 @@ class MPComplex:
|
|
|
425
450
|
def __neg__(self):
|
|
426
451
|
return MPComplex(-self.real, -self.imag, self.sigfigs)
|
|
427
452
|
|
|
453
|
+
__radd__ = __add__
|
|
454
|
+
__rmul__ = __mul__
|
|
455
|
+
|
|
428
456
|
def conjugate(self):
|
|
429
457
|
return MPComplex(self.real, -self.imag, self.sigfigs)
|
|
430
458
|
|
|
@@ -435,6 +463,9 @@ class MPComplex:
|
|
|
435
463
|
_setprec(self.sigfigs)
|
|
436
464
|
return +mod
|
|
437
465
|
|
|
466
|
+
def __abs__(self):
|
|
467
|
+
return self.modulus()
|
|
468
|
+
|
|
438
469
|
def __pow__(self, power, modulo=None):
|
|
439
470
|
if modulo is not None:
|
|
440
471
|
raise TypeError("Modulo operation is not supported for complex numbers")
|
|
@@ -552,12 +583,13 @@ def _remove_trailing_zeros(value: Any) -> str:
|
|
|
552
583
|
value_str = str(value).lower()
|
|
553
584
|
if value_str == "0" or value_str.startswith(("0e", "-0e")):
|
|
554
585
|
return "0"
|
|
586
|
+
if "." not in value_str:
|
|
587
|
+
return value_str
|
|
555
588
|
if "e" in value_str:
|
|
556
589
|
mantissa, exponent = value_str.split("e")
|
|
557
590
|
mantissa = mantissa.rstrip("0").rstrip(".")
|
|
558
591
|
return mantissa + "e" + exponent
|
|
559
|
-
|
|
560
|
-
return value_str.rstrip("0").rstrip(".")
|
|
592
|
+
return value_str.rstrip("0").rstrip(".")
|
|
561
593
|
|
|
562
594
|
|
|
563
595
|
def asmpc(real: Union[int, float, str, Decimal, complex, MPComplex], imag: prec = 0,
|
pypynum/sequence.py
CHANGED
|
@@ -1,6 +1,49 @@
|
|
|
1
1
|
from .types import Union, real
|
|
2
2
|
|
|
3
3
|
|
|
4
|
+
def pascal_triangle(n: int) -> list:
|
|
5
|
+
triangle = [[1]]
|
|
6
|
+
for i in range(1, n + 1):
|
|
7
|
+
new_row = [1]
|
|
8
|
+
for j in range(1, i):
|
|
9
|
+
new_row.append(triangle[i - 1][j - 1] + triangle[i - 1][j])
|
|
10
|
+
new_row.append(1)
|
|
11
|
+
triangle.append(new_row)
|
|
12
|
+
return triangle
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def bell_triangle(n: int) -> list:
|
|
16
|
+
triangle = [[1]]
|
|
17
|
+
for i in range(1, n + 1):
|
|
18
|
+
new_row = [triangle[i - 1][-1]]
|
|
19
|
+
for j in range(1, i + 1):
|
|
20
|
+
new_row.append(new_row[j - 1] + triangle[i - 1][j - 1])
|
|
21
|
+
triangle.append(new_row)
|
|
22
|
+
return triangle
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def stirling1(n: int) -> list:
|
|
26
|
+
triangle = [[1]]
|
|
27
|
+
for i in range(1, n + 1):
|
|
28
|
+
new_row = [0]
|
|
29
|
+
for j in range(1, i):
|
|
30
|
+
new_row.append((i - 1) * triangle[i - 1][j] + triangle[i - 1][j - 1])
|
|
31
|
+
new_row.append(triangle[i - 1][i - 1])
|
|
32
|
+
triangle.append(new_row)
|
|
33
|
+
return triangle
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def stirling2(n: int) -> list:
|
|
37
|
+
triangle = [[1]]
|
|
38
|
+
for i in range(1, n + 1):
|
|
39
|
+
new_row = [0]
|
|
40
|
+
for j in range(1, i):
|
|
41
|
+
new_row.append(j * triangle[i - 1][j] + triangle[i - 1][j - 1])
|
|
42
|
+
new_row.append(triangle[i - 1][i - 1])
|
|
43
|
+
triangle.append(new_row)
|
|
44
|
+
return triangle
|
|
45
|
+
|
|
46
|
+
|
|
4
47
|
def farey(n: int) -> list:
|
|
5
48
|
a2, b2 = None, None
|
|
6
49
|
if n == 0:
|
pypynum/this.py
CHANGED
|
@@ -2,7 +2,26 @@
|
|
|
2
2
|
The Zen of PyPyNum
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
|
-
Zen = "\x9a¤¢\xa0
|
|
5
|
+
Zen = ("\x9a¤¢\xa0¢°¼¥°âõòýõäàõð°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°\x9a\x9a"
|
|
6
|
+
"±äù°õóñâòýõ°ã·äõÜ\x9a¾ãõùâÿõøä°üñóùäñýõøäñý°öÿ°þÿùäñêùüñäþõýäâñàýÿó°õøä°ÿä°þùûñ°ãù°þ÷ùãõô°þù°éäùâñüåôÿÝ\x9a"
|
|
7
|
+
"¾ýõâÿõøä°ôõøãùüòñäãõ½üüõç°ñ°öÿ°øäåâä°õøä°øäùç°ãõäñþÿãõâ°äù°¼âñõüó°ãù°þÿùäåüÿã°ñ°öÙ\x9a"
|
|
8
|
+
"¾öÿÿâà°üñóùäñýõøäñý°ñ°öÿ°âÿ÷ùâ°õøä°øäùç°äù°âÿäóñöõâ°¼õæùãåüõ°ãù°þÿùäåüÿã°ñ°öÙ\x9a"
|
|
9
|
+
"¾öÿÿâà°äåÿ½äø÷åÿøä½üüõç°ñ°ãñ°¼ýõüòÿâà°ñ°öÿ°øäàõô°õøä°âõæÿóþå°þñó°õóþõùäñà°¼äõÉ\x9a"
|
|
10
|
+
"¾õæùãùóõô°ôþñ°äöùçã°«öÿÿâà°äóõâùô°õøä°ÿä°þùûñ°ãù°÷þùæüÿã°þù°ããõþäàýÿâÀ\x9a"
|
|
11
|
+
"¾äþõýõüõ°éäùäþõôù°õøä°ãñ°õåáùþå°ãñ°¼þÿùäåüÿã°äþñ÷õüõ°¼õü÷þùã°ñ°õò°ôüåÿøã°õâõøÄ\x9a"
|
|
12
|
+
"¾ýõâÿõøä°ôõþùöõô½üüõç°ñ°öÿ°éäùâñüó°õøä°ûõõã°õç°¼éäùå÷ùòýñ°öÿ°õóñö°õøä°þÙ\x9a"
|
|
13
|
+
"¾óù÷õäñâäã°ôþñ°üñþÿùäþõäþù°ãù°¼ôÿùâõà°ôõóñüà½üüõç°ñ°õûùü°¼õóþõüùÃ\x9a"
|
|
14
|
+
"¾ôõüñõóþÿó°äÿþ°¼ôõãÿàèõ°õò°äãåý°¼öÿÿâà°ñ°þù°þÿùäóùôñâäþÿó°ñ°õûùü°¼ãâÿââÕ\x9a"
|
|
15
|
+
"¾éäùâåà°üñóùäõâÿõøä°ãõôõãâõàåã°þõäöÿ°¼ýõâÿõøä°õüòñóùüààñ°þñ°õûùü°¼éäùüñóùäóñâÀ\x9a"
|
|
16
|
+
"¾õüåâ°üñâõþõ÷°õøä°õäñóãåöòÿ°äÿþ°äãåý°¼öÿÿâà°ñ°þù°ãþÿùäàõóèõ°õûùü°¼ãõãñó°üñùóõàÃ\x9a"
|
|
17
|
+
"¾õüòñãþõàãùôþù°ãù°¼ýõâÿõøä°þõæÿâà½üüõç°ñ°õûùü°¼éäùüùòñôñõÂ\x9a"
|
|
18
|
+
"¾éóþñôþåôõâ°äåÿøäùç°õóþõããõ°ãþùñäõâ°¼üñùýÿþéüÿà°üñýùþùý°ñ°õûùü°¼õôÿó°õãâñàÃ\x9a"
|
|
19
|
+
"¾ãþÿùäóþåö°öÿ°õâåäñþ°âñõþùü°õøä°âÿââùý°õôÿó°âåÿ°þù°ãõùøóâñâõùø°äñüÖ\x9a"
|
|
20
|
+
"¾þÿùäñóùäãùøàÿã°öÿ°õüóñþþùà°õøä°ãù°ýâÿö°þù°éäùóùüàýùÃ\x9a"
|
|
21
|
+
"¾ãýõüòÿâà°äãõûâñô°õøä°ãõäñþùýåüüù°óù÷ÿü°þù°éäùâñüÓ\x9a"
|
|
22
|
+
"¾ãýøäùâÿ÷üñ°éûüåò°õøä°ãôþõóãþñâä°ãóùäñýõøäñý°þù°õóþñ÷õüÕ\x9a¾þÿùäñýùèÿâààñ°ãø÷ùõçäåÿ°þÿùãùóõâÀ\x9a\x9a"
|
|
23
|
+
"¾ãôñõâøä°þÿøäéÀ°õâåà°øäùç°ãýøäùâÿ÷üñ°âåÿ°õæñõç°õç°¼éâñåäóþñã°üñóùäñýõøäñý°ãùøä°þÙ\x9a\x9a"
|
|
24
|
+
"ùéñùÚ°þõøÃ°éò°¼ýåÞéÀéÀ°öÿ°þõʰõøÄ°°°°°°°°°°°°°°°°\x9a")
|
|
6
25
|
print("".join([chr(ord(_) ^ 144) for _ in Zen[::-1]]))
|
|
7
26
|
for _ in list(globals().keys()):
|
|
8
27
|
if _[0] != "_":
|
pypynum/tools.py
CHANGED
|
@@ -185,16 +185,18 @@ def primality(n: int, iter_num: int = 10) -> bool:
|
|
|
185
185
|
"""
|
|
186
186
|
Introduction
|
|
187
187
|
==========
|
|
188
|
-
|
|
188
|
+
This function checks if a number is a prime using the Miller-Rabin primality test,
|
|
189
|
+
which is a probabilistic test to determine if a number is a probable prime.
|
|
189
190
|
|
|
190
191
|
Example
|
|
191
192
|
==========
|
|
192
193
|
>>> primality(2 ** 4423 - 1)
|
|
193
194
|
True
|
|
194
195
|
>>>
|
|
195
|
-
:param n:
|
|
196
|
-
:param iter_num:
|
|
197
|
-
|
|
196
|
+
:param n: The number to be tested for primality.
|
|
197
|
+
:param iter_num: The number of iterations for the test, which affects the accuracy.
|
|
198
|
+
More iterations reduce the probability of falsely identifying a composite number as prime.
|
|
199
|
+
:return: True if the number is a probable prime, False otherwise.
|
|
198
200
|
"""
|
|
199
201
|
from random import randint
|
|
200
202
|
if n == 2:
|
|
@@ -218,76 +220,100 @@ def primality(n: int, iter_num: int = 10) -> bool:
|
|
|
218
220
|
return True
|
|
219
221
|
|
|
220
222
|
|
|
221
|
-
def
|
|
223
|
+
def primes(limit: int) -> list:
|
|
222
224
|
"""
|
|
223
225
|
Introduction
|
|
224
226
|
==========
|
|
225
|
-
|
|
227
|
+
This function generates a list of prime numbers up to a specified limit.
|
|
226
228
|
|
|
227
229
|
Example
|
|
228
230
|
==========
|
|
229
|
-
>>>
|
|
231
|
+
>>> primes(100)
|
|
230
232
|
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
|
|
231
233
|
>>>
|
|
232
|
-
:param limit:
|
|
233
|
-
:return:
|
|
234
|
+
:param limit: The upper limit to which prime numbers are to be found (inclusive).
|
|
235
|
+
:return: A list of prime numbers up to the specified limit.
|
|
234
236
|
"""
|
|
235
|
-
|
|
236
|
-
|
|
237
|
+
result = list(range(limit + 1))
|
|
238
|
+
result[1] = 0
|
|
237
239
|
p = 2
|
|
238
240
|
s = 4
|
|
239
241
|
while s <= limit:
|
|
240
|
-
if
|
|
242
|
+
if result[p]:
|
|
241
243
|
for i in range(s, limit + 1, p):
|
|
242
|
-
|
|
244
|
+
result[i] = 0
|
|
243
245
|
p += 1
|
|
244
246
|
s = p * p
|
|
245
|
-
return [x for x in
|
|
247
|
+
return [x for x in result if x != 0]
|
|
246
248
|
|
|
247
249
|
|
|
248
|
-
def
|
|
250
|
+
def semiprimes(limit: int) -> list:
|
|
249
251
|
"""
|
|
250
252
|
Introduction
|
|
251
253
|
==========
|
|
252
|
-
|
|
254
|
+
This function generates a list of semiprime numbers up to a specified limit.
|
|
255
|
+
A semiprime is a natural number that is the product of two prime numbers.
|
|
253
256
|
|
|
254
257
|
Example
|
|
255
258
|
==========
|
|
256
|
-
>>>
|
|
259
|
+
>>> semiprimes(64)
|
|
257
260
|
[4, 6, 9, 10, 14, 15, 21, 22, 25, 26, 33, 34, 35, 38, 39, 46, 49, 51, 55, 57, 58, 62]
|
|
258
261
|
>>>
|
|
259
|
-
:param limit:
|
|
260
|
-
:return:
|
|
262
|
+
:param limit: The upper limit to which semiprime numbers are to be found (inclusive).
|
|
263
|
+
:return: A list of semiprime numbers up to the specified limit.
|
|
261
264
|
"""
|
|
262
|
-
|
|
263
|
-
length = len(
|
|
264
|
-
|
|
265
|
+
ps = primes(limit // 2)
|
|
266
|
+
length = len(ps)
|
|
267
|
+
result = []
|
|
265
268
|
for i in range(length):
|
|
266
|
-
first =
|
|
269
|
+
first = ps[i]
|
|
267
270
|
maximum = limit // first
|
|
268
271
|
for j in range(i, length):
|
|
269
|
-
second =
|
|
272
|
+
second = ps[j]
|
|
270
273
|
if second > maximum:
|
|
271
274
|
break
|
|
272
|
-
|
|
273
|
-
return sorted(
|
|
275
|
+
result.append(first * second)
|
|
276
|
+
return sorted(result)
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
def twinprimes(limit: int) -> list:
|
|
280
|
+
"""
|
|
281
|
+
Introduction
|
|
282
|
+
==========
|
|
283
|
+
This function generates a list of twin prime pairs up to a specified limit.
|
|
284
|
+
Twin primes are a pair of prime numbers that have a difference of two.
|
|
285
|
+
|
|
286
|
+
Example
|
|
287
|
+
==========
|
|
288
|
+
>>> twinprimes(100)
|
|
289
|
+
[(3, 5), (5, 7), (11, 13), (17, 19), (29, 31), (41, 43), (59, 61), (71, 73)]
|
|
290
|
+
>>>
|
|
291
|
+
:param limit: The upper limit to which twin prime pairs are to be found (inclusive).
|
|
292
|
+
:return: A list of twin prime pairs up to the specified limit.
|
|
293
|
+
"""
|
|
294
|
+
ps = primes(limit)
|
|
295
|
+
return [(p, p + 2) for p in ps if p + 2 in ps]
|
|
274
296
|
|
|
275
297
|
|
|
276
298
|
def prime_factors(integer: int, dictionary: bool = False, pollard_rho: bool = True) -> Union[list, dict]:
|
|
277
299
|
"""
|
|
278
300
|
Introduction
|
|
279
301
|
==========
|
|
280
|
-
|
|
302
|
+
This function computes the prime factors of a given integer. It can return the factors
|
|
303
|
+
as a list or a dictionary, and it can use the Pollard's rho algorithm for factorization.
|
|
281
304
|
|
|
282
305
|
Example
|
|
283
306
|
==========
|
|
284
307
|
>>> prime_factors(2305567963945518424753102147331756070)
|
|
285
308
|
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
|
|
286
309
|
>>>
|
|
287
|
-
:param integer: integer
|
|
288
|
-
:param dictionary:
|
|
289
|
-
|
|
290
|
-
:
|
|
310
|
+
:param integer: The integer to be factorized.
|
|
311
|
+
:param dictionary: A boolean indicating whether to return the factors as a dictionary with the prime factors as
|
|
312
|
+
keys and their counts as values.
|
|
313
|
+
:param pollard_rho: A boolean indicating whether to use Pollard's rho algorithm for factorization. If False,
|
|
314
|
+
a simple trial division method is used.
|
|
315
|
+
:return: A list of prime factors or a dictionary with prime factors and their counts, depending on the
|
|
316
|
+
'dictionary' parameter.
|
|
291
317
|
"""
|
|
292
318
|
from math import gcd
|
|
293
319
|
from random import randint
|
|
@@ -338,7 +364,7 @@ def prime_factors(integer: int, dictionary: bool = False, pollard_rho: bool = Tr
|
|
|
338
364
|
else:
|
|
339
365
|
return sorted(output)
|
|
340
366
|
else:
|
|
341
|
-
return []
|
|
367
|
+
return {} if dictionary else []
|
|
342
368
|
|
|
343
369
|
|
|
344
370
|
def magic_square(n):
|
|
File without changes
|
|
File without changes
|