PyPyNum 1.5.0__py3-none-any.whl → 1.5.2__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.
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyPyNum
3
- Version: 1.5.0
4
- Summary: A Python math package written in pure Python programming language [python_requires >= 3.5]
3
+ Version: 1.5.2
4
+ Summary: A multifunctional mathematical calculation package written in pure Python programming language [Python>=3.5]
5
5
  Home-page: https://www.gitee.com/PythonSJL/PyPyNum
6
6
  Author: Shen Jiayi
7
7
  Author-email: 2261748025@qq.com
@@ -673,8 +673,8 @@ Description-Content-Type: text/markdown
673
673
 
674
674
  # <font color = blue>PyPyNum</font>
675
675
 
676
- <font color = gree>A Python math package written in pure Python programming language</font> <font color = red>(
677
- python_requires >= 3.5)</font>
676
+ <font color = gree>A Python math package written in pure Python programming language</font><font color = red>
677
+ (python_requires >= 3.5)</font>
678
678
 
679
679
  ```
680
680
  ________ ___ ___ ________ ___ ___ ________ ___ ___ _____ ______
@@ -687,10 +687,14 @@ python_requires >= 3.5)</font>
687
687
  \|___|/ \|___|/
688
688
  ```
689
689
 
690
- ## Version -> 1.5.0 | PyPI -> https://pypi.org/project/PyPyNum/ | Gitee -> https://www.gitee.com/PythonSJL/PyPyNum
690
+ ## Version -> 1.5.2 | PyPI -> https://pypi.org/project/PyPyNum/ | Gitee -> https://www.gitee.com/PythonSJL/PyPyNum
691
691
 
692
692
  ![LOGO](PyPyNum.png)
693
693
 
694
+ PyPI上无法显示logo,可以在Gitee中查看。
695
+
696
+ The logo cannot be displayed on PyPI, it can be viewed in Gitee.
697
+
694
698
  ### 介绍
695
699
 
696
700
  #### Introduction
@@ -702,20 +706,27 @@ python_requires >= 3.5)</font>
702
706
  + 如需联系,QQ 2261748025 (Py𝙿𝚢𝚝𝚑𝚘𝚗-水晶兰)
703
707
  + If you need to contact, QQ 2261748025 (Py𝙿𝚢𝚝𝚑𝚘𝚗-水晶兰)
704
708
 
705
- ### PyPyNum的Zen
709
+ ### PyPyNum的Zen(预览)
706
710
 
707
- #### The Zen of PyPyNum
711
+ #### The Zen of PyPyNum (Preview)
708
712
 
709
713
  ```
710
714
  The Zen of PyPyNum, by Shen Jiayi
711
715
 
712
716
  This is a math package written purely in Python.
713
717
 
714
- ... (Do you want to see the entire content?
715
- Then enter "from pypynum import this" on your
718
+ Elegant is superior to clunky.
719
+ Clarity trumps obscurity.
720
+ Straightforwardness is preferred over convolution.
721
+ Sophisticated is better than overcomplicated.
722
+ Flat structure beats nested hierarchies.
723
+ Sparse code wins over bloated ones.
724
+
725
+ ... (Do you want to view all the content?
726
+ Enter "from pypynum import this" in your
716
727
  Python interpreter and run it!)
717
728
 
718
- December 27, 2023
729
+ February 27, 2024
719
730
  ```
720
731
 
721
732
  ### 与上一个版本相比新增功能
@@ -725,88 +736,69 @@ Python interpreter and run it!)
725
736
  ```
726
737
  !=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
727
738
 
728
- “Symbolics”模块中的希腊字母字符串中存
729
- 在错误,已更正
730
- There is an error in the Greek
731
- letter string in the "Symbolics"
732
- module, which has been corrected
739
+ 重写了PyPyNum的Zen。
740
+
741
+ Rewrote the Zen of PyPyNum.
742
+
743
+ !=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
744
+
745
+ “maths”模块的一些功能已经进行了优化,
746
+ 以实现更快的运行速度。
747
+
748
+ Some functions of the "maths"
749
+ module have been optimized to
750
+ achieve faster running speed.
733
751
 
734
752
  !=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
735
753
 
736
- 傅立叶变换的类“FT1D”在数据末尾设置自动
737
- 零填充,直到数据长度达到2的正整数幂
738
- The class "FT1D" of Fourier
739
- transform sets automatic zero
740
- padding at the end of the data
741
- until the data length reaches a
742
- positive integer power of 2
754
+ 修复了“tools”模块中的“split”函数导致
755
+ 的字符串分割错误。
756
+
757
+ Fixed string splitting error
758
+ caused by the "split" function
759
+ in the "tools" module.
743
760
 
744
761
  !=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
745
762
 
746
- plotting”模块中添加了一个非常有用的
747
- “color”函数,可用于使字符串或其他类型
748
- 的数据着色。
749
- A very useful "color" function
750
- has been added to the "plotting"
751
- module, which can be used to
752
- make strings or other types of
753
- data colored.
754
-
755
- 您可以使用此函数为字符上色,然后将其用作
756
- 绘制函数曲线的字符,并将“coloration”
757
- 参数设置为“True”(可能仅适用于
758
- PyCharm等编程软件)
759
- You can use this function to
760
- color a character, then use it
761
- as the character to draw the
762
- function curve, and set the
763
- "color" parameter to "True"
764
- (which may only be applicable to
765
- programming software like
766
- PyCharm)
763
+ sequence”模块设置为每个序列返回单独
764
+ 的第n项或包含第0到第n项的列表的功能。
765
+
766
+ The "sequence" module sets the
767
+ function of returning a separate
768
+ nth item or a list containing
769
+ 0th to nth items for each
770
+ sequence.
771
+
772
+
773
+ “geometric_sequence”函数补充了一个
774
+ 情况的求解函数,并且已经证实,其余两个情
775
+ 况没有解析解,需要使用多项式方程来求解。
776
+
777
+ The "geometric_sequence"
778
+ function supplements the solving
779
+ function for one scenario, and
780
+ it has been confirmed that there
781
+ are no analytical solutions for
782
+ the remaining two scenarios,
783
+ which need to be solved using
784
+ polynomial equations for
785
+ implementation.
767
786
 
768
787
  !=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
769
788
 
770
- <The "+" indicates the newly added method>
771
-
772
- [This is the base class of vectors, matrices, and tensors]
773
-
774
- Array(data=None, check=True)
775
- __add__(self, other)
776
- __eq__(self, other)
777
- __getitem__(self, item)
778
- __hash__(self)
779
- __init__(self, data=None, check=True)
780
- __ne__(self, other)
781
- __radd__(self, other)
782
- __repr__(self)
783
- __round__(self, n=None)
784
- __str__(self)
785
- argmax(self, axis=None) +
786
- argmin(self, axis=None) +
787
- basic(self, func, axis=None) +
788
- copy(self)
789
- flatten(self)
790
- max(self, axis=None) +
791
- mean(self, axis=None) +
792
- median(self, axis=None) +
793
- min(self, axis=None) +
794
- mode(self, axis=None) +
795
- product(self, axis=None) +
796
- ptp(self, axis=None) +
797
- reshape(self, shape)
798
- std(self, axis=None) +
799
- sum(self, axis=None) +
800
- var(self, axis=None) +
789
+ <<<The "+" indicates the newly added method>>>
801
790
 
802
791
  maths [Mathematical functions]
803
- root(x: num, y: num) -> num +
804
792
  ...
805
- cumsum(lst: arr) -> list +
806
- cumprod(lst: arr) -> list +
807
- iroot(y: int, n: int) -> int +
793
+ geom_mean(numbers: arr) -> num +
794
+ square_mean(numbers: arr) -> num +
795
+ harm_mean(numbers: arr) -> num +
796
+ ...
808
797
 
809
- <<< Other modules also have certain modifications >>>
798
+ sequence [Various sequences]
799
+ ...
800
+ recaman(n: int, single: bool = True) -> Union[int, list] +
801
+ ...
810
802
  ```
