mathai 2.2.6__tar.gz → 2.2.8__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.
- {mathai-2.2.6 → mathai-2.2.8}/PKG-INFO +68 -28
- {mathai-2.2.6 → mathai-2.2.8}/README.md +67 -27
- {mathai-2.2.6 → mathai-2.2.8}/mathai/__init__.py +10 -1
- {mathai-2.2.6 → mathai-2.2.8}/mathai/decision.py +4 -1
- mathai-2.2.8/mathai/formula_compiler.py +437 -0
- {mathai-2.2.6 → mathai-2.2.8}/mathai/formula_data.py +54 -42
- mathai-2.2.8/mathai/pde.py +42 -0
- {mathai-2.2.6 → mathai-2.2.8}/mathai.egg-info/PKG-INFO +68 -28
- {mathai-2.2.6 → mathai-2.2.8}/mathai.egg-info/SOURCES.txt +1 -16
- {mathai-2.2.6 → mathai-2.2.8}/setup.py +4 -6
- mathai-2.2.6/mathai/formula/differentiation.marshal +0 -0
- mathai-2.2.6/mathai/formula/integration.marshal +0 -0
- mathai-2.2.6/mathai/formula/integration_trig.marshal +0 -0
- mathai-2.2.6/mathai/formula/is_integrate_subs.marshal +0 -0
- mathai-2.2.6/mathai/formula/lambda_compress.marshal +0 -0
- mathai-2.2.6/mathai/formula/lambda_expand.marshal +0 -0
- mathai-2.2.6/mathai/formula/lambda_reduce.marshal +0 -0
- mathai-2.2.6/mathai/formula/limit_infinity.marshal +0 -0
- mathai-2.2.6/mathai/formula/matrix_vectorization_calculus.marshal +0 -0
- mathai-2.2.6/mathai/formula/power_rule.marshal +0 -0
- mathai-2.2.6/mathai/formula/quadratic.marshal +0 -0
- mathai-2.2.6/mathai/formula/statistics_1.marshal +0 -0
- mathai-2.2.6/mathai/formula/statistics_2.marshal +0 -0
- mathai-2.2.6/mathai/formula/test.marshal +0 -0
- mathai-2.2.6/mathai/formula/trigonometry_misc.marshal +0 -0
- mathai-2.2.6/mathai/formula_compiler.py +0 -452
- mathai-2.2.6/mathai/pde.py +0 -91
- {mathai-2.2.6 → mathai-2.2.8}/mathai/apart.py +0 -0
- {mathai-2.2.6 → mathai-2.2.8}/mathai/base.py +0 -0
- {mathai-2.2.6 → mathai-2.2.8}/mathai/diff.py +0 -0
- {mathai-2.2.6 → mathai-2.2.8}/mathai/electronic.py +0 -0
- {mathai-2.2.6 → mathai-2.2.8}/mathai/expand.py +0 -0
- {mathai-2.2.6 → mathai-2.2.8}/mathai/factor.py +0 -0
- {mathai-2.2.6 → mathai-2.2.8}/mathai/formula_interpretor.py +0 -0
- {mathai-2.2.6 → mathai-2.2.8}/mathai/fraction.py +0 -0
- {mathai-2.2.6 → mathai-2.2.8}/mathai/graphics.py +0 -0
- {mathai-2.2.6 → mathai-2.2.8}/mathai/integrate.py +0 -0
- {mathai-2.2.6 → mathai-2.2.8}/mathai/inverse.py +0 -0
- {mathai-2.2.6 → mathai-2.2.8}/mathai/lambda_calculus.py +0 -0
- {mathai-2.2.6 → mathai-2.2.8}/mathai/limit.py +0 -0
- {mathai-2.2.6 → mathai-2.2.8}/mathai/linear.py +0 -0
- {mathai-2.2.6 → mathai-2.2.8}/mathai/logic.py +0 -0
- {mathai-2.2.6 → mathai-2.2.8}/mathai/matrix.py +0 -0
- {mathai-2.2.6 → mathai-2.2.8}/mathai/ml.py +0 -0
- {mathai-2.2.6 → mathai-2.2.8}/mathai/mlscalar.py +0 -0
- {mathai-2.2.6 → mathai-2.2.8}/mathai/ode.py +0 -0
- {mathai-2.2.6 → mathai-2.2.8}/mathai/parser.py +0 -0
- {mathai-2.2.6 → mathai-2.2.8}/mathai/printeq.py +0 -0
- {mathai-2.2.6 → mathai-2.2.8}/mathai/qm.py +0 -0
- {mathai-2.2.6 → mathai-2.2.8}/mathai/simplify.py +0 -0
- {mathai-2.2.6 → mathai-2.2.8}/mathai/statistics.py +0 -0
- {mathai-2.2.6 → mathai-2.2.8}/mathai/test.py +0 -0
- {mathai-2.2.6 → mathai-2.2.8}/mathai/tool.py +0 -0
- {mathai-2.2.6 → mathai-2.2.8}/mathai/trig.py +0 -0
- {mathai-2.2.6 → mathai-2.2.8}/mathai/univariate_inequality.py +0 -0
- {mathai-2.2.6 → mathai-2.2.8}/mathai.egg-info/dependency_links.txt +0 -0
- {mathai-2.2.6 → mathai-2.2.8}/mathai.egg-info/requires.txt +0 -0
- {mathai-2.2.6 → mathai-2.2.8}/mathai.egg-info/top_level.txt +0 -0
- {mathai-2.2.6 → mathai-2.2.8}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mathai
|
|
3
|
-
Version: 2.2.
|
|
3
|
+
Version: 2.2.8
|
|
4
4
|
Summary: Mathematics solving Ai tailored to NCERT
|
|
5
5
|
Home-page: https://github.com/infinity390/mathai
|
|
6
6
|
Requires-Python: >=3.7
|
|
@@ -118,19 +118,16 @@ printeq(equation)
|
|
|
118
118
|
#### Example Demonstration 1 (derivation of hydrogen and helium atom's ground state energy in electron volts using the variational principle in quantum physics)
|
|
119
119
|
```python
|
|
120
120
|
from mathai import *
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
print()
|
|
124
|
-
print("ground state energy of helium atom using quantum physics variational principle")
|
|
125
|
-
print(f"{helium_gse()} eV")
|
|
121
|
+
import random
|
|
122
|
+
load_formula_from_file()
|
|
123
|
+
print(hydrogen_gse())
|
|
126
124
|
```
|
|
127
125
|
#### Output
|
|
128
126
|
```
|
|
129
|
-
|
|
130
|
-
|
|
127
|
+
loading formulas from file...
|
|
128
|
+
done
|
|
131
129
|
|
|
132
|
-
|
|
133
|
-
-77.48867420464012 eV
|
|
130
|
+
-13.605693122882869
|
|
134
131
|
```
|
|
135
132
|
|
|
136
133
|
#### Example Demonstration 2 (boolean algebra)
|
|
@@ -320,9 +317,16 @@ training done.
|
|
|
320
317
|
[[0.008834236758389541, 0.9940178289678866], [0.008739967675337235, 0.9941232242029681]]
|
|
321
318
|
```
|
|
322
319
|
|
|
323
|
-
#### Example Demonstration 8 (neural networks)
|
|
320
|
+
#### Example Demonstration 8 (neural networks + mixed)
|
|
324
321
|
```python
|
|
325
|
-
from mathai import
|
|
322
|
+
from mathai import *
|
|
323
|
+
load_formula_from_file()
|
|
324
|
+
god("abs(x)<1")
|
|
325
|
+
god("limit(sin(x)/x,x)")
|
|
326
|
+
god("integrate(sin(cos(x))*sin(x),x)")
|
|
327
|
+
god("integrate(1/(x*(x+2)),x)")
|
|
328
|
+
god("pdif(sin(x)*x,x)")
|
|
329
|
+
god("integrate(sin(x)^4,x)")
|
|
326
330
|
import random
|
|
327
331
|
def binary_random(*shape):
|
|
328
332
|
if len(shape) == 0:
|
|
@@ -330,24 +334,65 @@ def binary_random(*shape):
|
|
|
330
334
|
return [binary_random(*shape[1:]) for _ in range(shape[0])]
|
|
331
335
|
activation_function = parse("sigmoid(Z)")
|
|
332
336
|
detail = []
|
|
333
|
-
detail.append({"dim":[
|
|
334
|
-
detail.append({"dim":[
|
|
335
|
-
detail.append({"dim":[
|
|
337
|
+
detail.append({"dim":[4], "type":"dense", "activation":activation_function})
|
|
338
|
+
detail.append({"dim":[4], "type":"dense", "activation":activation_function})
|
|
339
|
+
detail.append({"dim":[4], "type":"dense", "activation":activation_function})
|
|
336
340
|
nn = NeuralNetwork(detail).model("image")
|
|
337
|
-
train_x = binary_random(
|
|
338
|
-
train_y = binary_random(
|
|
341
|
+
train_x = binary_random(1, 4)
|
|
342
|
+
train_y = binary_random(1, 4)
|
|
339
343
|
nn.train(train_x, train_y, 12, 10000, 1)
|
|
340
344
|
for item in train_x:
|
|
341
345
|
print(nn.predict(item))
|
|
342
346
|
print(train_y.pop(0))
|
|
343
|
-
|
|
344
|
-
print()
|
|
347
|
+
eq = simplify(parse("pdif(u,x)+pdif(u,y)=0"))
|
|
348
|
+
print(solve_pde(eq))
|
|
345
349
|
```
|
|
346
350
|
|
|
347
351
|
#### Output
|
|
348
352
|
|
|
349
353
|
```
|
|
350
|
-
|
|
354
|
+
loading formulas from file...
|
|
355
|
+
done
|
|
356
|
+
|
|
357
|
+
? abs(x)<1
|
|
358
|
+
thinking...
|
|
359
|
+
(-1+abs(x))<0
|
|
360
|
+
(((-1-x)<0)&(x<0))|(((-1+x)<0)&((x=0)|~((x=0)|(x<0))))
|
|
361
|
+
x∈(-1,1)
|
|
362
|
+
=> x∈(-1,1)
|
|
363
|
+
|
|
364
|
+
? limit(sin(x)/x,x)
|
|
365
|
+
thinking...
|
|
366
|
+
=> 1
|
|
367
|
+
|
|
368
|
+
? integrate(sin(cos(x))*sin(x),x)
|
|
369
|
+
thinking...
|
|
370
|
+
integrate((sin(cos(x))*sin(x)),x)
|
|
371
|
+
integrate(((cos((cos(x)-x))/2)+(-cos((cos(x)+x))/2)),x)
|
|
372
|
+
(integrate(cos((cos(x)-x)),x)/2)+(-integrate(cos((cos(x)+x)),x)/2)
|
|
373
|
+
subs(integrate(-sin(y),y),y,cos(x))
|
|
374
|
+
subs(cos(y),y,cos(x))
|
|
375
|
+
=> cos(cos(x))
|
|
376
|
+
|
|
377
|
+
? integrate(1/(x*(x+2)),x)
|
|
378
|
+
thinking...
|
|
379
|
+
integrate((1/((2+x)*x)),x)
|
|
380
|
+
integrate(((-1/(2*x))+(1/(2*(2+x)))),x)
|
|
381
|
+
(log(abs((2+x)))/2)+(-log(abs(x))/2)
|
|
382
|
+
=> (log(abs((2+x)))/2)+(-log(abs(x))/2)
|
|
383
|
+
|
|
384
|
+
? pdif(sin(x)*x,x)
|
|
385
|
+
thinking...
|
|
386
|
+
=> (cos(x)*x)+sin(x)
|
|
387
|
+
|
|
388
|
+
? integrate(sin(x)^4,x)
|
|
389
|
+
thinking...
|
|
390
|
+
integrate((sin(x)^4),x)
|
|
391
|
+
integrate((sin(x)^4),x)
|
|
392
|
+
integrate(((3/8)+(cos((4*x))/8)+(-cos((2*x))/2)),x)
|
|
393
|
+
((3*x)/8)+(-sin((2*x))/4)+(sin((4*x))/32)
|
|
394
|
+
=> ((3*x)/8)+(-sin((2*x))/4)+(sin((4*x))/32)
|
|
395
|
+
|
|
351
396
|
gradients calculated
|
|
352
397
|
calculated the equation of every weight in the network
|
|
353
398
|
epoch 0/10000
|
|
@@ -361,14 +406,9 @@ epoch 7000/10000
|
|
|
361
406
|
epoch 8000/10000
|
|
362
407
|
epoch 9000/10000
|
|
363
408
|
|
|
364
|
-
[0.
|
|
365
|
-
[1, 1]
|
|
366
|
-
|
|
367
|
-
[0.9862372758368634, 0.9960769568908187]
|
|
368
|
-
[1, 1]
|
|
369
|
-
|
|
370
|
-
[0.015725442209655396, 0.9936864875975912]
|
|
371
|
-
[0, 1]
|
|
409
|
+
[0.996605518637114, 0.9963836179387171, 0.9978967024929718, 0.9965181518637254]
|
|
410
|
+
[1, 1, 1, 1]
|
|
411
|
+
(-f((-y+x))+u)=0
|
|
372
412
|
```
|
|
373
413
|
|
|
374
414
|
#### Example Demonstration 9 (automatic testing)
|
|
@@ -103,19 +103,16 @@ printeq(equation)
|
|
|
103
103
|
#### Example Demonstration 1 (derivation of hydrogen and helium atom's ground state energy in electron volts using the variational principle in quantum physics)
|
|
104
104
|
```python
|
|
105
105
|
from mathai import *
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
print()
|
|
109
|
-
print("ground state energy of helium atom using quantum physics variational principle")
|
|
110
|
-
print(f"{helium_gse()} eV")
|
|
106
|
+
import random
|
|
107
|
+
load_formula_from_file()
|
|
108
|
+
print(hydrogen_gse())
|
|
111
109
|
```
|
|
112
110
|
#### Output
|
|
113
111
|
```
|
|
114
|
-
|
|
115
|
-
|
|
112
|
+
loading formulas from file...
|
|
113
|
+
done
|
|
116
114
|
|
|
117
|
-
|
|
118
|
-
-77.48867420464012 eV
|
|
115
|
+
-13.605693122882869
|
|
119
116
|
```
|
|
120
117
|
|
|
121
118
|
#### Example Demonstration 2 (boolean algebra)
|
|
@@ -305,9 +302,16 @@ training done.
|
|
|
305
302
|
[[0.008834236758389541, 0.9940178289678866], [0.008739967675337235, 0.9941232242029681]]
|
|
306
303
|
```
|
|
307
304
|
|
|
308
|
-
#### Example Demonstration 8 (neural networks)
|
|
305
|
+
#### Example Demonstration 8 (neural networks + mixed)
|
|
309
306
|
```python
|
|
310
|
-
from mathai import
|
|
307
|
+
from mathai import *
|
|
308
|
+
load_formula_from_file()
|
|
309
|
+
god("abs(x)<1")
|
|
310
|
+
god("limit(sin(x)/x,x)")
|
|
311
|
+
god("integrate(sin(cos(x))*sin(x),x)")
|
|
312
|
+
god("integrate(1/(x*(x+2)),x)")
|
|
313
|
+
god("pdif(sin(x)*x,x)")
|
|
314
|
+
god("integrate(sin(x)^4,x)")
|
|
311
315
|
import random
|
|
312
316
|
def binary_random(*shape):
|
|
313
317
|
if len(shape) == 0:
|
|
@@ -315,24 +319,65 @@ def binary_random(*shape):
|
|
|
315
319
|
return [binary_random(*shape[1:]) for _ in range(shape[0])]
|
|
316
320
|
activation_function = parse("sigmoid(Z)")
|
|
317
321
|
detail = []
|
|
318
|
-
detail.append({"dim":[
|
|
319
|
-
detail.append({"dim":[
|
|
320
|
-
detail.append({"dim":[
|
|
322
|
+
detail.append({"dim":[4], "type":"dense", "activation":activation_function})
|
|
323
|
+
detail.append({"dim":[4], "type":"dense", "activation":activation_function})
|
|
324
|
+
detail.append({"dim":[4], "type":"dense", "activation":activation_function})
|
|
321
325
|
nn = NeuralNetwork(detail).model("image")
|
|
322
|
-
train_x = binary_random(
|
|
323
|
-
train_y = binary_random(
|
|
326
|
+
train_x = binary_random(1, 4)
|
|
327
|
+
train_y = binary_random(1, 4)
|
|
324
328
|
nn.train(train_x, train_y, 12, 10000, 1)
|
|
325
329
|
for item in train_x:
|
|
326
330
|
print(nn.predict(item))
|
|
327
331
|
print(train_y.pop(0))
|
|
328
|
-
|
|
329
|
-
print()
|
|
332
|
+
eq = simplify(parse("pdif(u,x)+pdif(u,y)=0"))
|
|
333
|
+
print(solve_pde(eq))
|
|
330
334
|
```
|
|
331
335
|
|
|
332
336
|
#### Output
|
|
333
337
|
|
|
334
338
|
```
|
|
335
|
-
|
|
339
|
+
loading formulas from file...
|
|
340
|
+
done
|
|
341
|
+
|
|
342
|
+
? abs(x)<1
|
|
343
|
+
thinking...
|
|
344
|
+
(-1+abs(x))<0
|
|
345
|
+
(((-1-x)<0)&(x<0))|(((-1+x)<0)&((x=0)|~((x=0)|(x<0))))
|
|
346
|
+
x∈(-1,1)
|
|
347
|
+
=> x∈(-1,1)
|
|
348
|
+
|
|
349
|
+
? limit(sin(x)/x,x)
|
|
350
|
+
thinking...
|
|
351
|
+
=> 1
|
|
352
|
+
|
|
353
|
+
? integrate(sin(cos(x))*sin(x),x)
|
|
354
|
+
thinking...
|
|
355
|
+
integrate((sin(cos(x))*sin(x)),x)
|
|
356
|
+
integrate(((cos((cos(x)-x))/2)+(-cos((cos(x)+x))/2)),x)
|
|
357
|
+
(integrate(cos((cos(x)-x)),x)/2)+(-integrate(cos((cos(x)+x)),x)/2)
|
|
358
|
+
subs(integrate(-sin(y),y),y,cos(x))
|
|
359
|
+
subs(cos(y),y,cos(x))
|
|
360
|
+
=> cos(cos(x))
|
|
361
|
+
|
|
362
|
+
? integrate(1/(x*(x+2)),x)
|
|
363
|
+
thinking...
|
|
364
|
+
integrate((1/((2+x)*x)),x)
|
|
365
|
+
integrate(((-1/(2*x))+(1/(2*(2+x)))),x)
|
|
366
|
+
(log(abs((2+x)))/2)+(-log(abs(x))/2)
|
|
367
|
+
=> (log(abs((2+x)))/2)+(-log(abs(x))/2)
|
|
368
|
+
|
|
369
|
+
? pdif(sin(x)*x,x)
|
|
370
|
+
thinking...
|
|
371
|
+
=> (cos(x)*x)+sin(x)
|
|
372
|
+
|
|
373
|
+
? integrate(sin(x)^4,x)
|
|
374
|
+
thinking...
|
|
375
|
+
integrate((sin(x)^4),x)
|
|
376
|
+
integrate((sin(x)^4),x)
|
|
377
|
+
integrate(((3/8)+(cos((4*x))/8)+(-cos((2*x))/2)),x)
|
|
378
|
+
((3*x)/8)+(-sin((2*x))/4)+(sin((4*x))/32)
|
|
379
|
+
=> ((3*x)/8)+(-sin((2*x))/4)+(sin((4*x))/32)
|
|
380
|
+
|
|
336
381
|
gradients calculated
|
|
337
382
|
calculated the equation of every weight in the network
|
|
338
383
|
epoch 0/10000
|
|
@@ -346,14 +391,9 @@ epoch 7000/10000
|
|
|
346
391
|
epoch 8000/10000
|
|
347
392
|
epoch 9000/10000
|
|
348
393
|
|
|
349
|
-
[0.
|
|
350
|
-
[1, 1]
|
|
351
|
-
|
|
352
|
-
[0.9862372758368634, 0.9960769568908187]
|
|
353
|
-
[1, 1]
|
|
354
|
-
|
|
355
|
-
[0.015725442209655396, 0.9936864875975912]
|
|
356
|
-
[0, 1]
|
|
394
|
+
[0.996605518637114, 0.9963836179387171, 0.9978967024929718, 0.9965181518637254]
|
|
395
|
+
[1, 1, 1, 1]
|
|
396
|
+
(-f((-y+x))+u)=0
|
|
357
397
|
```
|
|
358
398
|
|
|
359
399
|
#### Example Demonstration 9 (automatic testing)
|
|
@@ -1,7 +1,16 @@
|
|
|
1
|
+
import os
|
|
2
|
+
def _ensure_formulas_compiled():
|
|
3
|
+
formula_dir = os.path.join(os.path.dirname(__file__), "formula")
|
|
4
|
+
if not os.path.exists(formula_dir) or not any(f.endswith(".marshal") for f in os.listdir(formula_dir)):
|
|
5
|
+
print("[mathai] compiling formulas for first-time use... do not terminate")
|
|
6
|
+
from .formula_data import init_formula
|
|
7
|
+
init_formula("all", True)
|
|
8
|
+
_ensure_formulas_compiled()
|
|
9
|
+
|
|
1
10
|
from .ode import diffsolve as ode_solve
|
|
2
11
|
from .ode import diffsolve_sep as ode_shift_term
|
|
3
12
|
|
|
4
|
-
from .pde import
|
|
13
|
+
from .pde import solve_pde
|
|
5
14
|
|
|
6
15
|
from .qm import hydrogen_gse, helium_gse, power_rule
|
|
7
16
|
|
|
@@ -5,7 +5,7 @@ from .ode import diffsolve as ode_solve
|
|
|
5
5
|
from .parser import parse
|
|
6
6
|
from .simplify import simplify, log0
|
|
7
7
|
from .base import *
|
|
8
|
-
from .diff import diff
|
|
8
|
+
from .diff import diff, diff2
|
|
9
9
|
from .trig import trig0, trig1, zu_simplify
|
|
10
10
|
from .univariate_inequality import simple_wavycurvy, wavycurvy, prepare, absolute, handle_sqrt, eq2range, domain, Range
|
|
11
11
|
from .fraction import fraction
|
|
@@ -295,6 +295,8 @@ def god(string):
|
|
|
295
295
|
eq = None
|
|
296
296
|
eq = parse(string)
|
|
297
297
|
log = [eq]
|
|
298
|
+
if "f_pdif" in str_form(eq):
|
|
299
|
+
eq = diff2(eq)
|
|
298
300
|
if "f_limit" in str_form(eq):
|
|
299
301
|
eq = limit1(limit5(eq))
|
|
300
302
|
elif all(not contain2(eq, "f_"+item) for item in "dif add mul abs pow dif integrate arcsin sin cos log limit eq lt le ge gt".split(" ")) and\
|
|
@@ -319,6 +321,7 @@ def god(string):
|
|
|
319
321
|
print(eq)
|
|
320
322
|
# eq = trig7(eq)
|
|
321
323
|
print(f"=> {eq}")
|
|
324
|
+
print()
|
|
322
325
|
return eq
|
|
323
326
|
elif "f_dif" in str_form(eq) or "f_integrate" in str_form(eq):
|
|
324
327
|
if "f_dif" in str_form(eq) and "f_integrate" not in str_form(eq):
|