mathai 0.4.8__py3-none-any.whl → 0.7.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.
- mathai/__init__.py +9 -8
- mathai/base.py +132 -34
- mathai/bivariate_inequality.py +317 -0
- mathai/diff.py +3 -3
- mathai/expand.py +159 -80
- mathai/factor.py +45 -21
- mathai/fraction.py +2 -2
- mathai/integrate.py +38 -19
- mathai/inverse.py +4 -4
- mathai/limit.py +94 -70
- mathai/linear.py +90 -81
- mathai/logic.py +7 -1
- mathai/matrix.py +228 -0
- mathai/parser.py +13 -7
- mathai/parsetab.py +61 -0
- mathai/printeq.py +12 -9
- mathai/simplify.py +511 -369
- mathai/structure.py +2 -2
- mathai/tool.py +2 -2
- mathai/trig.py +42 -25
- mathai/univariate_inequality.py +78 -30
- mathai-0.7.2.dist-info/METADATA +293 -0
- mathai-0.7.2.dist-info/RECORD +28 -0
- {mathai-0.4.8.dist-info → mathai-0.7.2.dist-info}/WHEEL +1 -1
- mathai-0.4.8.dist-info/METADATA +0 -234
- mathai-0.4.8.dist-info/RECORD +0 -25
- {mathai-0.4.8.dist-info → mathai-0.7.2.dist-info}/top_level.txt +0 -0
mathai/structure.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import itertools
|
|
2
|
-
from .simplify import
|
|
2
|
+
from .simplify import simplify
|
|
3
3
|
from .base import *
|
|
4
4
|
|
|
5
5
|
def structure(equation, formula, formula_out=None, only_const=False):
|
|
@@ -84,7 +84,7 @@ def transform_formula(equation, wrt, formula_list, var, expr):
|
|
|
84
84
|
for j in range(len(expr)):
|
|
85
85
|
item[i] = replace(item[i], expr[j][0], item2[j])
|
|
86
86
|
for i in range(2):
|
|
87
|
-
item[i] =
|
|
87
|
+
item[i] = simplify(item[i])
|
|
88
88
|
out = None
|
|
89
89
|
p = False
|
|
90
90
|
if var != "":
|
mathai/tool.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from .diff import diff
|
|
2
2
|
from .expand import expand
|
|
3
|
-
from .simplify import simplify
|
|
3
|
+
from .simplify import simplify
|
|
4
4
|
from .base import *
|
|
5
5
|
import math
|
|
6
6
|
|
|
@@ -159,5 +159,5 @@ def poly(eq, to_compute, m=10):
|
|
|
159
159
|
final = []
|
|
160
160
|
for index, item in enumerate(out):
|
|
161
161
|
final.append(substitute_val(item, 0, to_compute)/tree_form("d_"+str(math.factorial(index))))
|
|
162
|
-
|
|
162
|
+
|
|
163
163
|
return [expand(simplify(item)) for item in final][::-1]
|
mathai/trig.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import itertools
|
|
2
|
-
from .simplify import
|
|
2
|
+
from .simplify import simplify
|
|
3
3
|
from .base import *
|
|
4
4
|
from .expand import expand
|
|
5
5
|
from .structure import transform_formula
|
|
@@ -49,7 +49,7 @@ def trig0(eq):
|
|
|
49
49
|
count += 1
|
|
50
50
|
if count != 1:
|
|
51
51
|
return None
|
|
52
|
-
eq =
|
|
52
|
+
eq = simplify(product(lst)/tree_form("s_pi"))
|
|
53
53
|
out = frac(eq)
|
|
54
54
|
if out is None or out < 0:
|
|
55
55
|
return None
|
|
@@ -99,31 +99,48 @@ def trig0(eq):
|
|
|
99
99
|
if tuple(out) in trig_cos_table.keys():
|
|
100
100
|
return trig_cos_table[tuple(out)]
|
|
101
101
|
return TreeNode(eq.name, [trig0(child) for child in eq.children])
|
|
102
|
+
def cog(expr):
|
|
103
|
+
expr = TreeNode(expr.name, [product_to_sum(child) for child in expr.children])
|
|
104
|
+
expr = trig0(simplify(expr))
|
|
105
|
+
expr = expand(simplify(expr))
|
|
106
|
+
return expr
|
|
107
|
+
def product_to_sum(expr):
|
|
108
|
+
factors = factor_generation(expr)
|
|
109
|
+
other = []
|
|
110
|
+
lst = []
|
|
111
|
+
for item in factors:
|
|
112
|
+
if item.name in ["f_cos", "f_sin"]:
|
|
113
|
+
lst.append(item)
|
|
114
|
+
else:
|
|
115
|
+
other.append(item)
|
|
116
|
+
if len(lst) <= 1:
|
|
102
117
|
|
|
103
|
-
|
|
104
|
-
lst = factor_generation(eq)
|
|
105
|
-
if len(lst) == 1:
|
|
106
|
-
return lst[0]
|
|
118
|
+
return dowhile(expr, cog)
|
|
107
119
|
if len(lst) == 2:
|
|
108
120
|
a, b = lst
|
|
121
|
+
out = None
|
|
122
|
+
if a.name < b.name:
|
|
123
|
+
a, b = b, a
|
|
124
|
+
A, B = a.children[0], b.children[0]
|
|
109
125
|
if a.name == "f_sin" and b.name == "f_sin":
|
|
110
|
-
|
|
126
|
+
out =((A - B).fx("cos") - (A + B).fx("cos")) / tree_form("d_2")
|
|
111
127
|
elif a.name == "f_cos" and b.name == "f_cos":
|
|
112
|
-
|
|
128
|
+
out =((A - B).fx("cos") + (A + B).fx("cos")) / tree_form("d_2")
|
|
113
129
|
elif a.name == "f_sin" and b.name == "f_cos":
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
return
|
|
130
|
+
out =((A + B).fx("sin") + (A - B).fx("sin")) / tree_form("d_2")
|
|
131
|
+
|
|
132
|
+
return out * product(other)
|
|
133
|
+
|
|
134
|
+
rest = tree_form("d_1")
|
|
135
|
+
if len(lst) % 2 == 1:
|
|
136
|
+
rest = lst.pop(0)
|
|
137
|
+
out = []
|
|
138
|
+
for i in range(0, len(lst), 2):
|
|
139
|
+
out.append(product_to_sum(product(lst[i:i+2])))
|
|
140
|
+
expr = product(out)*rest*product(other)
|
|
141
|
+
|
|
142
|
+
return dowhile(expr, cog)
|
|
143
|
+
|
|
127
144
|
def trig_formula_init():
|
|
128
145
|
var = ""
|
|
129
146
|
formula_list = [(f"A*sin(B)+C*sin(B)", f"(A^2+C^2)^(1/2)*sin(B+arctan(C/A))"),\
|
|
@@ -162,11 +179,11 @@ def noneg_pow(eq):
|
|
|
162
179
|
if eq.name == "f_pow" and frac(eq.children[1]) is not None and frac(eq.children[1])<0:
|
|
163
180
|
return (eq.children[0]**(simplify(-eq.children[1])))**-1
|
|
164
181
|
return TreeNode(eq.name, [noneg_pow(child) for child in eq.children])
|
|
165
|
-
|
|
166
|
-
equation = product_to_sum(equation)
|
|
167
|
-
return TreeNode(equation.name, [_trig1(child) for child in equation.children])
|
|
182
|
+
|
|
168
183
|
def trig1(eq):
|
|
169
|
-
|
|
184
|
+
eq = noneg_pow(eq)
|
|
185
|
+
return product_to_sum(eq)
|
|
186
|
+
|
|
170
187
|
def trig4(eq):
|
|
171
188
|
done = False
|
|
172
189
|
def _trig4(eq, numer=True, chance="sin"):
|
mathai/univariate_inequality.py
CHANGED
|
@@ -3,13 +3,14 @@ import itertools
|
|
|
3
3
|
from .base import *
|
|
4
4
|
from .inverse import inverse
|
|
5
5
|
from collections import Counter
|
|
6
|
-
from .factor import factor2
|
|
7
|
-
from .simplify import simplify
|
|
6
|
+
#from .factor import factor2
|
|
7
|
+
from .simplify import simplify
|
|
8
8
|
from .expand import expand
|
|
9
9
|
from .fraction import fraction
|
|
10
10
|
import copy
|
|
11
11
|
from .diff import diff
|
|
12
12
|
from .logic import logic0
|
|
13
|
+
from .tool import poly, poly_simplify
|
|
13
14
|
def intersection2(domain, lst):
|
|
14
15
|
domain = copy.deepcopy(domain)
|
|
15
16
|
if domain == [True]:
|
|
@@ -18,6 +19,7 @@ def intersection2(domain, lst):
|
|
|
18
19
|
return []
|
|
19
20
|
lst = [item for item in lst if item not in domain]
|
|
20
21
|
out = []
|
|
22
|
+
|
|
21
23
|
for item2 in lst:
|
|
22
24
|
for index in range(len(domain)):
|
|
23
25
|
|
|
@@ -167,7 +169,54 @@ class Range:
|
|
|
167
169
|
return "U".join(out)
|
|
168
170
|
else:
|
|
169
171
|
return "U".join(out)+"-"+out2
|
|
170
|
-
|
|
172
|
+
def prepare(eq):
|
|
173
|
+
if eq.name[2:] in "and not or".split(" "):
|
|
174
|
+
output = TreeNode(eq.name, [])
|
|
175
|
+
for child in eq.children:
|
|
176
|
+
out = prepare(child)
|
|
177
|
+
if out is None:
|
|
178
|
+
return None
|
|
179
|
+
output.children.append(out)
|
|
180
|
+
output = TreeNode(output.name, output.children)
|
|
181
|
+
return output
|
|
182
|
+
elif eq.name[2:] in "gt lt eq ge le".split(" "):
|
|
183
|
+
eq = simplify(eq)
|
|
184
|
+
out = prepare(eq.children[0])
|
|
185
|
+
if out is None:
|
|
186
|
+
return None
|
|
187
|
+
output = TreeNode(eq.name, [out, tree_form("d_0")])
|
|
188
|
+
|
|
189
|
+
output = logic0(output)
|
|
190
|
+
return output
|
|
191
|
+
else:
|
|
192
|
+
eq = logic0(eq)
|
|
193
|
+
if eq.name in ["s_true", "s_false"]:
|
|
194
|
+
return eq
|
|
195
|
+
if len(vlist(eq)) != 1:
|
|
196
|
+
if "v_" not in str_form(eq):
|
|
197
|
+
return eq
|
|
198
|
+
return None
|
|
199
|
+
out = poly(eq, vlist(eq)[0])
|
|
200
|
+
if out is None or len(out) > 3:
|
|
201
|
+
|
|
202
|
+
output = []
|
|
203
|
+
for item in factor_generation(eq):
|
|
204
|
+
if item.name == "f_pow" and item.children[1].name == "d_-1":
|
|
205
|
+
out2 = poly(item.children[0], vlist(eq)[0])
|
|
206
|
+
if out2 is not None and len(out2) <= 3:
|
|
207
|
+
output.append(poly_simplify(item.children[0])**-1)
|
|
208
|
+
else:
|
|
209
|
+
return None
|
|
210
|
+
else:
|
|
211
|
+
out2 = poly(item, vlist(eq)[0])
|
|
212
|
+
if out2 is not None and len(out2) <= 3:
|
|
213
|
+
output.append(poly_simplify(item))
|
|
214
|
+
else:
|
|
215
|
+
return None
|
|
216
|
+
return simplify(product(output))
|
|
217
|
+
else:
|
|
218
|
+
return poly_simplify(eq)
|
|
219
|
+
|
|
171
220
|
dic_table = {}
|
|
172
221
|
def helper(eq, var="v_0"):
|
|
173
222
|
global dic_table
|
|
@@ -180,7 +229,7 @@ def helper(eq, var="v_0"):
|
|
|
180
229
|
if eq.children[0].name == "f_add":
|
|
181
230
|
|
|
182
231
|
eq.children[0] = simplify(expand(eq.children[0]))
|
|
183
|
-
eq = simplify(factor2(eq))
|
|
232
|
+
#eq = simplify(factor2(eq))
|
|
184
233
|
|
|
185
234
|
|
|
186
235
|
equ = False
|
|
@@ -198,10 +247,12 @@ def helper(eq, var="v_0"):
|
|
|
198
247
|
more = []
|
|
199
248
|
|
|
200
249
|
_, d = num_dem(eq.children[0])
|
|
201
|
-
d =
|
|
250
|
+
d = simplify(d)
|
|
251
|
+
|
|
252
|
+
#d = factor2(d)
|
|
202
253
|
|
|
203
254
|
for item in factor_generation(d):
|
|
204
|
-
|
|
255
|
+
|
|
205
256
|
item = simplify(expand(item))
|
|
206
257
|
if len(vlist(item)) != 0:
|
|
207
258
|
v = vlist(item)[0]
|
|
@@ -210,7 +261,7 @@ def helper(eq, var="v_0"):
|
|
|
210
261
|
out = inverse(item, vlist(item)[0])
|
|
211
262
|
more.append(simplify(out))
|
|
212
263
|
|
|
213
|
-
eq.children[0] = factor2(eq.children[0])
|
|
264
|
+
#eq.children[0] = factor2(eq.children[0])
|
|
214
265
|
|
|
215
266
|
for item in factor_generation(eq.children[0]):
|
|
216
267
|
item = simplify(expand(item))
|
|
@@ -262,6 +313,7 @@ def helper(eq, var="v_0"):
|
|
|
262
313
|
equal = list(set([simplify(item) for item in equal]))
|
|
263
314
|
more = list(set([simplify(item) for item in more]))
|
|
264
315
|
critical = [simplify(item) for item in critical]
|
|
316
|
+
|
|
265
317
|
critical = Counter(critical)
|
|
266
318
|
|
|
267
319
|
critical = sorted(critical.items(), key=lambda x: compute(x[0]))
|
|
@@ -277,7 +329,6 @@ def helper(eq, var="v_0"):
|
|
|
277
329
|
critical[i] = critical[i][0]
|
|
278
330
|
|
|
279
331
|
|
|
280
|
-
|
|
281
332
|
if eq.name == "f_eq":
|
|
282
333
|
final = Range([False], equal, more)
|
|
283
334
|
dic_table[eq2] = final
|
|
@@ -312,11 +363,6 @@ def wavycurvy(eq):
|
|
|
312
363
|
return ra
|
|
313
364
|
|
|
314
365
|
def absolute(equation):
|
|
315
|
-
if equation.name in ["f_and", "f_or", "f_not"]:
|
|
316
|
-
tmp = TreeNode(equation.name, [absolute(child) for child in equation.children])
|
|
317
|
-
if len(tmp.children)==1:
|
|
318
|
-
tmp =tmp.children[0]
|
|
319
|
-
return tmp
|
|
320
366
|
def mul_abs(eq):
|
|
321
367
|
if eq.name == "f_abs" and eq.children[0].name == "f_mul":
|
|
322
368
|
return simplify(product([item.fx("abs") for item in factor_generation(eq.children[0])]))
|
|
@@ -326,10 +372,13 @@ def absolute(equation):
|
|
|
326
372
|
def collectabs(eq):
|
|
327
373
|
out = []
|
|
328
374
|
if eq.name == "f_abs":
|
|
329
|
-
|
|
375
|
+
|
|
376
|
+
out.append(eq)
|
|
330
377
|
return out
|
|
331
378
|
for child in eq.children:
|
|
332
379
|
out += collectabs(child)
|
|
380
|
+
if out != []:
|
|
381
|
+
return out
|
|
333
382
|
return out
|
|
334
383
|
def abc(eq, arr):
|
|
335
384
|
def trans(eq):
|
|
@@ -345,23 +394,16 @@ def absolute(equation):
|
|
|
345
394
|
return TreeNode(eq.name, [trans(child) for child in eq.children])
|
|
346
395
|
return trans(eq)
|
|
347
396
|
out = list(set(collectabs(equation)))
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
for item in itertools.product([0,1,2], repeat=len(out)):
|
|
351
|
-
out3 = []
|
|
352
|
-
for i in range(len(item)):
|
|
353
|
-
out3.append(copy.deepcopy(TreeNode({0:"f_gt", 1:"f_lt", 2:"f_eq"}[item[i]], [out[i], tree_form("d_0")])))
|
|
354
|
-
out3 = TreeNode("f_and", out3+[abc(copy.deepcopy(equation), list(item))])
|
|
355
|
-
if len(out3.children) == 1:
|
|
356
|
-
out3 = out3.children[0]
|
|
357
|
-
out2.append(out3)
|
|
358
|
-
if len(out2) == 1:
|
|
359
|
-
return out2[0]
|
|
397
|
+
if out == []:
|
|
398
|
+
return logic0(equation)
|
|
360
399
|
else:
|
|
361
|
-
|
|
362
|
-
|
|
400
|
+
a = TreeNode("f_ge", [out[0].children[0], tree_form("d_0")]) & replace(equation, out[0], out[0].children[0])
|
|
401
|
+
b = TreeNode("f_lt", [out[0].children[0], tree_form("d_0")]) & replace(equation, out[0], -out[0].children[0])
|
|
402
|
+
return a | b
|
|
363
403
|
def handle_sqrt(eq):
|
|
404
|
+
d= []
|
|
364
405
|
def helper2(eq):
|
|
406
|
+
nonlocal d
|
|
365
407
|
if eq.name in ["f_lt", "f_gt", "f_le", "f_ge","f_eq"]:
|
|
366
408
|
out = []
|
|
367
409
|
def helper(eq):
|
|
@@ -378,13 +420,19 @@ def handle_sqrt(eq):
|
|
|
378
420
|
eq2, sgn = inverse(simplify(eq.children[0]), str_form(item), True)
|
|
379
421
|
if sgn == False:
|
|
380
422
|
n = tree_form("d_-1")
|
|
423
|
+
d.append(TreeNode("f_ge", [eq2,tree_form("d_0")]))
|
|
424
|
+
#d.append(TreeNode("f_ge", [item.children[0],tree_form("d_0")]))
|
|
381
425
|
eq3 = simplify(expand(simplify(eq2**2)))
|
|
382
426
|
|
|
383
427
|
return simplify(TreeNode(eq.name, [simplify(n*item.children[0]-eq3*n), tree_form("d_0")]))
|
|
428
|
+
|
|
384
429
|
return TreeNode(eq.name, [helper2(child) for child in eq.children])
|
|
385
|
-
|
|
430
|
+
out = helper2(eq)
|
|
431
|
+
if len(d) == 0:
|
|
432
|
+
return out
|
|
433
|
+
return TreeNode("f_and", [helper2(eq)]+d)
|
|
386
434
|
def domain(eq):
|
|
387
|
-
eq =
|
|
435
|
+
eq = simplify(eq)
|
|
388
436
|
out = []
|
|
389
437
|
def helper2(eq):
|
|
390
438
|
nonlocal out
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mathai
|
|
3
|
+
Version: 0.7.2
|
|
4
|
+
Summary: Mathematics solving Ai tailored to NCERT
|
|
5
|
+
Home-page: https://github.com/infinity390/mathai4
|
|
6
|
+
Requires-Python: >=3.7
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: lark-parser
|
|
9
|
+
Dynamic: description
|
|
10
|
+
Dynamic: description-content-type
|
|
11
|
+
Dynamic: home-page
|
|
12
|
+
Dynamic: requires-dist
|
|
13
|
+
Dynamic: requires-python
|
|
14
|
+
Dynamic: summary
|
|
15
|
+
|
|
16
|
+
# Math AI Documentation
|
|
17
|
+
## Source
|
|
18
|
+
Github repository of the code
|
|
19
|
+
https://github.com/infinity390/mathai4
|
|
20
|
+
|
|
21
|
+
## Philosophy
|
|
22
|
+
I think it is a big realization in computer science and programming to realize that computers can solve mathematics.
|
|
23
|
+
This understanding should be made mainstream. It can help transform education, mathematical research, and computation of mathematical equations for work.
|
|
24
|
+
|
|
25
|
+
## Societal Implications Of Such A Computer Program And The Author's Comment On Universities Of India
|
|
26
|
+
I think mathematics is valued by society because of education. Schools and universities teach them.
|
|
27
|
+
So this kind of software, if made mainstream, could bring real change.
|
|
28
|
+
|
|
29
|
+
## The Summary Of How Computer "Solves" Math
|
|
30
|
+
Math equations are a tree data structure (`TreeNode` class).
|
|
31
|
+
We can manipulate the math equations using various algorithms (functions provided by the `mathai` library).
|
|
32
|
+
We first parse the math equation strings to get the tree data structure (`parse` function in `mathai`).
|
|
33
|
+
|
|
34
|
+
## The Library
|
|
35
|
+
Import the library by doing:
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from mathai import *
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### str_form
|
|
42
|
+
It is the string representation of a `TreeNode` math equation.
|
|
43
|
+
|
|
44
|
+
#### Example
|
|
45
|
+
```text
|
|
46
|
+
(cos(x)^2)+(sin(x)^2)
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Is represented internally as:
|
|
50
|
+
|
|
51
|
+
```text
|
|
52
|
+
f_add
|
|
53
|
+
f_pow
|
|
54
|
+
f_cos
|
|
55
|
+
v_0
|
|
56
|
+
d_2
|
|
57
|
+
f_pow
|
|
58
|
+
f_sin
|
|
59
|
+
v_0
|
|
60
|
+
d_2
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
#### Leaf Nodes
|
|
64
|
+
|
|
65
|
+
**Variables** (start with a `v_` prefix):
|
|
66
|
+
|
|
67
|
+
- `v_0` -> x
|
|
68
|
+
- `v_1` -> y
|
|
69
|
+
- `v_2` -> z
|
|
70
|
+
- `v_3` -> a
|
|
71
|
+
|
|
72
|
+
**Numbers** (start with `d_` prefix; only integers):
|
|
73
|
+
|
|
74
|
+
- `d_-1` -> -1
|
|
75
|
+
- `d_0` -> 0
|
|
76
|
+
- `d_1` -> 1
|
|
77
|
+
- `d_2` -> 2
|
|
78
|
+
|
|
79
|
+
#### Branch Nodes
|
|
80
|
+
- `f_add` -> addition
|
|
81
|
+
- `f_mul` -> multiplication
|
|
82
|
+
- `f_pow` -> power
|
|
83
|
+
|
|
84
|
+
### parse
|
|
85
|
+
Takes a math equation string and outputs a `TreeNode` object.
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
from mathai import *
|
|
89
|
+
|
|
90
|
+
equation = parse("sin(x)^2+cos(x)^2")
|
|
91
|
+
print(equation)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
#### Output
|
|
95
|
+
```text
|
|
96
|
+
(cos(x)^2)+(sin(x)^2)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### solve, simplify
|
|
100
|
+
It simplifies and cleans up a given math equation.
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
from mathai import *
|
|
104
|
+
|
|
105
|
+
equation = simplify(parse("(x+x+x+x-1-1-1-1)*(4*x-4)*sin(sin(x+x+x)*sin(3*x))"))
|
|
106
|
+
printeq(equation)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
#### Output
|
|
110
|
+
```text
|
|
111
|
+
((-4+(4*x))^2)*sin((sin((3*x))^2))
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Incomplete Documentation, Will be updated and completed later on
|
|
115
|
+
|
|
116
|
+
### Demonstrations
|
|
117
|
+
|
|
118
|
+
#### Example Demonstration 1 (absolute value inequalities)
|
|
119
|
+
```python
|
|
120
|
+
from mathai import *
|
|
121
|
+
question_list_from_lecture = [
|
|
122
|
+
"2*x/(2*x^2 + 5*x + 2) > 1/(x + 1)",
|
|
123
|
+
"(x + 2)*(x + 3)/((x - 2)*(x - 3)) <= 1",
|
|
124
|
+
"(5*x - 1) < (x + 1)^2 & (x + 1)^2 < 7*x - 3",
|
|
125
|
+
"(2*x - 1)/(2*x^3 + 3*x^2 + x) > 0",
|
|
126
|
+
"abs(x + 5)*x + 2*abs(x + 7) - 2 = 0",
|
|
127
|
+
"x*abs(x) - 5*abs(x + 2) + 6 = 0",
|
|
128
|
+
"x^2 - abs(x + 2) + x > 0",
|
|
129
|
+
"abs(abs(x - 2) - 3) <= 2",
|
|
130
|
+
"abs(3*x - 5) + abs(8 - x) = abs(3 + 2*x)",
|
|
131
|
+
"abs(x^2 + 5*x + 9) < abs(x^2 + 2*x + 2) + abs(3*x + 7)"
|
|
132
|
+
]
|
|
133
|
+
|
|
134
|
+
for item in question_list_from_lecture:
|
|
135
|
+
eq = simplify(parse(item))
|
|
136
|
+
eq = dowhile(eq, absolute)
|
|
137
|
+
eq = simplify(factor1(fraction(eq)))
|
|
138
|
+
eq = prepare(eq)
|
|
139
|
+
eq = factor2(eq)
|
|
140
|
+
c = wavycurvy(eq & domain(eq)).fix()
|
|
141
|
+
print(c)
|
|
142
|
+
```
|
|
143
|
+
#### Output
|
|
144
|
+
|
|
145
|
+
```
|
|
146
|
+
(-2,-1)U(-(2/3),-(1/2))
|
|
147
|
+
(-inf,0)U(2,3)U{0}
|
|
148
|
+
(2,4)
|
|
149
|
+
(-inf,-1)U(-(1/2),0)U(1/2,+inf)
|
|
150
|
+
{-4,-3,-(3/2)-(sqrt(57)/2)}
|
|
151
|
+
{-1,(5/2)-(sqrt(89)/2),(5/2)+(sqrt(41)/2)}
|
|
152
|
+
(-inf,-sqrt(2))U((2*sqrt(2))/2,+inf)
|
|
153
|
+
(-3,1)U(3,7)U{1,-3,7,3}
|
|
154
|
+
(5/3,8)U{5/3,8}
|
|
155
|
+
(-inf,-(7/3))
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
#### Example Demonstration 2 (trigonometry)
|
|
159
|
+
```python
|
|
160
|
+
from mathai import *
|
|
161
|
+
def nested_func(eq_node):
|
|
162
|
+
eq_node = fraction(eq_node)
|
|
163
|
+
eq_node = simplify(eq_node)
|
|
164
|
+
eq_node = trig1(eq_node)
|
|
165
|
+
eq_node = trig0(eq_node)
|
|
166
|
+
return eq_node
|
|
167
|
+
for item in ["(cosec(x)-cot(x))^2=(1-cos(x))/(1+cos(x))", "cos(x)/(1+sin(x)) + (1+sin(x))/cos(x) = 2*sec(x)",\
|
|
168
|
+
"tan(x)/(1-cot(x)) + cot(x)/(1-tan(x)) = 1 + sec(x)*cosec(x)", "(1+sec(x))/sec(x) = sin(x)^2/(1-cos(x))",\
|
|
169
|
+
"(cos(x)-sin(x)+1)/(cos(x)+sin(x)-1) = cosec(x)+cot(x)"]:
|
|
170
|
+
eq = logic0(dowhile(parse(item), nested_func))
|
|
171
|
+
print(eq)
|
|
172
|
+
```
|
|
173
|
+
#### Output
|
|
174
|
+
|
|
175
|
+
```
|
|
176
|
+
true
|
|
177
|
+
true
|
|
178
|
+
true
|
|
179
|
+
true
|
|
180
|
+
true
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
#### Example Demonstration 3 (integration)
|
|
184
|
+
```python
|
|
185
|
+
from mathai import *
|
|
186
|
+
|
|
187
|
+
eq = simplify(parse("integrate(2*x/(x^2+1),x)"))
|
|
188
|
+
eq = integrate_const(eq)
|
|
189
|
+
eq = integrate_fraction(eq)
|
|
190
|
+
print(simplify(fraction(simplify(eq))))
|
|
191
|
+
|
|
192
|
+
eq = simplify(parse("integrate(sin(cos(x))*sin(x),x)"))
|
|
193
|
+
eq = integrate_subs(eq)
|
|
194
|
+
eq = integrate_const(eq)
|
|
195
|
+
eq = integrate_formula(eq)
|
|
196
|
+
eq = integrate_clean(eq)
|
|
197
|
+
print(simplify(eq))
|
|
198
|
+
|
|
199
|
+
eq = simplify(parse("integrate(x*sqrt(x+2),x)"))
|
|
200
|
+
eq = integrate_subs(eq)
|
|
201
|
+
eq = integrate_const(eq)
|
|
202
|
+
eq = integrate_formula(eq)
|
|
203
|
+
eq = expand(eq)
|
|
204
|
+
eq = integrate_const(eq)
|
|
205
|
+
eq = integrate_summation(eq)
|
|
206
|
+
eq = simplify(eq)
|
|
207
|
+
eq = integrate_const(eq)
|
|
208
|
+
eq = integrate_formula(eq)
|
|
209
|
+
eq = integrate_clean(eq)
|
|
210
|
+
print(simplify(fraction(simplify(eq))))
|
|
211
|
+
|
|
212
|
+
eq = simplify(parse("integrate(x/(e^(x^2)),x)"))
|
|
213
|
+
eq = integrate_subs(eq)
|
|
214
|
+
eq = integrate_const(eq)
|
|
215
|
+
eq = integrate_formula(eq)
|
|
216
|
+
eq = simplify(eq)
|
|
217
|
+
eq = integrate_formula(eq)
|
|
218
|
+
eq = integrate_clean(eq)
|
|
219
|
+
print(simplify(eq))
|
|
220
|
+
|
|
221
|
+
eq = fraction(trig0(trig1(simplify(parse("integrate(sin(x)^4,x)")))))
|
|
222
|
+
eq = integrate_const(eq)
|
|
223
|
+
eq = integrate_summation(eq)
|
|
224
|
+
eq = integrate_formula(eq)
|
|
225
|
+
eq = integrate_const(eq)
|
|
226
|
+
eq = integrate_formula(eq)
|
|
227
|
+
print(factor0(simplify(fraction(simplify(eq)))))
|
|
228
|
+
```
|
|
229
|
+
#### Output
|
|
230
|
+
|
|
231
|
+
```
|
|
232
|
+
log(abs((1+(x^2))))
|
|
233
|
+
cos(cos(x))
|
|
234
|
+
((6*((2+x)^(5/2)))-(20*((2+x)^(3/2))))/15
|
|
235
|
+
-((e^-(x^2))/2)
|
|
236
|
+
-(((8*sin((2*x)))-(12*x)-sin((4*x)))/32)
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
#### Example Demonstration 4 (derivation of hydrogen atom's ground state energy in electron volts using the variational principle in quantum physics)
|
|
240
|
+
```python
|
|
241
|
+
from mathai import *;
|
|
242
|
+
def auto_integration(eq):
|
|
243
|
+
for _ in range(3):
|
|
244
|
+
eq=dowhile(integrate_subs(eq),lambda x:integrate_summation(integrate_const(integrate_formula(simplify(expand(x))))));
|
|
245
|
+
out=integrate_clean(copy.deepcopy(eq));
|
|
246
|
+
if "f_integrate" not in str_form(out):return dowhile(out,lambda x:simplify(fraction(x)));
|
|
247
|
+
eq=integrate_byparts(eq);
|
|
248
|
+
return eq;
|
|
249
|
+
z,k,m,e1,hbar=map(lambda s:simplify(parse(s)),["1","8987551787","9109383701*10^(-40)","1602176634*10^(-28)","1054571817*10^(-43)"]);
|
|
250
|
+
pi,euler,r=tree_form("s_pi"),tree_form("s_e"),parse("r");a0=hbar**2/(k*e1**2*m);psi=((z**3/(pi*a0**3)).fx("sqrt"))*euler**(-(z/a0)*r);
|
|
251
|
+
laplace_psi=diff(r**2*diff(psi,r.name),r.name)/r**2;V=-(k*z*e1**2)/r;Hpsi=-hbar**2/(2*m)*laplace_psi+V*psi;
|
|
252
|
+
norm=lambda f:simplify(
|
|
253
|
+
limit3(limit2(expand(TreeNode("f_limitpinf",[auto_integration(TreeNode("f_integrate",[f*parse("4")*pi*r**2,r])),r]))))
|
|
254
|
+
-limit1(TreeNode("f_limit",[auto_integration(TreeNode("f_integrate",[f*parse("4")*pi*r**2,r])),r]))
|
|
255
|
+
);
|
|
256
|
+
print(compute(norm(psi*Hpsi)/(norm(psi**2)*e1)));
|
|
257
|
+
```
|
|
258
|
+
#### Output
|
|
259
|
+
|
|
260
|
+
```
|
|
261
|
+
-13.605693122882867
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
#### Example Demonstration 5 (boolean algebra)
|
|
265
|
+
```python
|
|
266
|
+
from mathai import *
|
|
267
|
+
print(logic_n(simplify(parse("~(p<->q)<->(~p<->q)"))))
|
|
268
|
+
print(logic_n(simplify(parse("(p->q)<->(~q->~p)"))))
|
|
269
|
+
```
|
|
270
|
+
#### Output
|
|
271
|
+
|
|
272
|
+
```
|
|
273
|
+
true
|
|
274
|
+
true
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
#### Example Demonstration 6 (limits)
|
|
278
|
+
```python
|
|
279
|
+
from mathai import *
|
|
280
|
+
limits = ["(e^(tan(x)) - 1 - tan(x)) / x^2", "sin(x)/x", "(1-cos(x))/x^2", "(sin(x)-x)/sin(x)^3"]
|
|
281
|
+
for q in limits:
|
|
282
|
+
q = fraction(simplify(TreeNode("f_limit",[parse(q),parse("x")])))
|
|
283
|
+
q = limit1(q)
|
|
284
|
+
print(q)
|
|
285
|
+
```
|
|
286
|
+
#### Output
|
|
287
|
+
|
|
288
|
+
```
|
|
289
|
+
1/2
|
|
290
|
+
1
|
|
291
|
+
1/2
|
|
292
|
+
-(1/6)
|
|
293
|
+
```
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
mathai/__init__.py,sha256=Mv0vNdV-FHKS6MzAsnHsE0eBtSkCUq0nc9tUgCWxbFo,1541
|
|
2
|
+
mathai/apart.py,sha256=VSS3khE9PNuxiRvdU5JDl4IN-KJBSIFjwR17pkhviXI,4197
|
|
3
|
+
mathai/base.py,sha256=hRiJWS94asWl-t11eGrVCEhZqIub0T-8S_Eqmlun6mI,15819
|
|
4
|
+
mathai/bivariate_inequality.py,sha256=Da-A1kqVynR0tNOlEI7GSTf5T2vNkcF4etL9-EoyPJg,11415
|
|
5
|
+
mathai/console.py,sha256=Sn58iwYE79MLEh67s8X3q6vZjw6g7f9XM1T8_dBBR2o,3048
|
|
6
|
+
mathai/diff.py,sha256=RSTwlfeddvYXUDShCeRdcPjsmAS8Vf5OkYJAaUBPaiM,3060
|
|
7
|
+
mathai/expand.py,sha256=r2Ha6graDLgLOlx3ox4egUvJD5L_-4_n-FQs2wyWVKg,6284
|
|
8
|
+
mathai/factor.py,sha256=3wcmZOGUqMlLj4v2DA14ZLqEQ7khavOi7PjZJU6VX40,12494
|
|
9
|
+
mathai/fraction.py,sha256=88xvRpDGfFi8tbe1QIyejdSP91HcErrN4VS2MxzbhrY,4392
|
|
10
|
+
mathai/integrate.py,sha256=C_lqYgQN4UiriCb_LDkpwtKx7XJhp_K8T9skCkxWqas,17208
|
|
11
|
+
mathai/inverse.py,sha256=ya7P8WjzfaAL3UXL7xqOh5GaIsXLDZ-F6lZFy3IEgaQ,2931
|
|
12
|
+
mathai/limit.py,sha256=9F8i9UZh2xb-V8A5Sd1gdhDf9c2RFgpE1GdNn9MvbWI,5703
|
|
13
|
+
mathai/linear.py,sha256=viGlPU8BPrjLWHlyNUvnfPHNH5d4ZBImiQMdyXaKGg0,5702
|
|
14
|
+
mathai/logic.py,sha256=Ndz4Fd6aNCmzFlqoPyyIpSmV_BXmYHsurePjLyZJoNc,9809
|
|
15
|
+
mathai/matrix.py,sha256=sIusSmZN0Y6k4TovI5L6Hepls9i7FPRjA3CZIU4X4_w,7276
|
|
16
|
+
mathai/ode.py,sha256=zxxTXAOpt7oSsfpgI4vHsCWKXevmM96ZOBZWWs-vj8Y,4801
|
|
17
|
+
mathai/parser.py,sha256=3cBl7DhqL275gqXszET5zC85O9v3XKxRPc2EaOigAns,7302
|
|
18
|
+
mathai/parsetab.py,sha256=TL-4jvRM_Tx6ipwet8CFJc2DkjR4tGsbrGF_r4IC8xI,9651
|
|
19
|
+
mathai/printeq.py,sha256=4UgLJo-vV_YlVw_3QUQY_jQMHrFnG-ZKAyVZsd7yD6o,1450
|
|
20
|
+
mathai/simplify.py,sha256=VsUw89U3FqSpD3mMUGM0pr0dZ__MDQOBD8maaB7MDBY,19973
|
|
21
|
+
mathai/structure.py,sha256=wrU7kqphSN7CqaVffyHHXD2-3t5My_Z_TtYFoUe_lTU,4099
|
|
22
|
+
mathai/tool.py,sha256=ozcXTXLbKUnyPM9r9kz9M43YA2CBcWezcqLZfEs8rpc,6051
|
|
23
|
+
mathai/trig.py,sha256=fnBbfiopcQzFg4ya1BoO5M0X_aCBnse2bjnKh1juw4I,11223
|
|
24
|
+
mathai/univariate_inequality.py,sha256=LPFdWgC1y5zBwnsy1wwZxj-yP_SbqFDhCmTTzhuwoiY,16469
|
|
25
|
+
mathai-0.7.2.dist-info/METADATA,sha256=e4tsi5hAzJaj4cqRDXewQl3SueJlmBt8ePY3Jvxbwj4,7742
|
|
26
|
+
mathai-0.7.2.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
27
|
+
mathai-0.7.2.dist-info/top_level.txt,sha256=ROP4l3OhGYw3ihkQGASr18xM9GsK4z3_6whV5AyXLwE,7
|
|
28
|
+
mathai-0.7.2.dist-info/RECORD,,
|