811
803
 
812
804
  ### 运行用时测试
@@ -1047,8 +1039,14 @@ PyPyNum
1047
1039
  freq(data: arr) -> dict
1048
1040
  mode(data: arr)
1049
1041
  mean(numbers: arr) -> num
1042
+ geom_mean(numbers: arr) -> num
1043
+ square_mean(numbers: arr) -> num
1044
+ harm_mean(numbers: arr) -> num
1050
1045
  var(numbers: arr) -> num
1051
1046
  std(numbers: arr) -> num
1047
+ cov(x: arr, y: arr) -> num
1048
+ corr_coeff(x: arr, y: arr) -> num
1049
+ coeff_det(x: arr, y: arr) -> num
1052
1050
  product(numbers: arr) -> num
1053
1051
  sigma(i: int, n: int, f) -> num
1054
1052
  pi(i: int, n: int, f) -> num
@@ -1096,9 +1094,12 @@ PyPyNum
1096
1094
  polynomial_regression(x: Union[list, tuple], y: Union[list, tuple], n: int = None) -> list
1097
1095
  ★ sequence [Various sequences]
1098
1096
  FUNCTIONS
1097
+ fibonacci(n: int, single: bool = True) -> Union[int, list]
1098
+ catalan(n: int, single: bool = True) -> Union[int, list]
1099
1099
  bernoulli(n: int, single: bool = True) -> list
1100
- catalan(n: int) -> int
1101
- fibonacci(n: int) -> int
1100
+ recaman(n: int, single: bool = True) -> Union[int, list]
1101
+ arithmetic_sequence(*, a1: real = None, an: real = None, d: real = None, n: real = None, s: real = None) -> dict
1102
+ geometric_sequence(*, a1: real = None, an: real = None, r: real = None, n: real = None, s: real = None) -> dict
1102
1103
  ★ tools [Other useful tools]
1103
1104
  FUNCTIONS
1104
1105
  classify(array: Union[list, tuple]) -> dict
@@ -3,32 +3,32 @@ pypynum/FourierT.py,sha256=AtG0tESykzEs4gDsXhcizW7qhQnmw0gjcWcXefBqzhs,1401
3
3
  pypynum/Geometry.py,sha256=bJCuif-wHO-t7oHFEE7ntzIdQwzUEbT3mcKgmBV6Wps,13982
4
4
  pypynum/Group.py,sha256=m39OZNRoG9b3p_7sS1u50A0rJl0aYqYPVvnttkYQ_gw,2944
5
5
  pypynum/Logic.py,sha256=IJAv59ECHU0HmG9lYCAQ_puqeL6Zor3-IDIVH48KBWE,11000
6
- pypynum/Matrix.py,sha256=tDo7lFesMmIKula-zbq3UaleW8HshF1LUr8MuT16_oM,10915
6
+ pypynum/Matrix.py,sha256=NLwrjpikZRsT8_tdH20NMFnDh2S2iY_XMOyOJAZQK8w,10771
7
7
  pypynum/NeuralN.py,sha256=iSOvC9JW1h4AFGokGGOTkKie5hAYN_YT9H4f3apI9b8,3275
8
8
  pypynum/PyPyNum.png,sha256=t96tJPWfHxT8kcXm_qZI2z5W36TgOqjCU9qdgbmlFws,11623
9
9
  pypynum/Quaternion.py,sha256=E7ajc4sDJyOuQQIwKPhUEHgiaeeR5BEzFZHhJMxvbok,8007
10
- pypynum/README.md,sha256=5nzL_Oz3cAPzO8S2MFS15lW6Kt0JH4rz_7ffhIZ_UaY,39546
10
+ pypynum/README.md,sha256=CMrWRhCKqn8BIB_2uIgj2ix2NYCbpYp254IMRes3P-8,39841
11
11
  pypynum/Symbolics.py,sha256=Nfo0DEch7LII53ye1wZAdIfd3IAOKbECnZQMSk_cmCs,2898
12
12
  pypynum/Tensor.py,sha256=FIeRh0BS_N7Mr_1l_7wv63_BmacjMpit4ydEkXhGaz0,3614
13
13
  pypynum/Vector.py,sha256=V_d3sUtr5IEzxqA_ZqjYDuZKCIkkV3kod9Wv8DZYLy0,3310
14
- pypynum/__init__.py,sha256=zbDAv1MIKOszPg-ac1gYGU8shoXECuFIb5JB3TrscP0,1658
14
+ pypynum/__init__.py,sha256=yBTYauFR5w4ThCCyUWhPakWUYJwnGUUq8hDiHZ5HVN0,1658
15
15
  pypynum/__temporary.py,sha256=OAs7it7xjDovgAmKLcj-9Pqp0228SSon3OZx0ih_h4I,5860
16
16
  pypynum/cipher.py,sha256=J5PZl8Xt71LuX29eSBu4cybNK6Z3rhA9og_YzD0YJfU,1002
17
17
  pypynum/constants.py,sha256=h9zkrZkoTaJ0l8OhXcFlFJFF3ndG94IrAp3V-1ujsD0,806
