math4u 0.2.1__tar.gz → 0.2.3__tar.gz
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.
- math4u-0.2.3/PKG-INFO +373 -0
- math4u-0.2.3/README.md +338 -0
- {math4u-0.2.1 → math4u-0.2.3}/pyproject.toml +18 -2
- math4u-0.2.3/src/math4u/__init__.py +109 -0
- math4u-0.2.3/src/math4u/file_io.py +28 -0
- math4u-0.2.3/src/math4u/gmpy2_tools.py +31 -0
- math4u-0.2.3/src/math4u/pari_tools.py +38 -0
- math4u-0.2.3/src/math4u/plotly_tools.py +31 -0
- math4u-0.2.3/src/math4u/pyvista_tools.py +38 -0
- math4u-0.2.3/src/math4u/sage_tools.py +34 -0
- math4u-0.2.3/src/math4u/seaborn_tools.py +41 -0
- math4u-0.2.1/PKG-INFO +0 -97
- math4u-0.2.1/README.md +0 -68
- math4u-0.2.1/src/math4u/__init__.py +0 -133
- {math4u-0.2.1 → math4u-0.2.3}/LICENSE +0 -0
- {math4u-0.2.1 → math4u-0.2.3}/src/math4u/calculus.py +0 -0
- {math4u-0.2.1 → math4u-0.2.3}/src/math4u/data_structures.py +0 -0
- {math4u-0.2.1 → math4u-0.2.3}/src/math4u/exceptions.py +0 -0
- {math4u-0.2.1 → math4u-0.2.3}/src/math4u/linear_algebra.py +0 -0
- {math4u-0.2.1 → math4u-0.2.3}/src/math4u/numerical.py +0 -0
- {math4u-0.2.1 → math4u-0.2.3}/src/math4u/oop.py +0 -0
- {math4u-0.2.1 → math4u-0.2.3}/src/math4u/recursion.py +0 -0
- {math4u-0.2.1 → math4u-0.2.3}/src/math4u/scipy_tools.py +0 -0
- {math4u-0.2.1 → math4u-0.2.3}/src/math4u/string_processing.py +0 -0
- {math4u-0.2.1 → math4u-0.2.3}/src/math4u/visualization.py +0 -0
math4u-0.2.3/PKG-INFO
ADDED
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: math4u
|
|
3
|
+
Version: 0.2.3
|
|
4
|
+
Summary: Python Package สำหรับการคำนวณและเครื่องมือทางคณิตศาสตร์
|
|
5
|
+
Project-URL: Homepage, https://github.com/username/my_package
|
|
6
|
+
Project-URL: Documentation, https://github.com/username/my_package#readme
|
|
7
|
+
Project-URL: Repository, https://github.com/username/my_package.git
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/username/my_package/issues
|
|
9
|
+
Author-email: Bunyasak Rakjing <boonyasuk1213@gmail.com>
|
|
10
|
+
License: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: calculus,linear-algebra,mathematics,networkx,numpy,plotly,pyvista,scipy,seaborn,sympy
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Requires-Python: >=3.8
|
|
23
|
+
Requires-Dist: gmpy2
|
|
24
|
+
Requires-Dist: matplotlib
|
|
25
|
+
Requires-Dist: networkx
|
|
26
|
+
Requires-Dist: numpy
|
|
27
|
+
Requires-Dist: plotly
|
|
28
|
+
Requires-Dist: pyvista
|
|
29
|
+
Requires-Dist: scipy
|
|
30
|
+
Requires-Dist: seaborn
|
|
31
|
+
Requires-Dist: sympy
|
|
32
|
+
Provides-Extra: pari
|
|
33
|
+
Requires-Dist: cypari2; extra == 'pari'
|
|
34
|
+
Description-Content-Type: text/markdown
|
|
35
|
+
|
|
36
|
+
# math4u
|
|
37
|
+
|
|
38
|
+
Python Package สำหรับการคำนวณ Calculus, Linear Algebra และเครื่องมือทางคณิตศาสตร์
|
|
39
|
+
|
|
40
|
+
## การใช้งาน
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
import math4u
|
|
44
|
+
|
|
45
|
+
# =========================
|
|
46
|
+
# Calculus
|
|
47
|
+
# =========================
|
|
48
|
+
|
|
49
|
+
print(math4u.derivative("x**3 + 2*x"))
|
|
50
|
+
# 3*x**2 + 2
|
|
51
|
+
|
|
52
|
+
print(math4u.second_derivative("x**3 + 2*x"))
|
|
53
|
+
# 6*x
|
|
54
|
+
|
|
55
|
+
print(math4u.integrate("x**2 + 2*x"))
|
|
56
|
+
# x**3/3 + x**2
|
|
57
|
+
|
|
58
|
+
print(math4u.definite_integral("x**2", 0, 2))
|
|
59
|
+
# 8/3
|
|
60
|
+
|
|
61
|
+
print(math4u.limit("sin(x)/x", point=0))
|
|
62
|
+
# 1
|
|
63
|
+
|
|
64
|
+
print(math4u.taylor_series("exp(x)", point=0, order=5))
|
|
65
|
+
# x**4/24 + x**3/6 + x**2/2 + x + 1
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
# =========================
|
|
69
|
+
# Linear Algebra
|
|
70
|
+
# =========================
|
|
71
|
+
|
|
72
|
+
A = [[1, 2], [3, 4]]
|
|
73
|
+
B = [[5, 6], [7, 8]]
|
|
74
|
+
|
|
75
|
+
print(math4u.matrix_add(A, B))
|
|
76
|
+
# Matrix([[6, 8], [10, 12]])
|
|
77
|
+
|
|
78
|
+
print(math4u.matrix_multiply(A, B))
|
|
79
|
+
# Matrix([[19, 22], [43, 50]])
|
|
80
|
+
|
|
81
|
+
print(math4u.determinant(A))
|
|
82
|
+
# -2
|
|
83
|
+
|
|
84
|
+
print(math4u.inverse_matrix(A))
|
|
85
|
+
# Matrix([[-2, 1], [3/2, -1/2]])
|
|
86
|
+
|
|
87
|
+
print(math4u.transpose(A))
|
|
88
|
+
# Matrix([[1, 3], [2, 4]])
|
|
89
|
+
|
|
90
|
+
print(math4u.solve_linear_system(
|
|
91
|
+
[[2, 1], [1, -1]],
|
|
92
|
+
[5, 1]
|
|
93
|
+
))
|
|
94
|
+
# (2, 1)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
# =========================
|
|
98
|
+
# String Processing
|
|
99
|
+
# =========================
|
|
100
|
+
|
|
101
|
+
print(math4u.reverse_string("Hello"))
|
|
102
|
+
# olleH
|
|
103
|
+
|
|
104
|
+
print(math4u.count_words("Hello Python World"))
|
|
105
|
+
# 3
|
|
106
|
+
|
|
107
|
+
print(math4u.count_characters("Hello"))
|
|
108
|
+
# 5
|
|
109
|
+
|
|
110
|
+
print(math4u.to_uppercase("hello"))
|
|
111
|
+
# HELLO
|
|
112
|
+
|
|
113
|
+
print(math4u.to_lowercase("HELLO"))
|
|
114
|
+
# hello
|
|
115
|
+
|
|
116
|
+
print(math4u.remove_spaces("Hello World"))
|
|
117
|
+
# HelloWorld
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
# =========================
|
|
121
|
+
# Data Structures
|
|
122
|
+
# =========================
|
|
123
|
+
|
|
124
|
+
print(math4u.list_operations([10, 20, 30]))
|
|
125
|
+
|
|
126
|
+
print(math4u.tuple_operations((1, 2, 3)))
|
|
127
|
+
|
|
128
|
+
print(math4u.dictionary_keys({
|
|
129
|
+
"a": 1,
|
|
130
|
+
"b": 2
|
|
131
|
+
}))
|
|
132
|
+
|
|
133
|
+
print(math4u.dictionary_values({
|
|
134
|
+
"a": 1,
|
|
135
|
+
"b": 2
|
|
136
|
+
}))
|
|
137
|
+
|
|
138
|
+
print(math4u.set_union({1, 2}, {2, 3}))
|
|
139
|
+
|
|
140
|
+
print(math4u.set_intersection({1, 2}, {2, 3}))
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
# =========================
|
|
144
|
+
# Recursive Functions
|
|
145
|
+
# =========================
|
|
146
|
+
|
|
147
|
+
print(math4u.factorial(5))
|
|
148
|
+
# 120
|
|
149
|
+
|
|
150
|
+
print(math4u.fibonacci(6))
|
|
151
|
+
# 8
|
|
152
|
+
|
|
153
|
+
print(math4u.power_recursive(2, 5))
|
|
154
|
+
# 32
|
|
155
|
+
|
|
156
|
+
print(math4u.sum_recursive([1, 2, 3, 4]))
|
|
157
|
+
# 10
|
|
158
|
+
|
|
159
|
+
print(math4u.gcd_recursive(48, 18))
|
|
160
|
+
# 6
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
# =========================
|
|
164
|
+
# Recursive Function with Memoization
|
|
165
|
+
# =========================
|
|
166
|
+
|
|
167
|
+
print(math4u.fibonacci_memo(10))
|
|
168
|
+
# 55
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
# =========================
|
|
172
|
+
# Object-Oriented Programming
|
|
173
|
+
# =========================
|
|
174
|
+
|
|
175
|
+
calc = math4u.Calculator(10)
|
|
176
|
+
print(calc.add(5))
|
|
177
|
+
# 15
|
|
178
|
+
|
|
179
|
+
scientific = math4u.ScientificCalculator(4)
|
|
180
|
+
print(scientific.square())
|
|
181
|
+
# 16
|
|
182
|
+
|
|
183
|
+
advanced = math4u.AdvancedCalculator(3)
|
|
184
|
+
print(advanced.cube())
|
|
185
|
+
# 27
|
|
186
|
+
|
|
187
|
+
special = math4u.SpecialCalculator(2)
|
|
188
|
+
print(special.fourth_power())
|
|
189
|
+
# 16
|
|
190
|
+
|
|
191
|
+
basic = math4u.BasicCalculator(5)
|
|
192
|
+
print(basic.double())
|
|
193
|
+
# 10
|
|
194
|
+
|
|
195
|
+
hybrid = math4u.HybridCalculator(2)
|
|
196
|
+
print(hybrid.fifth_power())
|
|
197
|
+
# 32
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
# =========================
|
|
201
|
+
# Exception Handling
|
|
202
|
+
# =========================
|
|
203
|
+
|
|
204
|
+
print(math4u.safe_divide(10, 2))
|
|
205
|
+
# 5.0
|
|
206
|
+
|
|
207
|
+
print(math4u.safe_divide(10, 0))
|
|
208
|
+
# None
|
|
209
|
+
|
|
210
|
+
print(math4u.safe_square_root(16))
|
|
211
|
+
# 4.0
|
|
212
|
+
|
|
213
|
+
print(math4u.safe_square_root(-1))
|
|
214
|
+
# None
|
|
215
|
+
|
|
216
|
+
print(math4u.validate_number("25"))
|
|
217
|
+
# 25.0
|
|
218
|
+
|
|
219
|
+
print(math4u.get_list_item([10, 20, 30], 1))
|
|
220
|
+
# 20
|
|
221
|
+
|
|
222
|
+
print(math4u.get_dictionary_value(
|
|
223
|
+
{"name": "Math"},
|
|
224
|
+
"name"
|
|
225
|
+
))
|
|
226
|
+
# Math
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
# =========================
|
|
230
|
+
# NumPy
|
|
231
|
+
# =========================
|
|
232
|
+
|
|
233
|
+
print(math4u.create_array([1, 2, 3]))
|
|
234
|
+
|
|
235
|
+
print(math4u.array_mean([1, 2, 3, 4]))
|
|
236
|
+
# 2.5
|
|
237
|
+
|
|
238
|
+
print(math4u.array_sum([1, 2, 3, 4]))
|
|
239
|
+
# 10
|
|
240
|
+
|
|
241
|
+
print(math4u.matrix_multiply_numpy(
|
|
242
|
+
[[1, 2], [3, 4]],
|
|
243
|
+
[[5, 6], [7, 8]]
|
|
244
|
+
))
|
|
245
|
+
|
|
246
|
+
print(math4u.array_statistics([1, 2, 3, 4, 5]))
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
# =========================
|
|
250
|
+
# SciPy and SymPy
|
|
251
|
+
# =========================
|
|
252
|
+
|
|
253
|
+
import sympy as sp
|
|
254
|
+
|
|
255
|
+
x = sp.Symbol("x")
|
|
256
|
+
|
|
257
|
+
print(math4u.symbolic_simplify(
|
|
258
|
+
(x**2 - 1) / (x - 1)
|
|
259
|
+
))
|
|
260
|
+
# x + 1
|
|
261
|
+
|
|
262
|
+
print(math4u.symbolic_expand(
|
|
263
|
+
(x + 1)**2
|
|
264
|
+
))
|
|
265
|
+
# x**2 + 2*x + 1
|
|
266
|
+
|
|
267
|
+
print(math4u.numerical_integral(
|
|
268
|
+
lambda x: x**2,
|
|
269
|
+
0,
|
|
270
|
+
1
|
|
271
|
+
))
|
|
272
|
+
# 0.333333...
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
# =========================
|
|
276
|
+
# File I/O
|
|
277
|
+
# =========================
|
|
278
|
+
|
|
279
|
+
math4u.write_text(
|
|
280
|
+
"example.txt",
|
|
281
|
+
"Hello math4u"
|
|
282
|
+
)
|
|
283
|
+
|
|
284
|
+
print(math4u.read_text("example.txt"))
|
|
285
|
+
# Hello math4u
|
|
286
|
+
|
|
287
|
+
math4u.append_text(
|
|
288
|
+
"example.txt",
|
|
289
|
+
"\nPython Package"
|
|
290
|
+
)
|
|
291
|
+
|
|
292
|
+
print(math4u.read_lines("example.txt"))
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
# =========================
|
|
296
|
+
# Matplotlib
|
|
297
|
+
# =========================
|
|
298
|
+
|
|
299
|
+
x = [1, 2, 3, 4]
|
|
300
|
+
y = [1, 4, 9, 16]
|
|
301
|
+
|
|
302
|
+
math4u.visualization.plot_function(x, y)
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
# =========================
|
|
306
|
+
# Seaborn
|
|
307
|
+
# =========================
|
|
308
|
+
|
|
309
|
+
math4u.seaborn_tools.plot_line(
|
|
310
|
+
[1, 2, 3, 4],
|
|
311
|
+
[1, 4, 9, 16]
|
|
312
|
+
)
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
# =========================
|
|
316
|
+
# Plotly
|
|
317
|
+
# =========================
|
|
318
|
+
|
|
319
|
+
math4u.plotly_tools.plot_bar(
|
|
320
|
+
["A", "B", "C"],
|
|
321
|
+
[10, 20, 15]
|
|
322
|
+
)
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
# =========================
|
|
326
|
+
# NetworkX
|
|
327
|
+
# =========================
|
|
328
|
+
|
|
329
|
+
edges = [
|
|
330
|
+
("A", "B"),
|
|
331
|
+
("B", "C"),
|
|
332
|
+
("C", "A")
|
|
333
|
+
]
|
|
334
|
+
|
|
335
|
+
graph = math4u.visualization.create_graph(edges)
|
|
336
|
+
|
|
337
|
+
math4u.visualization.draw_graph(edges)
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
# =========================
|
|
341
|
+
# PyVista
|
|
342
|
+
# =========================
|
|
343
|
+
|
|
344
|
+
sphere = math4u.pyvista_tools.create_sphere(
|
|
345
|
+
radius=1
|
|
346
|
+
)
|
|
347
|
+
|
|
348
|
+
# Display the 3D object
|
|
349
|
+
# math4u.pyvista_tools.show_mesh(sphere)
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
# =========================
|
|
353
|
+
# GMPY2
|
|
354
|
+
# =========================
|
|
355
|
+
|
|
356
|
+
print(math4u.gmpy2_tools.big_integer(123456789))
|
|
357
|
+
|
|
358
|
+
print(math4u.gmpy2_tools.gmpy2_gcd(48, 18))
|
|
359
|
+
# 6
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
# =========================
|
|
363
|
+
# SageMath
|
|
364
|
+
# =========================
|
|
365
|
+
|
|
366
|
+
print(math4u.sage_tools.sage_available())
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
# =========================
|
|
370
|
+
# PARI/GP
|
|
371
|
+
# =========================
|
|
372
|
+
|
|
373
|
+
print(math4u.pari_tools.pari_available())
|
math4u-0.2.3/README.md
ADDED
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
# math4u
|
|
2
|
+
|
|
3
|
+
Python Package สำหรับการคำนวณ Calculus, Linear Algebra และเครื่องมือทางคณิตศาสตร์
|
|
4
|
+
|
|
5
|
+
## การใช้งาน
|
|
6
|
+
|
|
7
|
+
```python
|
|
8
|
+
import math4u
|
|
9
|
+
|
|
10
|
+
# =========================
|
|
11
|
+
# Calculus
|
|
12
|
+
# =========================
|
|
13
|
+
|
|
14
|
+
print(math4u.derivative("x**3 + 2*x"))
|
|
15
|
+
# 3*x**2 + 2
|
|
16
|
+
|
|
17
|
+
print(math4u.second_derivative("x**3 + 2*x"))
|
|
18
|
+
# 6*x
|
|
19
|
+
|
|
20
|
+
print(math4u.integrate("x**2 + 2*x"))
|
|
21
|
+
# x**3/3 + x**2
|
|
22
|
+
|
|
23
|
+
print(math4u.definite_integral("x**2", 0, 2))
|
|
24
|
+
# 8/3
|
|
25
|
+
|
|
26
|
+
print(math4u.limit("sin(x)/x", point=0))
|
|
27
|
+
# 1
|
|
28
|
+
|
|
29
|
+
print(math4u.taylor_series("exp(x)", point=0, order=5))
|
|
30
|
+
# x**4/24 + x**3/6 + x**2/2 + x + 1
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
# =========================
|
|
34
|
+
# Linear Algebra
|
|
35
|
+
# =========================
|
|
36
|
+
|
|
37
|
+
A = [[1, 2], [3, 4]]
|
|
38
|
+
B = [[5, 6], [7, 8]]
|
|
39
|
+
|
|
40
|
+
print(math4u.matrix_add(A, B))
|
|
41
|
+
# Matrix([[6, 8], [10, 12]])
|
|
42
|
+
|
|
43
|
+
print(math4u.matrix_multiply(A, B))
|
|
44
|
+
# Matrix([[19, 22], [43, 50]])
|
|
45
|
+
|
|
46
|
+
print(math4u.determinant(A))
|
|
47
|
+
# -2
|
|
48
|
+
|
|
49
|
+
print(math4u.inverse_matrix(A))
|
|
50
|
+
# Matrix([[-2, 1], [3/2, -1/2]])
|
|
51
|
+
|
|
52
|
+
print(math4u.transpose(A))
|
|
53
|
+
# Matrix([[1, 3], [2, 4]])
|
|
54
|
+
|
|
55
|
+
print(math4u.solve_linear_system(
|
|
56
|
+
[[2, 1], [1, -1]],
|
|
57
|
+
[5, 1]
|
|
58
|
+
))
|
|
59
|
+
# (2, 1)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
# =========================
|
|
63
|
+
# String Processing
|
|
64
|
+
# =========================
|
|
65
|
+
|
|
66
|
+
print(math4u.reverse_string("Hello"))
|
|
67
|
+
# olleH
|
|
68
|
+
|
|
69
|
+
print(math4u.count_words("Hello Python World"))
|
|
70
|
+
# 3
|
|
71
|
+
|
|
72
|
+
print(math4u.count_characters("Hello"))
|
|
73
|
+
# 5
|
|
74
|
+
|
|
75
|
+
print(math4u.to_uppercase("hello"))
|
|
76
|
+
# HELLO
|
|
77
|
+
|
|
78
|
+
print(math4u.to_lowercase("HELLO"))
|
|
79
|
+
# hello
|
|
80
|
+
|
|
81
|
+
print(math4u.remove_spaces("Hello World"))
|
|
82
|
+
# HelloWorld
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
# =========================
|
|
86
|
+
# Data Structures
|
|
87
|
+
# =========================
|
|
88
|
+
|
|
89
|
+
print(math4u.list_operations([10, 20, 30]))
|
|
90
|
+
|
|
91
|
+
print(math4u.tuple_operations((1, 2, 3)))
|
|
92
|
+
|
|
93
|
+
print(math4u.dictionary_keys({
|
|
94
|
+
"a": 1,
|
|
95
|
+
"b": 2
|
|
96
|
+
}))
|
|
97
|
+
|
|
98
|
+
print(math4u.dictionary_values({
|
|
99
|
+
"a": 1,
|
|
100
|
+
"b": 2
|
|
101
|
+
}))
|
|
102
|
+
|
|
103
|
+
print(math4u.set_union({1, 2}, {2, 3}))
|
|
104
|
+
|
|
105
|
+
print(math4u.set_intersection({1, 2}, {2, 3}))
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
# =========================
|
|
109
|
+
# Recursive Functions
|
|
110
|
+
# =========================
|
|
111
|
+
|
|
112
|
+
print(math4u.factorial(5))
|
|
113
|
+
# 120
|
|
114
|
+
|
|
115
|
+
print(math4u.fibonacci(6))
|
|
116
|
+
# 8
|
|
117
|
+
|
|
118
|
+
print(math4u.power_recursive(2, 5))
|
|
119
|
+
# 32
|
|
120
|
+
|
|
121
|
+
print(math4u.sum_recursive([1, 2, 3, 4]))
|
|
122
|
+
# 10
|
|
123
|
+
|
|
124
|
+
print(math4u.gcd_recursive(48, 18))
|
|
125
|
+
# 6
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
# =========================
|
|
129
|
+
# Recursive Function with Memoization
|
|
130
|
+
# =========================
|
|
131
|
+
|
|
132
|
+
print(math4u.fibonacci_memo(10))
|
|
133
|
+
# 55
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
# =========================
|
|
137
|
+
# Object-Oriented Programming
|
|
138
|
+
# =========================
|
|
139
|
+
|
|
140
|
+
calc = math4u.Calculator(10)
|
|
141
|
+
print(calc.add(5))
|
|
142
|
+
# 15
|
|
143
|
+
|
|
144
|
+
scientific = math4u.ScientificCalculator(4)
|
|
145
|
+
print(scientific.square())
|
|
146
|
+
# 16
|
|
147
|
+
|
|
148
|
+
advanced = math4u.AdvancedCalculator(3)
|
|
149
|
+
print(advanced.cube())
|
|
150
|
+
# 27
|
|
151
|
+
|
|
152
|
+
special = math4u.SpecialCalculator(2)
|
|
153
|
+
print(special.fourth_power())
|
|
154
|
+
# 16
|
|
155
|
+
|
|
156
|
+
basic = math4u.BasicCalculator(5)
|
|
157
|
+
print(basic.double())
|
|
158
|
+
# 10
|
|
159
|
+
|
|
160
|
+
hybrid = math4u.HybridCalculator(2)
|
|
161
|
+
print(hybrid.fifth_power())
|
|
162
|
+
# 32
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
# =========================
|
|
166
|
+
# Exception Handling
|
|
167
|
+
# =========================
|
|
168
|
+
|
|
169
|
+
print(math4u.safe_divide(10, 2))
|
|
170
|
+
# 5.0
|
|
171
|
+
|
|
172
|
+
print(math4u.safe_divide(10, 0))
|
|
173
|
+
# None
|
|
174
|
+
|
|
175
|
+
print(math4u.safe_square_root(16))
|
|
176
|
+
# 4.0
|
|
177
|
+
|
|
178
|
+
print(math4u.safe_square_root(-1))
|
|
179
|
+
# None
|
|
180
|
+
|
|
181
|
+
print(math4u.validate_number("25"))
|
|
182
|
+
# 25.0
|
|
183
|
+
|
|
184
|
+
print(math4u.get_list_item([10, 20, 30], 1))
|
|
185
|
+
# 20
|
|
186
|
+
|
|
187
|
+
print(math4u.get_dictionary_value(
|
|
188
|
+
{"name": "Math"},
|
|
189
|
+
"name"
|
|
190
|
+
))
|
|
191
|
+
# Math
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
# =========================
|
|
195
|
+
# NumPy
|
|
196
|
+
# =========================
|
|
197
|
+
|
|
198
|
+
print(math4u.create_array([1, 2, 3]))
|
|
199
|
+
|
|
200
|
+
print(math4u.array_mean([1, 2, 3, 4]))
|
|
201
|
+
# 2.5
|
|
202
|
+
|
|
203
|
+
print(math4u.array_sum([1, 2, 3, 4]))
|
|
204
|
+
# 10
|
|
205
|
+
|
|
206
|
+
print(math4u.matrix_multiply_numpy(
|
|
207
|
+
[[1, 2], [3, 4]],
|
|
208
|
+
[[5, 6], [7, 8]]
|
|
209
|
+
))
|
|
210
|
+
|
|
211
|
+
print(math4u.array_statistics([1, 2, 3, 4, 5]))
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
# =========================
|
|
215
|
+
# SciPy and SymPy
|
|
216
|
+
# =========================
|
|
217
|
+
|
|
218
|
+
import sympy as sp
|
|
219
|
+
|
|
220
|
+
x = sp.Symbol("x")
|
|
221
|
+
|
|
222
|
+
print(math4u.symbolic_simplify(
|
|
223
|
+
(x**2 - 1) / (x - 1)
|
|
224
|
+
))
|
|
225
|
+
# x + 1
|
|
226
|
+
|
|
227
|
+
print(math4u.symbolic_expand(
|
|
228
|
+
(x + 1)**2
|
|
229
|
+
))
|
|
230
|
+
# x**2 + 2*x + 1
|
|
231
|
+
|
|
232
|
+
print(math4u.numerical_integral(
|
|
233
|
+
lambda x: x**2,
|
|
234
|
+
0,
|
|
235
|
+
1
|
|
236
|
+
))
|
|
237
|
+
# 0.333333...
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
# =========================
|
|
241
|
+
# File I/O
|
|
242
|
+
# =========================
|
|
243
|
+
|
|
244
|
+
math4u.write_text(
|
|
245
|
+
"example.txt",
|
|
246
|
+
"Hello math4u"
|
|
247
|
+
)
|
|
248
|
+
|
|
249
|
+
print(math4u.read_text("example.txt"))
|
|
250
|
+
# Hello math4u
|
|
251
|
+
|
|
252
|
+
math4u.append_text(
|
|
253
|
+
"example.txt",
|
|
254
|
+
"\nPython Package"
|
|
255
|
+
)
|
|
256
|
+
|
|
257
|
+
print(math4u.read_lines("example.txt"))
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
# =========================
|
|
261
|
+
# Matplotlib
|
|
262
|
+
# =========================
|
|
263
|
+
|
|
264
|
+
x = [1, 2, 3, 4]
|
|
265
|
+
y = [1, 4, 9, 16]
|
|
266
|
+
|
|
267
|
+
math4u.visualization.plot_function(x, y)
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
# =========================
|
|
271
|
+
# Seaborn
|
|
272
|
+
# =========================
|
|
273
|
+
|
|
274
|
+
math4u.seaborn_tools.plot_line(
|
|
275
|
+
[1, 2, 3, 4],
|
|
276
|
+
[1, 4, 9, 16]
|
|
277
|
+
)
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
# =========================
|
|
281
|
+
# Plotly
|
|
282
|
+
# =========================
|
|
283
|
+
|
|
284
|
+
math4u.plotly_tools.plot_bar(
|
|
285
|
+
["A", "B", "C"],
|
|
286
|
+
[10, 20, 15]
|
|
287
|
+
)
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
# =========================
|
|
291
|
+
# NetworkX
|
|
292
|
+
# =========================
|
|
293
|
+
|
|
294
|
+
edges = [
|
|
295
|
+
("A", "B"),
|
|
296
|
+
("B", "C"),
|
|
297
|
+
("C", "A")
|
|
298
|
+
]
|
|
299
|
+
|
|
300
|
+
graph = math4u.visualization.create_graph(edges)
|
|
301
|
+
|
|
302
|
+
math4u.visualization.draw_graph(edges)
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
# =========================
|
|
306
|
+
# PyVista
|
|
307
|
+
# =========================
|
|
308
|
+
|
|
309
|
+
sphere = math4u.pyvista_tools.create_sphere(
|
|
310
|
+
radius=1
|
|
311
|
+
)
|
|
312
|
+
|
|
313
|
+
# Display the 3D object
|
|
314
|
+
# math4u.pyvista_tools.show_mesh(sphere)
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
# =========================
|
|
318
|
+
# GMPY2
|
|
319
|
+
# =========================
|
|
320
|
+
|
|
321
|
+
print(math4u.gmpy2_tools.big_integer(123456789))
|
|
322
|
+
|
|
323
|
+
print(math4u.gmpy2_tools.gmpy2_gcd(48, 18))
|
|
324
|
+
# 6
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
# =========================
|
|
328
|
+
# SageMath
|
|
329
|
+
# =========================
|
|
330
|
+
|
|
331
|
+
print(math4u.sage_tools.sage_available())
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
# =========================
|
|
335
|
+
# PARI/GP
|
|
336
|
+
# =========================
|
|
337
|
+
|
|
338
|
+
print(math4u.pari_tools.pari_available())
|