18
18
  pypynum/equations.py,sha256=_4xIXr7A56qBXKzJXyb91L4h09H7TDVNrcufy-XxkaI,744
19
19
  pypynum/errors.py,sha256=11-Au4aV8H5ExaDuMtu5iuGvpRaJP8gW7XbGNRmefSI,173
20
20
  pypynum/file.py,sha256=rqrPdcX0NOEPM8s40-ymgPKsTn0HKABW-VEh1OtPnsk,3188
21
- pypynum/maths.py,sha256=2SpP0N2yL98aM_dHfNrm5QSN1JGxWxfxDQYZrH_Hglw,15711
21
+ pypynum/maths.py,sha256=psjcH4_Mfg9vd2QOETNlimbopsMl8yM33TpXrbS5noI,18792
22
22
  pypynum/plotting.py,sha256=YQg9sO_nuLSaAKQuSpebWVvbu-ns2A7JOrHch6r0FQ0,8326
23
23
  pypynum/probability.py,sha256=kZLCfZb2q_y1CVbozSZj9xQ8Dw3il5WcAojX0jsNyXw,2130
24
24
  pypynum/random.py,sha256=vfTtyH5yOSKJoSI_-NT_Tg8wC-ZXT0wt34f87oaSpJY,4610
25
25
  pypynum/regression.py,sha256=D9J9lM23HiyY4eE8vHKaHoiwuvD1RYhkVNO0jQ4yml4,2118
26
- pypynum/sequence.py,sha256=dWhdBZxU_ttQqNR4TMPJMcPqSrrepecnkwI_Q4OrKTQ,1425
26
+ pypynum/sequence.py,sha256=JtRc3pkhso71ZeabxHluyVmTDcoKUKbUcGyk5F4MLdA,6554
27
27
  pypynum/test.py,sha256=Bksa7HZaywKBbLaCw2R5kGRFj6eKzkkJ7BdJBgIB3uM,8428
28
- pypynum/this.py,sha256=z2HU548nVf7yDdsm7Cpzjf55lUVvp7fdHh8XDjokDBU,2406
29
- pypynum/tools.py,sha256=KXSK-IRYdU3kRDLdnJB0hXRvqxUMwGpYe6Vkz6chhKo,6396
28
+ pypynum/this.py,sha256=8Swp75xE5g6436NCVDfYUVwUzUcQFPLcCNFWQWY5eGQ,2129
29
+ pypynum/tools.py,sha256=8oMApp9ElC_VXlZZl4_ZrGuXZGwNOc0MVA4aigg06Ww,7268
30
30
  pypynum/types.py,sha256=CVWPZo_ACr_QGH5gAOhoG3jK35peiqipu3PH8ScEYHE,181
31
- PyPyNum-1.5.0.dist-info/METADATA,sha256=bVGkhwYBA3Gb6C1Lyr0qaqxQppLSMyjfDURAfh1Gej8,80363
32
- PyPyNum-1.5.0.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
33
- PyPyNum-1.5.0.dist-info/top_level.txt,sha256=4wW_Xb4bRglmiMsdPAe9f75MkXhNpuN88H17g_Cr5u8,8
34
- PyPyNum-1.5.0.dist-info/RECORD,,
31
+ PyPyNum-1.5.2.dist-info/METADATA,sha256=NXHtN5_rvZmOYeKGNca9B1Hl6VMPCO2asADP_yV0PLw,80676
32
+ PyPyNum-1.5.2.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
33
+ PyPyNum-1.5.2.dist-info/top_level.txt,sha256=4wW_Xb4bRglmiMsdPAe9f75MkXhNpuN88H17g_Cr5u8,8
34
+ PyPyNum-1.5.2.dist-info/RECORD,,
pypynum/Matrix.py CHANGED
@@ -168,10 +168,8 @@ class Matrix(Array):
168
168
  if len(item) == 2:
169
169
  if isinstance(item[0], int) and isinstance(item[1], (int, slice)):
170
170
  return self.data[item[0]][item[1]]
171
- elif isinstance(item[0], slice) and isinstance(item[1], int):
172
- return self.t().data[item[1]][item[0]]
173
- elif isinstance(item[0], slice) and isinstance(item[1], slice):
174
- return Matrix(Matrix(self.data[item[0]]).t().data[item[1]]).t()
171
+ elif isinstance(item[0], slice) and isinstance(item[1], (int, slice)):
172
+ return [row[item[1]] for row in self.data[item[0]]]
175
173
  else:
176
174
  return []
177
175
  else:
pypynum/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # <font color = blue>PyPyNum</font>
2
2
 
3
- <font color = gree>A Python math package written in pure Python programming language</font> <font color = red>(
4
- python_requires >= 3.5)</font>
3
+ <font color = gree>A Python math package written in pure Python programming language</font><font color = red>
4
+ (python_requires >= 3.5)</font>
5
5
 
6
6
  ```
7
7
  ________ ___ ___ ________ ___ ___ ________ ___ ___ _____ ______
@@ -14,10 +14,14 @@ python_requires >= 3.5)</font>
14
14
  \|___|/ \|___|/
15
15
  ```
16
16
 
17
- ## Version -> 1.5.0 | PyPI -> https://pypi.org/project/PyPyNum/ | Gitee -> https://www.gitee.com/PythonSJL/PyPyNum
17
+ ## Version -> 1.5.2 | PyPI -> https://pypi.org/project/PyPyNum/ | Gitee -> https://www.gitee.com/PythonSJL/PyPyNum
18
18
 
19
19
  ![LOGO](PyPyNum.png)
20
20
 
21
+ PyPI上无法显示logo,可以在Gitee中查看。
22
+
23
+ The logo cannot be displayed on PyPI, it can be viewed in Gitee.
24
+
21
25
  ### 介绍
22
26
 
23
27
  #### Introduction
@@ -29,20 +33,27 @@ python_requires >= 3.5)</font>
29
33
  + 如需联系,QQ 2261748025 (Py𝙿𝚢𝚝𝚑𝚘𝚗-水晶兰)
30
34
  + If you need to contact, QQ 2261748025 (Py𝙿𝚢𝚝𝚑𝚘𝚗-水晶兰)
31
35
 
32
- ### PyPyNum的Zen
36
+ ### PyPyNum的Zen(预览)
33
37
 
34
- #### The Zen of PyPyNum
38
+ #### The Zen of PyPyNum (Preview)
35
39
 
36
40
  ```
37
41
  The Zen of PyPyNum, by Shen Jiayi
38
42
 
39
43
  This is a math package written purely in Python.
40
44
 
41
- ... (Do you want to see the entire content?
42
- Then enter "from pypynum import this" on your
45
+ Elegant is superior to clunky.
46
+ Clarity trumps obscurity.
47
+ Straightforwardness is preferred over convolution.
48
+ Sophisticated is better than overcomplicated.
49
+ Flat structure beats nested hierarchies.
50
+ Sparse code wins over bloated ones.
51
+
52
+ ... (Do you want to view all the content?
53
+ Enter "from pypynum import this" in your
43
54
  Python interpreter and run it!)
44
55
 
45
- December 27, 2023
56
+ February 27, 2024
46
57
  ```
47
58
 
48
59
  ### 与上一个版本相比新增功能
@@ -52,88 +63,69 @@ Python interpreter and run it!)
52
63
  ```
53
64
  !=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
54
65
 
55
- “Symbolics”模块中的希腊字母字符串中存
56
- 在错误,已更正
57
- There is an error in the Greek
58
- letter string in the "Symbolics"
59
- module, which has been corrected
66
+ 重写了PyPyNum的Zen。
67
+
68
+ Rewrote the Zen of PyPyNum.
69
+
70
+ !=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
71
+
72
+ “maths”模块的一些功能已经进行了优化,
73
+ 以实现更快的运行速度。
74
+
75
+ Some functions of the "maths"
76
+ module have been optimized to
77
+ achieve faster running speed.
60
78
 
61
79
  !=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
62
80
 
63
- 傅立叶变换的类“FT1D”在数据末尾设置自动
64
- 零填充,直到数据长度达到2的正整数幂
65
- The class "FT1D" of Fourier
66
- transform sets automatic zero
67
- padding at the end of the data
68
- until the data length reaches a
69
- positive integer power of 2
81
+ 修复了“tools”模块中的“split”函数导致
82
+ 的字符串分割错误。
83
+
84
+ Fixed string splitting error
85
+ caused by the "split" function
86
+ in the "tools" module.
70
87
 
71
88
  !=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
72
89
 
73
- plotting”模块中添加了一个非常有用的
74
- “color”函数,可用于使字符串或其他类型
75
- 的数据着色。
76
- A very useful "color" function
77
- has been added to the "plotting"
78
- module, which can be used to
79
- make strings or other types of
80
- data colored.
81
-
82
- 您可以使用此函数为字符上色,然后将其用作
83
- 绘制函数曲线的字符,并将“coloration”
84
- 参数设置为“True”(可能仅适用于
85
- PyCharm等编程软件)
86
- You can use this function to
87
- color a character, then use it
88
- as the character to draw the
89
- function curve, and set the
90
- "color" parameter to "True"
91
- (which may only be applicable to
92
- programming software like
93
- PyCharm)
90
+ sequence”模块设置为每个序列返回单独
91
+ 的第n项或包含第0到第n项的列表的功能。
92
+
93
+ The "sequence" module sets the
94
+ function of returning a separate
95
+ nth item or a list containing
96
+ 0th to nth items for each
97
+ sequence.
98
+
99
+
100
+ “geometric_sequence”函数补充了一个
101
+ 情况的求解函数,并且已经证实,其余两个情
102
+ 况没有解析解,需要使用多项式方程来求解。
103
+
104
+ The "geometric_sequence"
105
+ function supplements the solving
106
+ function for one scenario, and
107
+ it has been confirmed that there
108
+ are no analytical solutions for
109
+ the remaining two scenarios,
110
+ which need to be solved using
111
+ polynomial equations for
112
+ implementation.
94
113
 
95
114
  !=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
96
115
 
97
- <The "+" indicates the newly added method>
98
-
99
- [This is the base class of vectors, matrices, and tensors]
100
-
101
- Array(data=None, check=True)
102
- __add__(self, other)
103
- __eq__(self, other)
104
- __getitem__(self, item)
105
- __hash__(self)
106
- __init__(self, data=None, check=True)
107
- __ne__(self, other)
108
- __radd__(self, other)
109
- __repr__(self)
110
- __round__(self, n=None)
111
- __str__(self)
112
- argmax(self, axis=None) +
113
- argmin(self, axis=None) +
114
- basic(self, func, axis=None) +
115
- copy(self)
116
- flatten(self)
117
- max(self, axis=None) +
118
- mean(self, axis=None) +
119
- median(self, axis=None) +
120
- min(self, axis=None) +
121
- mode(self, axis=None) +
122
- product(self, axis=None) +
123
- ptp(self, axis=None) +
124
- reshape(self, shape)
125
- std(self, axis=None) +
126
- sum(self, axis=None) +
127
- var(self, axis=None) +
116
+ <<<The "+" indicates the newly added method>>>
128
117
 
129
118
  maths [Mathematical functions]
130
- root(x: num, y: num) -> num +
131
119
  ...
132
- cumsum(lst: arr) -> list +
133
- cumprod(lst: arr) -> list +
134
- iroot(y: int, n: int) -> int +
120
+ geom_mean(numbers: arr) -> num +
121
+ square_mean(numbers: arr) -> num +
122
+ harm_mean(numbers: arr) -> num +
123
+ ...
135
124
 
136
- <<< Other modules also have certain modifications >>>
125
+ sequence [Various sequences]
126
+ ...
127
+ recaman(n: int, single: bool = True) -> Union[int, list] +
128
+ ...
137
129
  ```
138
130
 
139
131
  ### 运行用时测试
@@ -374,8 +366,14 @@ PyPyNum
374
366
  freq(data: arr) -> dict
375
367
  mode(data: arr)
376
368
  mean(numbers: arr) -> num
369
+ geom_mean(numbers: arr) -> num
370
+ square_mean(numbers: arr) -> num
371
+ harm_mean(numbers: arr) -> num
377
372
  var(numbers: arr) -> num
378
373
  std(numbers: arr) -> num
374
+ cov(x: arr, y: arr) -> num
375
+ corr_coeff(x: arr, y: arr) -> num
376
+ coeff_det(x: arr, y: arr) -> num
379
377
  product(numbers: arr) -> num
380
378
  sigma(i: int, n: int, f) -> num
381
379
  pi(i: int, n: int, f) -> num
@@ -423,9 +421,12 @@ PyPyNum
423
421
  polynomial_regression(x: Union[list, tuple], y: Union[list, tuple], n: int = None) -> list
424
422
  ★ sequence [Various sequences]
425
423
  FUNCTIONS
424
+ fibonacci(n: int, single: bool = True) -> Union[int, list]
425
+ catalan(n: int, single: bool = True) -> Union[int, list]
426
426
  bernoulli(n: int, single: bool = True) -> list
427
- catalan(n: int) -> int
428
- fibonacci(n: int) -> int
427
+ recaman(n: int, single: bool = True) -> Union[int, list]
428
+ arithmetic_sequence(*, a1: real = None, an: real = None, d: real = None, n: real = None, s: real = None) -> dict
429
+ geometric_sequence(*, a1: real = None, an: real = None, r: real = None, n: real = None, s: real = None) -> dict
429
430
  ★ tools [Other useful tools]
430
431
  FUNCTIONS
431
432
  classify(array: Union[list, tuple]) -> dict
pypynum/__init__.py CHANGED
@@ -33,7 +33,7 @@ from .tools import *
33
33
  from . import types
34
34
  from .Vector import vec
35
35
 
36
- __version__ = "1.5.0"
36
+ __version__ = "1.5.2"
37
37
  print("PyPyNum", "Version -> " + __version__, "PyPI -> https://pypi.org/project/PyPyNum/",
38
38
  "Gitee -> https://www.gitee.com/PythonSJL/PyPyNum", sep=" | ")
39
39
  del math, arr, ite, num, real, geom, RandomError, LogicError, InputError, FullError, Union
pypynum/maths.py CHANGED
@@ -424,6 +424,57 @@ def mean(numbers: arr) -> num:
424
424
  return sum(numbers) / len(numbers)
425
425
 
426
426
 
427
+ def geom_mean(numbers: arr) -> num:
428
+ """
429
+ introduction
430
+ ==========
431
+ The geometric mean of numbers
432
+
433
+ example
434
+ ==========
435
+ >>> geom_mean([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
436
+ 4.528728688116765
437
+ >>>
438
+ :param numbers: list | tuple
439
+ :return:
440
+ """
441
+ return root(product(numbers), len(numbers))
442
+
443
+
444
+ def square_mean(numbers: arr) -> num:
445
+ """
446
+ introduction
447
+ ==========
448
+ Square mean of numbers
449
+
450
+ example
451
+ ==========
452
+ >>> square_mean([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
453
+ 6.2048368229954285
454
+ >>>
455
+ :param numbers: list | tuple
456
+ :return:
457
+ """
458
+ return (sum(map(lambda n: n * n, numbers)) / len(numbers)) ** 0.5
459
+
460
+
461
+ def harm_mean(numbers: arr) -> num:
462
+ """
463
+ introduction
464
+ ==========
465
+ The harmonic mean of numbers
466
+
467
+ example
468
+ ==========
469
+ >>> harm_mean([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
470
+ 3.414171521474055
471
+ >>>
472
+ :param numbers: list | tuple
473
+ :return:
474
+ """
475
+ return 0 if 0 in numbers else len(numbers) / sum(map(lambda n: 1 / n, numbers))
476
+
477
+
427
478
  def var(numbers: arr) -> num:
428
479
  """
429
480
  introduction
@@ -459,6 +510,70 @@ def std(numbers: arr) -> num:
459
510
  return var(numbers) ** 0.5
460
511
 
461
512
 
513
+ def cov(x: arr, y: arr) -> num:
514
+ """
515
+ introduction
516
+ ==========
517
+ Covariance of numbers
518
+
519
+ example
520
+ ==========
521
+ >>> cov([1, 2, 3, 4, 5], [6, 7, 8, 9, 10])
522
+ 2.0
523
+ >>>
524
+ :param x: list | tuple
525
+ :param y: list | tuple
526
+ :return:
527
+ """
528
+ mean_x = mean(x)
529
+ mean_y = mean(y)
530
+ return sum([(x_i - mean_x) * (y_i - mean_y) for x_i, y_i in zip(x, y)]) / len(x)
531
+
532
+
533
+ def corr_coeff(x: arr, y: arr) -> num:
534
+ """
535
+ introduction
536
+ ==========
537
+ The correlation coefficient of numbers
538
+
539
+ example
540
+ ==========
541
+ >>> corr_coeff([1, 2, 3, 4, 5], [6, 7, 8, 9, 10])
542
+ 0.9999999999999998
543
+ >>>
544
+ :param x: list | tuple
545
+ :param y: list | tuple
546
+ :return:
547
+ """
548
+ if len(set(y)) == 1:
549
+ return 1.0
550
+ n = len(x)
551
+ mean_x = mean(x)
552
+ mean_y = mean(y)
553
+ covariance = sum((_x - mean_x) * (_y - mean_y) for _x, _y in zip(x, y)) / n
554
+ std_x = (sum((_x - mean_x) ** 2 for _x in x) / n) ** 0.5
555
+ std_y = (sum((_y - mean_y) ** 2 for _y in y) / n) ** 0.5
556
+ return covariance / (std_x * std_y)
557
+
558
+
559
+ def coeff_det(x: arr, y: arr) -> num:
560
+ """
561
+ introduction
562
+ ==========
563
+ The coefficient of determination for numbers
564
+
565
+ example
566
+ ==========
567
+ >>> coeff_det([1, 2, 3, 4, 5], [6, 7, 8, 9, 10])
568
+ 0.9999999999999996
569
+ >>>
570
+ :param x: list | tuple
571
+ :param y: list | tuple
572
+ :return:
573
+ """
574
+ return corr_coeff(x, y) ** 2
575
+
576
+
462
577
  def product(numbers: arr) -> num:
463
578
  """
464
579
  introduction
@@ -473,10 +588,29 @@ def product(numbers: arr) -> num:
473
588
  :param numbers: list | tuple
474
589
  :return:
475
590
  """
476
- result = 1
477
- for _ in numbers:
478
- result *= _
479
- return result
591
+ if len(numbers) == 0:
592
+ return 1
593
+ elif 0 in numbers:
594
+ return 0
595
+ elif len(numbers) == 1:
596
+ return numbers[0]
597
+ elif len(numbers) <= 4096:
598
+ result = numbers[0]
599
+ for i in numbers[1:]:
600
+ result *= i
601
+ return result
602
+
603
+ def prod(n):
604
+ if len(n) == 1:
605
+ return n[0]
606
+ mid = len(n) // 2
607
+ left_half = n[:mid]
608
+ right_half = n[mid:]
609
+ left_product = prod(left_half)
610
+ right_product = prod(right_half)
611
+ return left_product * right_product
612
+
613
+ return prod(numbers)
480
614
 
481
615
 
482
616
  def sigma(i: int, n: int, f) -> num:
@@ -652,6 +786,8 @@ def combination(n: int, r: int) -> int:
652
786
  :param r: integer
653
787
  :return:
654
788
  """
789
+ if r > n >> 1:
790
+ return combination(n, n - r)
655
791
  return product(list(range(n, n - r, -1))) // product(list(range(r, 0, -1)))
656
792
 
657
793
 
@@ -664,13 +800,13 @@ def zeta(alpha: real) -> float:
664
800
 
665
801
  example
666
802
  ==========
667
- >>> zeta(2)
668
- 1.6449339668472496
803
+ >>> zeta(3)
804
+ 1.202056903150321
669
805
  >>>
670
806
  :param alpha: integer | float
671
807
  :return:
672
808
  """
673
- return sum([1 / _ ** alpha for _ in range(1, 10000000)])
809
+ return sum(map(lambda _: _ ** (-alpha), range(1, 1000000)))
674
810
 
675
811
 
676
812
  def gaussian(x: real, _mu: real = 0, _sigma: real = 1) -> float:
@@ -845,7 +981,6 @@ def iroot(y: int, n: int) -> int:
845
981
  :param n: integer
846
982
  :return:
847
983
  """
848
- from math import log as _log
849
984
  i = False
850
985
  if y < 0 and n & 1:
851
986
  y = abs(y)
@@ -857,7 +992,7 @@ def iroot(y: int, n: int) -> int:
857
992
  try:
858
993
  g = int(y ** (1 / n) + 0.5)
859
994
  except OverflowError:
860
- e = _log(y, 2) / n
995
+ e = math.log(y, 2) / n
861
996
  if e > 53:
862
997
  s = int(e - 53)
863
998
  g = int(2 ** (e - s) + 1) << s
pypynum/sequence.py CHANGED
@@ -1,6 +1,16 @@
1
- def fibonacci(n: int) -> int:
1
+ from .types import Union, real
2
+
3
+
4
+ def fibonacci(n: int, single: bool = True) -> Union[int, list]:
2
5
  if isinstance(n, float):
3
6
  n = int(n)
7
+ if not single:
8
+ if n == 0:
9
+ return [0]
10
+ res = [0, 1]
11
+ for i in range(2, n + 1):
12
+ res.append(res[i - 1] + res[i - 2])
13
+ return res
4
14
 
5
15
  def mul(_a, _b):
6
16
  c = [[0, 0], [0, 0]]
@@ -22,12 +32,14 @@ def fibonacci(n: int) -> int:
22
32
  return res[0][1]
23
33
 
24
34
 
25
- def catalan(n: int) -> int:
35
+ def catalan(n: int, single: bool = True) -> Union[int, list]:
26
36
  try:
27
37
  from math import comb
28
38
  except ImportError:
29
39
  from .maths import combination as comb
30
- return comb(2 * n, n) // (n + 1)
40
+ if isinstance(n, float):
41
+ n = int(n)
42
+ return comb(2 * n, n) // (n + 1) if single else [comb(2 * x, x) // (x + 1) for x in range(n + 1)]
31
43
 
32
44
 
33
45
  def bernoulli(n: int, single: bool = True) -> list:
@@ -47,3 +59,117 @@ def bernoulli(n: int, single: bool = True) -> list:
47
59
  b = -s / (m + 1)
48
60
  result.append(b)
49
61
  return [result[n].numerator, result[n].denominator] if single else [[n.numerator, n.denominator] for n in result]
62
+
63
+
64
+ def recaman(n: int, single: bool = True) -> Union[int, list]:
65
+ if isinstance(n, float):
66
+ n = int(n)
67
+ seq = []
68
+ for i in range(n + 1):
69
+ if i == 0:
70
+ x = 0
71
+ else:
72
+ x = seq[i - 1] - i
73
+ if x >= 0 and x not in seq:
74
+ seq += [x]
75
+ else:
76
+ seq += [seq[i - 1] + i]
77
+ return seq[n] if single else seq
78
+
79
+
80
+ def arithmetic_sequence(*, a1: real = None, an: real = None, d: real = None, n: real = None, s: real = None) -> dict:
81
+ if [a1, an, d, n, s].count(None) != 2:
82
+ raise ValueError("Must provide exactly three valid parameters")
83
+
84
+ def solve_quadratic_equation(a, b, c):
85
+ delta = b ** 2 - 4 * a * c
86
+ if delta > 0:
87
+ x1 = (-b + delta ** 0.5) / (2 * a)
88
+ x2 = (-b - delta ** 0.5) / (2 * a)
89
+ return [x1, x2]
90
+ elif delta == 0:
91
+ x = -b / (2 * a)
92
+ return [x]
93
+ else:
94
+ return []
95
+
96
+ if any([not isinstance(val, (int, float, type(None))) for val in [a1, an, d, n, s]]):
97
+ raise ValueError("The input parameters must all be real numbers")
98
+ if a1 is not None and an is not None and d is not None:
99
+ n = (an - a1) / d + 1
100
+ s = n / 2 * (2 * a1 + (n - 1) * d)
101
+ elif a1 is not None and an is not None and n is not None:
102
+ d = (an - a1) / (n - 1)
103
+ s = n / 2 * (a1 + an)
104
+ elif a1 is not None and an is not None and s is not None:
105
+ n = s * 2 / (a1 + an)
106
+ d = (an - a1) / (n - 1)
107
+ elif a1 is not None and d is not None and n is not None:
108
+ an = a1 + (n - 1) * d
109
+ s = n / 2 * (2 * a1 + (n - 1) * d)
110
+ elif a1 is not None and d is not None and s is not None:
111
+ n = [item for item in solve_quadratic_equation(d, 2 * a1 - d, -2 * s) if item > 0]
112
+ if len(n) == 1:
113
+ n = n[0]
114
+ an = a1 + (n - 1) * d
115
+ elif a1 is not None and n is not None and s is not None:
116
+ an = 2 * s / n - a1
117
+ d = (an - a1) / (n - 1)
118
+ elif an is not None and d is not None and n is not None:
119
+ a1 = an - (n - 1) * d
120
+ s = n / 2 * (a1 + an)
121
+ elif an is not None and d is not None and s is not None:
122
+ n = [item for item in solve_quadratic_equation(-d, 2 * an + d, -2 * s) if item > 0]
123
+ if len(n) == 1:
124
+ n = n[0]
125
+ a1 = an - (n - 1) * d
126
+ elif an is not None and n is not None and s is not None:
127
+ d = (an * n - s) / (n * (n - 1) / 2)
128
+ a1 = an - (n - 1) * d
129
+ elif d is not None and n is not None and s is not None:
130
+ a1 = (s / n) - (d * (n - 1)) / 2
131
+ an = a1 + (n - 1) * d
132
+ if isinstance(n, list):
133
+ n = sorted(n)
134
+ return {"a1": a1, "an": an, "d": d, "n": n, "s": s}
135
+
136
+
137
+ def geometric_sequence(*, a1: real = None, an: real = None, r: real = None, n: real = None, s: real = None) -> dict:
138
+ from math import log
139
+ if [a1, an, r, n, s].count(None) != 2:
140
+ raise ValueError("Must provide exactly three valid parameters")
141
+ if any([not isinstance(val, (int, float, type(None))) for val in [a1, an, r, n, s]]):
142
+ raise ValueError("The input parameters must all be real numbers")
143
+ if a1 is not None and an is not None and r is not None:
144
+ n = log(an / a1, r) + 1
145
+ s = a1 * (r ** n - 1) / (r - 1) if r != 1 else a1 * n
146
+ elif a1 is not None and an is not None and n is not None:
147
+ r = (an / a1) ** (1 / (n - 1))
148
+ s = a1 * (r ** n - 1) / (r - 1) if r != 1 else a1 * n
149
+ elif a1 is not None and an is not None and s is not None:
150
+ r = (s - a1) / (s - an)
151
+ n = log(an / a1, r) + 1
152
+ elif a1 is not None and r is not None and n is not None:
153
+ an = a1 * r ** (n - 1)
154
+ s = a1 * (r ** n - 1) / (r - 1) if r != 1 else a1 * n
155
+ elif a1 is not None and r is not None and s is not None:
156
+ an = (s * r - s + a1) / r
157
+ n = log(an / a1, r) + 1
158
+ elif a1 is not None and n is not None and s is not None:
159
+ an = NotImplemented
160
+ r = NotImplemented
161
+ elif an is not None and r is not None and n is not None:
162
+ a1 = an / r ** (n - 1)
163
+ s = a1 * (r ** n - 1) / (r - 1) if r != 1 else a1 * n
164
+ elif an is not None and r is not None and s is not None:
165
+ a1 = s * (1 - r) + an * r
166
+ n = log(an / a1, r) + 1
167
+ elif an is not None and n is not None and s is not None:
168
+ a1 = NotImplemented
169
+ r = NotImplemented
170
+ elif r is not None and n is not None and s is not None:
171
+ a1 = s * (r - 1) / (r ** n - 1)
172
+ an = a1 * r ** (n - 1)
173
+ if isinstance(n, list):
174
+ n = sorted(n)
175
+ return {"a1": a1, "an": an, "r": r, "n": n, "s": s}
pypynum/this.py CHANGED
@@ -2,8 +2,8 @@
2
2
  The Zen of PyPyNum
3
3
  """
4
4
 
5
- Zen = 'rKJHJXTOJX\n\x1d\x1a\x15\x1d\x1b\x1d<XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXrrV\n\x19\x1d\x01X\x19X\x16\x11\x10\x0c\x11\x0fX\x14\x19\x17\x1fX\x0b\x11\x10\x0cX\x0b\x0b\x19\x08\n\r\x0bX\x16\x19\x1bX1rT\x10\x1f\r\x17\x16\x1dX\x0c\x0b\x19\x1eX\x0b\x11X\x1c\x1d\x1d\x08\x0bX\x1d\x0c\x19\x1c\x08\rX\x1d\x10\x0cX\x1e1rT\x0c\x1e\x1d\x14X\x0b\n\x19\x1d\x01X\x1e\x14\x19\x10X\x19X\x1c\x16\x19X\x1d\x16\x17X\x14\x14\x11\x0c\x0bX\x0b\x11X\x1d\n\x1d\x10,rrV\x14\x17\x17\x10\x1b\x0bX\x10\x1f\x11\x10X\x15\x17\n\x1eX\x1c\x1d\x0c\x19\r\x1c\x19\n\x1fX\x01\x1c\x19\x1d\n\x14\x19X\x1d\x0e\x19\x10X1X\x0b\x08\x19\x10\n\x1d(rT\x0b\x14\x19\x17\x1fX\x1f\x16\x11\x0e\x1d\x11\x10\x1b\x19X\x16\x1d\x10\x0fXT\x1d\x0b\n\r\x17\x1bX\x1e7rT\x1d\x1c\x17\x1bX\x1e\x17X\x0b\x1d\x16\x11\x14XHHHHIX\x1c\x1d\x1d\x1b\x00\x1dX\x17\x0cX\x0b\x15\x11\x19X\x1d\x1f\x19\x13\x1b\x19\x08X\x10\x0c\x19\x15X\x0b\x11\x10,rrV\x0c\x11X\x1d\x13\x11\x14X\x16\x19\x1bX\x1d\x16\x17\x01\n\x1d\x0e\x1dX\x1d\x08\x17\x10X1rT\x01(\x11\x1b+X\x1c\x16\x19X\x01(\x15\r6X\x0b\x19X\x10\x1b\r\x0bX\x0b\x1d\x1f\x19\x13\x1b\x19\x08r\x14\x19\x1b\x11\x0c\x19\x15\x1d\x10\x0c\x19\x15X\x1e\x17X\x16\x17\x11\x0c\n\x17\x08X\x14\x14\x19\x15\x0bX\x19X\x1d\x1b\x19\x14\x08\x1d\nX\x16\x19\x1bX\x0c1rT\x1d\x1f\x19\r\x1f\x16\x19\x14X;X\x1d\x0c\r\x1b\x1d\x00\x1dX\x0c\x17\x16\x16\x19\x1bX\x0b\n\x1d\x0c\x1d\n\x08\n\x1d\x0c\x16\x11X\x01(\x01(r\x0c\x19\x10\x0cX\x1d\x1f\x19\x0c\x16\x19\x0e\x1c\x19\x0b\x11\x1cX\x1d\x10\x0cX\n\x17\x1eX\x1d\x0c\x19\x0b\x16\x1d\x08\x15\x17\x1bX\x16\x19\x1bX\x0c\x11X\x0c\r:rT\x1d\x1f\x19\r\x1f\x16\x19\x14X;X\x0b\x19X\x0c\x0b\x19\x1eX\x0b\x19X\x0c\x17\x16X\x0b\x11X\x16\x17\x10\x0c\x01(X\x1d\n\r\x08X\x10\x1f\r\x17\x10\x0c\x149rrV\x1d\x16\x17\x14\x19X\x1d\x15X\x01\x1aX\x16\x1d\x0c\x0c\x11\n\x0fX\x1c\x1d\x1d\x1c\x16\x11X\x0b\x19\x0fX\x0c\x11XT\n\x1d\x0e\x1d\x0f\x170rrG\x0c\x16\x1d\x1c\r\x0c\x0br\x14\x17\x17\x10\x1b\x0bX\x10\x1f\x11\x10X\x19X\x01\x1aX\x16\x1d\x0c\x0c\x11\n\x0fX\x0b\x19\x0fX\x0b\x11\x10\x0cX\x1d\x0e\x1d\x11\x14\x1d\x1aX\r\x17\x01X\x17<rrV\x16\x17\x10\x0c\x01(X\x16\x11X\x01\x14\x1d\n\r\x08X\x16\x1d\x0c\x0c\x11\n\x0fX\x1d\x1f\x19\x13\x1b\x19\x08X\x10\x0c\x19\x15X\x19X\x0b\x11X\x0b\x11\x10,rr\x11\x01\x19\x112X\x16\x1d\x10+X\x01\x1aXT\x15\r6\x01(\x01(X\x1e\x17X\x16\x1d"X\x1d\x10,XXXXr'
6
- print("".join([chr(ord(_) ^ 120) for _ in Zen[::-1]]))
5
+ Zen = "\x9a¤¢\xa0¢°¼§¢°éâñåâòõÖ°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°\x9a\x9a±äù°õóñâòýõ°ã·äõü½äàõóþÿó°äåÿôþñäã°ñ°ãù°þ÷ùãõô°âñüåôÿÝ\x9a¾÷þùãùýÿâà°õò°äø÷ùý°äù°¼ôâñçâÿöäø÷ùñâäã°ãù°þÿùäñäþõýõüàýù°õøä°öÙ\x9a¾äù°âõôùãþÿóõâ°¼ôþõøõâàýÿó°ÿä°÷þù÷þõüüñøó°ãù°þÿùäñäþõýõüàýù°õøä°öÙ\x9a¾÷þùøãåâ°ÿä°âÿùâõàåã°ãù°÷þùäùñç°ãõýùäõýÿã°¼âõæõçÿØ\x9a¾þÿùäñþùäãñâóÿâà°þñøä°âõääõò°ãù°éüäàýÿâà°÷þùäóÑ\x9a¾øóñÿâààñ°ãåÿùæòÿ½õþÿ°éüþÿ°õøä°¼éüüñõôù½õþÿ°õò°äãåý°õâõøÄ\x9a¾õäñüåóõàã°ÿä°õ÷âå°õøä°äãùãõâ°¼ããõþõå÷ñæ°öÿ°õóþõãõâà°õøä°þÙ\x9a¾ôõäåý°éüäùóùüàèõ°ããõüþÅ\x9a¾ôõóþõüùã°äÿþ°¼þõûÿàã°õò°äãåý°ãâÿââÕ\x9a¾éäùâåà°âõæÿ°ãøàýåùâä°þõäöÿ°éäùüñóùäóñâÀ\x9a¾ãýâÿþ°õøä°õôùââõæÿ°äÿþ°ôüåÿøã°ãõãñó°üñùóõàÃ\x9a¾äþåÿýñâñà°ãù°éäùüùòñôñõÂ\x9a¾ãõþÿ°ôõäñÿüò°âõæÿ°ãþùç°õôÿó°õãâñàÃ\x9a¾ãõùøóâñâõùø°ôõäãõþ°ãäñõò°õâåäóåâäã°äñüÖ\x9a¾ôõäñóùüàýÿóâõæÿ°þñøä°âõääõò°ãù°ôõäñóùäãùøàÿÃ\x9a¾þÿùäåüÿæþÿó°âõæÿ°ôõââõöõâà°ãù°ããõþôâñçâÿöäø÷ùñâäÃ\x9a¾éäùâåóãòÿ°ãàýåâä°éäùâñüÓ\x9a¾éûþåüó°ÿä°âÿùâõàåã°ãù°äþñ÷õüÕ\x9a\x9a¾þÿøäéÀ°þù°éüõâåà°þõääùâç°õ÷ñûóñà°øäñý°ñ°ãù°ãùøÄ\x9a\x9aùéñùÚ°þõøÃ°éò°¼ýåÞéÀéÀ°öÿ°þõʰõøÄ°°°°\x9a"
6
+ print("".join([chr(ord(_) ^ 144) for _ in Zen[::-1]]))
7
7
  for _ in list(globals().keys()):
8
8
  del globals()[_]
9
9
  del _
pypynum/tools.py CHANGED
@@ -160,6 +160,7 @@ def split(iterable: ite, key: arr, retain: bool = False) -> list:
160
160
  if indexes:
161
161
  index = min(indexes)
162
162
  result.append(iterable[pointer:index])
163
+ pointer = index
163
164
  if retain is True:
164
165
  result.append(indexes[index])
165
166
  pointer += len(indexes[index])
@@ -173,7 +174,7 @@ def split(iterable: ite, key: arr, retain: bool = False) -> list:
173
174
  if isinstance(iterable, (list, tuple)):
174
175
  pointer = item + 1
175
176
  if retain is True:
176
- result.append(iterable[item])
177
+ result.append([iterable[item]])
177
178
  result.append(iterable[pointer:])
178
179
  else:
179
180
  raise TypeError("Iterable can only be a list, tuple or str")
@@ -211,6 +212,43 @@ def interpolation(data: arr, length: int) -> list:
211
212
  return result
212
213
 
213
214
 
215
+ def primality(n: int, iter_num: int = 10) -> bool:
216
+ """
217
+ introduction
218
+ ==========
219
+ Using the Miller Rabin method to test the primality of positive integers
220
+
221
+ example
222
+ ==========
223
+ >>> primality(2 ** 4423 - 1)
224
+ True
225
+ >>>
226
+ :param n: integer
227
+ :param iter_num: integer
228
+ :return:
229
+ """
230
+ from random import randint
231
+ if n == 2:
232
+ return True
233
+ elif n & 1 == 0 or n < 2:
234
+ return False
235
+ m, s = n - 1, 0
236
+ while m & 1 == 0:
237
+ m = m >> 1
238
+ s += 1
239
+ for _ in range(iter_num):
240
+ b = pow(randint(2, n - 1), m, n)
241
+ if b == 1 or b == n - 1:
242
+ continue
243
+ for __ in range(s - 1):
244
+ b = b * b % n
245
+ if b == n - 1:
246
+ break
247
+ else:
248
+ return False
249
+ return True
250
+
251
+
214
252
  if __name__ == "__main__":
215
253
  import doctest
216
254