mathai 0.4.7__tar.gz → 0.4.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-0.4.7 → mathai-0.4.8}/PKG-INFO +4 -1
- {mathai-0.4.7 → mathai-0.4.8}/README.md +3 -0
- {mathai-0.4.7 → mathai-0.4.8}/mathai/__init__.py +3 -2
- {mathai-0.4.7 → mathai-0.4.8}/mathai/apart.py +28 -9
- {mathai-0.4.7 → mathai-0.4.8}/mathai/base.py +1 -1
- {mathai-0.4.7 → mathai-0.4.8}/mathai/factor.py +11 -5
- {mathai-0.4.7 → mathai-0.4.8}/mathai/integrate.py +39 -5
- {mathai-0.4.7 → mathai-0.4.8}/mathai/limit.py +2 -0
- {mathai-0.4.7 → mathai-0.4.8}/mathai/simplify.py +9 -0
- mathai-0.4.8/mathai/tool.py +163 -0
- {mathai-0.4.7 → mathai-0.4.8}/mathai/trig.py +3 -2
- {mathai-0.4.7 → mathai-0.4.8}/mathai.egg-info/PKG-INFO +4 -1
- {mathai-0.4.7 → mathai-0.4.8}/setup.py +1 -1
- mathai-0.4.7/mathai/tool.py +0 -67
- {mathai-0.4.7 → mathai-0.4.8}/mathai/console.py +0 -0
- {mathai-0.4.7 → mathai-0.4.8}/mathai/diff.py +0 -0
- {mathai-0.4.7 → mathai-0.4.8}/mathai/expand.py +0 -0
- {mathai-0.4.7 → mathai-0.4.8}/mathai/fraction.py +0 -0
- {mathai-0.4.7 → mathai-0.4.8}/mathai/inverse.py +0 -0
- {mathai-0.4.7 → mathai-0.4.8}/mathai/linear.py +0 -0
- {mathai-0.4.7 → mathai-0.4.8}/mathai/logic.py +0 -0
- {mathai-0.4.7 → mathai-0.4.8}/mathai/ode.py +0 -0
- {mathai-0.4.7 → mathai-0.4.8}/mathai/parser.py +0 -0
- {mathai-0.4.7 → mathai-0.4.8}/mathai/printeq.py +0 -0
- {mathai-0.4.7 → mathai-0.4.8}/mathai/structure.py +0 -0
- {mathai-0.4.7 → mathai-0.4.8}/mathai/univariate_inequality.py +0 -0
- {mathai-0.4.7 → mathai-0.4.8}/mathai.egg-info/SOURCES.txt +0 -0
- {mathai-0.4.7 → mathai-0.4.8}/mathai.egg-info/dependency_links.txt +0 -0
- {mathai-0.4.7 → mathai-0.4.8}/mathai.egg-info/requires.txt +0 -0
- {mathai-0.4.7 → mathai-0.4.8}/mathai.egg-info/top_level.txt +0 -0
- {mathai-0.4.7 → mathai-0.4.8}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mathai
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.8
|
|
4
4
|
Summary: Mathematics solving Ai tailored to NCERT
|
|
5
5
|
Home-page: https://github.com/infinity390/mathai4
|
|
6
6
|
Author: educated indians are having a low iq and are good for nothing
|
|
@@ -16,6 +16,9 @@ Dynamic: requires-python
|
|
|
16
16
|
Dynamic: summary
|
|
17
17
|
|
|
18
18
|
# Math AI Documentation
|
|
19
|
+
## Source
|
|
20
|
+
Github repository of the code
|
|
21
|
+
https://github.com/infinity390/mathai4
|
|
19
22
|
|
|
20
23
|
## Philosophy
|
|
21
24
|
I think it is a big realization in computer science and programming to realize that computers can solve mathematics.
|
|
@@ -37,7 +37,7 @@ from .trig import trig0, trig1, trig2, trig3, trig4
|
|
|
37
37
|
|
|
38
38
|
from .logic import logic0, logic1, logic2, logic3
|
|
39
39
|
|
|
40
|
-
from .apart import apart
|
|
40
|
+
from .apart import apart, apart2
|
|
41
41
|
|
|
42
42
|
from .console import console
|
|
43
43
|
|
|
@@ -48,4 +48,5 @@ from .univariate_inequality import wavycurvy, absolute, domain, handle_sqrt
|
|
|
48
48
|
from .base import *
|
|
49
49
|
|
|
50
50
|
from .tool import enclose_const
|
|
51
|
-
|
|
51
|
+
from .tool import poly_simplify
|
|
52
|
+
from .tool import longdiv
|
|
@@ -6,19 +6,23 @@ from .diff import diff
|
|
|
6
6
|
from .inverse import inverse
|
|
7
7
|
from .base import *
|
|
8
8
|
import math
|
|
9
|
-
from .
|
|
9
|
+
from .factor import factor2
|
|
10
|
+
from .tool import poly, enclose_const, longdiv
|
|
10
11
|
|
|
11
12
|
def _apart(eq, v=None):
|
|
13
|
+
|
|
12
14
|
if v is None:
|
|
13
15
|
if len(vlist(eq)) == 0:
|
|
14
16
|
return eq
|
|
15
17
|
v = vlist(eq)[0]
|
|
16
18
|
origv = vlist(eq)
|
|
17
|
-
|
|
19
|
+
|
|
18
20
|
if eq.name != "f_mul":
|
|
19
21
|
return eq
|
|
22
|
+
|
|
20
23
|
if any("f_"+item in str_form(eq) for item in "sin cos tan log".split(" ")):
|
|
21
24
|
return eq
|
|
25
|
+
|
|
22
26
|
def exclude(eq):
|
|
23
27
|
if eq.name == "f_pow" and frac(eq.children[1]) is not None and frac(eq.children[1]).denominator != 1:
|
|
24
28
|
return False
|
|
@@ -48,7 +52,7 @@ def _apart(eq, v=None):
|
|
|
48
52
|
|
|
49
53
|
|
|
50
54
|
facd2 = remove_duplicates_custom(facd, lambda m, n: simplify(expand(simplify(m-n))) == tree_form("d_0"))
|
|
51
|
-
|
|
55
|
+
|
|
52
56
|
if len(facd2) == 1:
|
|
53
57
|
return eq
|
|
54
58
|
x = tree_form(v)
|
|
@@ -60,7 +64,7 @@ def _apart(eq, v=None):
|
|
|
60
64
|
g = countfac(facd, item)
|
|
61
65
|
for n in range(int(g.name[2:])):
|
|
62
66
|
n = n+1
|
|
63
|
-
if n >
|
|
67
|
+
if n > 3:
|
|
64
68
|
return eq
|
|
65
69
|
n = tree_form("d_"+str(n))
|
|
66
70
|
|
|
@@ -87,6 +91,7 @@ def _apart(eq, v=None):
|
|
|
87
91
|
dem.append(item**n)
|
|
88
92
|
s.append(a/item**n)
|
|
89
93
|
else:
|
|
94
|
+
|
|
90
95
|
return eq
|
|
91
96
|
final3 = summation(s)
|
|
92
97
|
|
|
@@ -95,13 +100,13 @@ def _apart(eq, v=None):
|
|
|
95
100
|
final2 = []
|
|
96
101
|
for i in range(len(num)):
|
|
97
102
|
final2.append(product([dem[k] for k in range(len(dem)) if i != k])*num[i])
|
|
98
|
-
|
|
103
|
+
|
|
99
104
|
final = summation(final2)
|
|
100
|
-
|
|
105
|
+
|
|
101
106
|
s = simplify(TreeNode("f_eq", [final-eq2, tree_form("d_0")]))
|
|
102
|
-
|
|
107
|
+
|
|
103
108
|
lst = poly(s.children[0], v)
|
|
104
|
-
|
|
109
|
+
|
|
105
110
|
lst = [TreeNode("f_eq", [item, tree_form("d_0")]) for item in lst if "v_" in str_form(item)]
|
|
106
111
|
lst2 = []
|
|
107
112
|
for item in lst:
|
|
@@ -112,12 +117,26 @@ def _apart(eq, v=None):
|
|
|
112
117
|
for item in out.children:
|
|
113
118
|
|
|
114
119
|
final3 = replace(final3, tree_form(list(set(vlist(item))&set(origv))[0]), inverse(item.children[0], list(set(vlist(item))&set(origv))[0]))
|
|
115
|
-
|
|
120
|
+
final4 = simplify(final3)
|
|
121
|
+
|
|
122
|
+
return final4
|
|
123
|
+
def apart2(eq):
|
|
124
|
+
if eq.name == "f_mul":
|
|
125
|
+
|
|
126
|
+
a, b = num_dem(eq)
|
|
127
|
+
|
|
128
|
+
tmp = longdiv(a, b, 2, 1)
|
|
129
|
+
|
|
130
|
+
if tmp is not None:
|
|
131
|
+
return simplify(tmp[0]+tmp[1]/b)
|
|
132
|
+
return TreeNode(eq.name, [apart2(child) for child in eq.children])
|
|
116
133
|
def apart(eq):
|
|
134
|
+
eq = factor2(simplify(eq))
|
|
117
135
|
eq, fx = enclose_const(eq)
|
|
118
136
|
def helper(eq):
|
|
119
137
|
eq2 = _apart(eq)
|
|
120
138
|
if eq != eq2:
|
|
121
139
|
return eq2
|
|
140
|
+
|
|
122
141
|
return TreeNode(eq.name, [helper(child) for child in eq.children])
|
|
123
142
|
return fx(helper(eq))
|
|
@@ -43,6 +43,7 @@ def take_common(eq):
|
|
|
43
43
|
eq2 = term_common(eq2)
|
|
44
44
|
if eq2.name == "f_mul":
|
|
45
45
|
return take_common(solve(summation([item2 for index, item2 in enumerate(eq.children) if index not in item]) + eq2))
|
|
46
|
+
break
|
|
46
47
|
return eq
|
|
47
48
|
return term_common(eq)
|
|
48
49
|
def take_common2(eq):
|
|
@@ -190,7 +191,7 @@ def factor_helper(equation, complexnum, power=2):
|
|
|
190
191
|
high(child)
|
|
191
192
|
def helper(eq):
|
|
192
193
|
nonlocal maxnum, fx, r
|
|
193
|
-
if eq.name == "f_pow" and eq.children[1].name[:2] == "d_":
|
|
194
|
+
if eq.name == "f_pow" and eq.children[1].name[:2] == "d_" and eq.children[0] == curr:
|
|
194
195
|
n = int(eq.children[1].name[2:])
|
|
195
196
|
if maxnum !=1 and n % maxnum == 0:
|
|
196
197
|
fx = lambda x: replace(x, tree_form(r), curr**tree_form("d_"+str(maxnum)))
|
|
@@ -198,18 +199,19 @@ def factor_helper(equation, complexnum, power=2):
|
|
|
198
199
|
return out
|
|
199
200
|
return TreeNode(eq.name, [helper(child) for child in eq.children])
|
|
200
201
|
out = None
|
|
202
|
+
|
|
201
203
|
for i in range(2,4):
|
|
202
204
|
if power == i:
|
|
203
205
|
for curr in vlist(equation):
|
|
204
206
|
curr = tree_form(curr)
|
|
205
207
|
fx = None
|
|
206
208
|
maxnum = 1
|
|
207
|
-
high(equation)
|
|
209
|
+
high(equation.copy_tree())
|
|
208
210
|
|
|
209
211
|
if maxnum != 1:
|
|
210
212
|
maxnum= maxnum/power
|
|
211
213
|
maxnum = round(maxnum)
|
|
212
|
-
eq2 = helper(equation)
|
|
214
|
+
eq2 = helper(equation.copy_tree())
|
|
213
215
|
if not contain(eq2, tree_form(r)) or (contain(eq2, tree_form(r)) and not contain(eq2,curr)):
|
|
214
216
|
if not contain(eq2, tree_form(r)):
|
|
215
217
|
r = curr.name
|
|
@@ -262,14 +264,18 @@ def factor_helper(equation, complexnum, power=2):
|
|
|
262
264
|
if success:
|
|
263
265
|
equation = fx(eq2)
|
|
264
266
|
break
|
|
267
|
+
|
|
265
268
|
if power == 4:
|
|
269
|
+
|
|
266
270
|
out = transform_formula(helper(equation), "v_0", formula_gen9[0], formula_gen9[1], formula_gen9[2])
|
|
271
|
+
|
|
267
272
|
if out is not None:
|
|
268
273
|
out = simplify(solve(out))
|
|
269
274
|
if out is not None and (complexnum or (not complexnum and not contain(out, tree_form("s_i")))):
|
|
270
275
|
return out
|
|
276
|
+
|
|
271
277
|
return TreeNode(equation.name, [factor_helper(child, complexnum, power) for child in equation.children])
|
|
272
|
-
def factor(equation
|
|
273
|
-
return solve(take_common2(simplify(
|
|
278
|
+
def factor(equation):
|
|
279
|
+
return solve(take_common2(simplify(equation)))
|
|
274
280
|
def factor2(equation, complexnum=False):
|
|
275
281
|
return solve(factor_helper(solve(factor_helper(simplify(factor_helper(simplify(equation), complexnum, 2)), complexnum, 3)), complexnum, 4))
|
|
@@ -31,8 +31,13 @@ def integrate_summation(equation):
|
|
|
31
31
|
def subs_heuristic(eq, var):
|
|
32
32
|
output = []
|
|
33
33
|
def collect2(eq):
|
|
34
|
+
if eq.name == "f_pow" and frac(eq.children[1]) is not None and frac(eq.children[1]) == Fraction(1,2):
|
|
35
|
+
|
|
36
|
+
if eq.children[0] == var:
|
|
37
|
+
output.append(str_form(eq))
|
|
34
38
|
if eq.name == "f_pow" and frac(eq.children[1]) is not None and frac(eq.children[1]).denominator == 1 and abs(frac(eq.children[1]).numerator) % 2 == 0:
|
|
35
|
-
|
|
39
|
+
if len(eq.children[0].children) == 0 or eq.children[0].children[0] == var:
|
|
40
|
+
output.append(str_form(eq.children[0]**2))
|
|
36
41
|
if eq.name in ["f_pow", "f_sin", "f_cos", "f_arcsin"] and var.name in str_form(eq.children[0]):
|
|
37
42
|
if eq.children[0].name[:2] != "v_":
|
|
38
43
|
output.append(str_form(eq.children[0]))
|
|
@@ -57,7 +62,20 @@ def subs_heuristic(eq, var):
|
|
|
57
62
|
|
|
58
63
|
tmp = list(set([simplify(tree_form(x)) for x in output]))
|
|
59
64
|
tmp = sorted(tmp, key=lambda x: len(str(x)))
|
|
60
|
-
|
|
65
|
+
poly_term = None
|
|
66
|
+
term_degree = 100
|
|
67
|
+
output = []
|
|
68
|
+
for item in tmp:
|
|
69
|
+
n = poly(simplify(item), var.name)
|
|
70
|
+
if n is None:
|
|
71
|
+
output.append(item)
|
|
72
|
+
else:
|
|
73
|
+
if term_degree > len(n):
|
|
74
|
+
poly_term = item
|
|
75
|
+
term_degree = len(n)
|
|
76
|
+
if poly_term is None:
|
|
77
|
+
return tmp
|
|
78
|
+
return [poly_term]+output
|
|
61
79
|
try_index = []
|
|
62
80
|
try_lst = []
|
|
63
81
|
def ref(eq):
|
|
@@ -170,7 +188,7 @@ def integrate_subs(equation, term, v1, v2):
|
|
|
170
188
|
|
|
171
189
|
return none
|
|
172
190
|
|
|
173
|
-
return TreeNode("f_subs", [TreeNode("f_integrate", [simplify(
|
|
191
|
+
return TreeNode("f_subs", [TreeNode("f_integrate", [simplify(equation), tree_form(origv2)]),tree_form(origv2) ,g])
|
|
174
192
|
|
|
175
193
|
def integrate_subs_main(equation):
|
|
176
194
|
if equation.name == "f_ref":
|
|
@@ -359,10 +377,21 @@ def integration_formula_trig():
|
|
|
359
377
|
[parse("C"), parse("0"), parse("1")], [parse("D"), parse("0"), parse("1")],\
|
|
360
378
|
[parse("E"), parse("0"), parse("1")], [parse("F"), parse("0"), parse("1")]]
|
|
361
379
|
return [formula_list, var, expr]
|
|
362
|
-
|
|
363
|
-
|
|
364
380
|
formula_gen4 = integration_formula_trig()
|
|
365
381
|
|
|
382
|
+
def integration_formula_ex():
|
|
383
|
+
var = "x"
|
|
384
|
+
formula_list = [
|
|
385
|
+
(
|
|
386
|
+
f"e^(A*{var})*cos(B*{var})",
|
|
387
|
+
f"e^(A*{var})*(A*cos(B*{var}) + B*sin(B*{var}))/(A^2 + B^2)"
|
|
388
|
+
)
|
|
389
|
+
]
|
|
390
|
+
formula_list = [[simplify(parse(y)) for y in x] for x in formula_list]
|
|
391
|
+
expr = [[parse("A"), parse("1")], [parse("B"), parse("1")]]
|
|
392
|
+
return [formula_list, var, expr]
|
|
393
|
+
|
|
394
|
+
formula_gen11 = integration_formula_ex()
|
|
366
395
|
def rm_const(equation):
|
|
367
396
|
if equation.name == "f_ref":
|
|
368
397
|
return equation
|
|
@@ -406,4 +435,9 @@ def integrate_formula(equation):
|
|
|
406
435
|
if out is not None:
|
|
407
436
|
|
|
408
437
|
return out
|
|
438
|
+
if "f_cos" in expr_str and contain(integrand, tree_form("s_e")):
|
|
439
|
+
out = transform_formula(integrand, wrt.name, formula_gen11[0], formula_gen11[1], formula_gen11[2])
|
|
440
|
+
if out is not None:
|
|
441
|
+
|
|
442
|
+
return out
|
|
409
443
|
return TreeNode(eq2.name, [integrate_formula(child) for child in eq2.children])
|
|
@@ -14,6 +14,7 @@ def substitute_val(eq, val, var="v_0"):
|
|
|
14
14
|
|
|
15
15
|
def subslimit(equation, var):
|
|
16
16
|
equation2 = trig0(replace(equation, var, tree_form("d_0")))
|
|
17
|
+
|
|
17
18
|
try:
|
|
18
19
|
tmp = simplify(equation2)
|
|
19
20
|
return simplify(expand(tmp))
|
|
@@ -35,6 +36,7 @@ def lhospital(num, den, steps,var):
|
|
|
35
36
|
logs = []
|
|
36
37
|
|
|
37
38
|
out = check(num, den, var)
|
|
39
|
+
|
|
38
40
|
if isinstance(out, TreeNode):
|
|
39
41
|
return out,[]
|
|
40
42
|
for _ in range(steps):
|
|
@@ -168,6 +168,15 @@ def clear_div(eq, denom=False):
|
|
|
168
168
|
return solve(product(lst2)),sign
|
|
169
169
|
|
|
170
170
|
def simplify(eq):
|
|
171
|
+
if "v_" not in str_form(eq):
|
|
172
|
+
n = frac(eq)
|
|
173
|
+
if n is not None:
|
|
174
|
+
if n.numerator == 0:
|
|
175
|
+
return tree_form("d_0")
|
|
176
|
+
if n.denominator != 1:
|
|
177
|
+
return tree_form("d_"+str(n.numerator))/tree_form("d_"+str(n.denominator))
|
|
178
|
+
else:
|
|
179
|
+
return tree_form("d_"+str(n.numerator))
|
|
171
180
|
error = False
|
|
172
181
|
eq = flatten_tree(eq)
|
|
173
182
|
if eq.name in ["f_and", "f_or", "f_not"]:
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
from .diff import diff
|
|
2
|
+
from .expand import expand
|
|
3
|
+
from .simplify import simplify, solve
|
|
4
|
+
from .base import *
|
|
5
|
+
import math
|
|
6
|
+
|
|
7
|
+
def poly_div(dividend_coeffs, divisor_coeffs):
|
|
8
|
+
"""
|
|
9
|
+
Perform polynomial division using coefficients with symbolic simplification.
|
|
10
|
+
"""
|
|
11
|
+
# Deep copy inputs using copy_tree()
|
|
12
|
+
dividend = [item.copy_tree() for item in dividend_coeffs]
|
|
13
|
+
divisor = [item.copy_tree() for item in divisor_coeffs]
|
|
14
|
+
|
|
15
|
+
# Remove leading zeros
|
|
16
|
+
while len(dividend) > 1 and simplify(dividend[0]) == 0:
|
|
17
|
+
dividend.pop(0)
|
|
18
|
+
while len(divisor) > 1 and simplify(divisor[0]) == 0:
|
|
19
|
+
divisor.pop(0)
|
|
20
|
+
|
|
21
|
+
# Validate divisor
|
|
22
|
+
if len(divisor) == 0 or simplify(divisor[0]) == 0:
|
|
23
|
+
raise ValueError("Invalid divisor")
|
|
24
|
+
|
|
25
|
+
if len(dividend) < len(divisor):
|
|
26
|
+
return [tree_form("d_0")], [item.copy_tree() for item in dividend]
|
|
27
|
+
|
|
28
|
+
# Calculate degrees
|
|
29
|
+
deg_p = len(dividend) - 1
|
|
30
|
+
deg_q = len(divisor) - 1
|
|
31
|
+
deg_quot = deg_p - deg_q
|
|
32
|
+
|
|
33
|
+
# Initialize quotient (highest degree first)
|
|
34
|
+
quotient = [tree_form("d_0")] * (deg_quot + 1)
|
|
35
|
+
|
|
36
|
+
# Working dividend - keep original structure
|
|
37
|
+
working_dividend = [item.copy_tree() for item in dividend]
|
|
38
|
+
|
|
39
|
+
# Long division - align by current leading terms
|
|
40
|
+
for k in range(deg_quot, -1, -1):
|
|
41
|
+
# Remove leading zeros from working dividend
|
|
42
|
+
while len(working_dividend) > 1 and simplify(working_dividend[0]) == 0:
|
|
43
|
+
working_dividend.pop(0)
|
|
44
|
+
|
|
45
|
+
if len(working_dividend) == 0 or simplify(working_dividend[0]) == 0:
|
|
46
|
+
continue
|
|
47
|
+
|
|
48
|
+
# Calculate quotient term for degree k
|
|
49
|
+
leading_ratio = simplify(working_dividend[0] / divisor[0])
|
|
50
|
+
quotient[k] = leading_ratio
|
|
51
|
+
|
|
52
|
+
# Subtract leading_ratio * divisor (aligned at leading terms)
|
|
53
|
+
new_dividend = []
|
|
54
|
+
for i in range(max(len(working_dividend), len(divisor))):
|
|
55
|
+
dividend_term = working_dividend[i] if i < len(working_dividend) else tree_form("d_0")
|
|
56
|
+
divisor_term = simplify(leading_ratio * divisor[i]) if i < len(divisor) else tree_form("d_0")
|
|
57
|
+
result = simplify(dividend_term - divisor_term)
|
|
58
|
+
new_dividend.append(result)
|
|
59
|
+
|
|
60
|
+
working_dividend = new_dividend
|
|
61
|
+
|
|
62
|
+
# Remainder is terms with degree < deg_q (last deg_q terms of final dividend)
|
|
63
|
+
remainder = working_dividend[-(deg_q):] if len(working_dividend) > deg_q else working_dividend
|
|
64
|
+
while len(remainder) > 1 and simplify(remainder[0]) == 0:
|
|
65
|
+
remainder.pop(0)
|
|
66
|
+
if not remainder:
|
|
67
|
+
remainder = [tree_form("d_0")]
|
|
68
|
+
|
|
69
|
+
# Clean quotient trailing zeros
|
|
70
|
+
while len(quotient) > 1 and simplify(quotient[-1]) == 0:
|
|
71
|
+
quotient.pop()
|
|
72
|
+
|
|
73
|
+
return quotient, remainder
|
|
74
|
+
|
|
75
|
+
def unpoly(eq, var):
|
|
76
|
+
eq = eq[::-1]
|
|
77
|
+
eq = [simplify(item) for item in eq]
|
|
78
|
+
eq2 = copy.deepcopy([eq[i]*tree_form(var)**tree_form("d_"+str(i)) if i != 0 else eq[i] for i in range(len(eq))])
|
|
79
|
+
return summation(eq2)
|
|
80
|
+
|
|
81
|
+
def longdiv(p, q, p_min=0, q_min=0):
|
|
82
|
+
p, q = simplify(p), simplify(q)
|
|
83
|
+
|
|
84
|
+
var = set(vlist(p)) & set(vlist(q))
|
|
85
|
+
if len(var) > 0:
|
|
86
|
+
var = list(var)[0]
|
|
87
|
+
p = poly(p, var)
|
|
88
|
+
q = poly(q, var)
|
|
89
|
+
if p is not None and q is not None and len(p)-1>=p_min and len(q)-1>=q_min and len(p)<=len(q):
|
|
90
|
+
a, b = poly_div(p, q)
|
|
91
|
+
return unpoly(a, var), unpoly(b, var)
|
|
92
|
+
return None
|
|
93
|
+
def poly_simplify(eq):
|
|
94
|
+
a, b = num_dem(eq)
|
|
95
|
+
b = simplify(b)
|
|
96
|
+
if b != 1:
|
|
97
|
+
return simplify(poly_simplify(a)/poly_simplify(b))
|
|
98
|
+
for var in vlist(eq):
|
|
99
|
+
n = poly(eq, var, 20)
|
|
100
|
+
if n is not None:
|
|
101
|
+
return simplify(unpoly(n, var))
|
|
102
|
+
return TreeNode(eq.name, [poly_simplify(child) for child in eq.children])
|
|
103
|
+
def enclose_const(eq):
|
|
104
|
+
def req(eq, dic):
|
|
105
|
+
for key in dic.keys():
|
|
106
|
+
eq = replace(eq, dic[key], key)
|
|
107
|
+
return eq
|
|
108
|
+
alloclst = []
|
|
109
|
+
for i in range(0,26):
|
|
110
|
+
if "v_"+str(i) not in vlist(eq):
|
|
111
|
+
alloclst.append(tree_form("v_"+str(i)))
|
|
112
|
+
dic = {}
|
|
113
|
+
def helper(eq):
|
|
114
|
+
nonlocal alloclst, dic
|
|
115
|
+
if frac(eq) is not None:
|
|
116
|
+
return eq
|
|
117
|
+
|
|
118
|
+
if "v_" not in str_form(eq):
|
|
119
|
+
if eq not in dic.keys():
|
|
120
|
+
n = alloclst.pop(0)
|
|
121
|
+
dic[eq] = n
|
|
122
|
+
return dic[eq]
|
|
123
|
+
else:
|
|
124
|
+
if eq.name == "f_pow":
|
|
125
|
+
return TreeNode(eq.name, [helper(eq.children[0]), eq.children[1]])
|
|
126
|
+
return TreeNode(eq.name, [helper(child) for child in eq.children])
|
|
127
|
+
eq= helper(eq)
|
|
128
|
+
return eq, lambda x: req(x, dic)
|
|
129
|
+
|
|
130
|
+
def poly(eq, to_compute, m=10):
|
|
131
|
+
def substitute_val(eq, val, var="v_0"):
|
|
132
|
+
eq = replace(eq, tree_form(var), tree_form("d_"+str(val)))
|
|
133
|
+
return eq
|
|
134
|
+
def inv(eq):
|
|
135
|
+
if eq.name[:2] == "f_" and eq.name[2:] in "ref try integrate subs".split(" "):
|
|
136
|
+
return False
|
|
137
|
+
if eq.name[2:] in ["sin", "cos", "log"] and contain(eq.children[0], tree_form(to_compute)):
|
|
138
|
+
return False
|
|
139
|
+
if eq.name == "f_pow" and contain(eq.children[0], tree_form(to_compute)) and\
|
|
140
|
+
(frac(eq.children[1]) is None or frac(eq.children[1]) < 0 or frac(eq.children[1]).denominator != 1):
|
|
141
|
+
return False
|
|
142
|
+
if eq.name == "f_abs":
|
|
143
|
+
return False
|
|
144
|
+
if any(not inv(child) for child in eq.children):
|
|
145
|
+
return False
|
|
146
|
+
return True
|
|
147
|
+
if not inv(eq):
|
|
148
|
+
return None
|
|
149
|
+
out = []
|
|
150
|
+
eq2 = eq
|
|
151
|
+
for i in range(m):
|
|
152
|
+
out.append(expand(simplify(eq2)))
|
|
153
|
+
eq2 = diff(eq2, to_compute)
|
|
154
|
+
for i in range(len(out)-1,-1,-1):
|
|
155
|
+
if out[i] == tree_form("d_0"):
|
|
156
|
+
out.pop(i)
|
|
157
|
+
else:
|
|
158
|
+
break
|
|
159
|
+
final = []
|
|
160
|
+
for index, item in enumerate(out):
|
|
161
|
+
final.append(substitute_val(item, 0, to_compute)/tree_form("d_"+str(math.factorial(index))))
|
|
162
|
+
|
|
163
|
+
return [expand(simplify(item)) for item in final][::-1]
|
|
@@ -215,7 +215,9 @@ def trig4(eq):
|
|
|
215
215
|
a = eq.children[0].children[0]
|
|
216
216
|
return tree_form("d_1")/(1+a**2)**(tree_form("d_2")**-1)
|
|
217
217
|
|
|
218
|
-
return TreeNode(eq.name, [_trig4(child, False, chance) if
|
|
218
|
+
return TreeNode(eq.name, [_trig4(child, False, chance) if eq.name != "f_add" and\
|
|
219
|
+
(not numer or (eq.name == "f_pow" and frac(eq.children[1]) is not None and frac(eq.children[1]) < 0))\
|
|
220
|
+
else _trig4(child, True, chance) for child in eq.children])
|
|
219
221
|
eq= _trig4(eq)
|
|
220
222
|
if not done:
|
|
221
223
|
eq = _trig4(eq,"cos")
|
|
@@ -255,4 +257,3 @@ def trig2(eq):
|
|
|
255
257
|
|
|
256
258
|
# If no sin/cos pairs found, just recurse on children
|
|
257
259
|
return TreeNode(eq.name, [trig2(child) for child in eq.children])
|
|
258
|
-
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mathai
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.8
|
|
4
4
|
Summary: Mathematics solving Ai tailored to NCERT
|
|
5
5
|
Home-page: https://github.com/infinity390/mathai4
|
|
6
6
|
Author: educated indians are having a low iq and are good for nothing
|
|
@@ -16,6 +16,9 @@ Dynamic: requires-python
|
|
|
16
16
|
Dynamic: summary
|
|
17
17
|
|
|
18
18
|
# Math AI Documentation
|
|
19
|
+
## Source
|
|
20
|
+
Github repository of the code
|
|
21
|
+
https://github.com/infinity390/mathai4
|
|
19
22
|
|
|
20
23
|
## Philosophy
|
|
21
24
|
I think it is a big realization in computer science and programming to realize that computers can solve mathematics.
|
mathai-0.4.7/mathai/tool.py
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
from .diff import diff
|
|
2
|
-
from .expand import expand
|
|
3
|
-
from .simplify import simplify
|
|
4
|
-
from .base import *
|
|
5
|
-
import math
|
|
6
|
-
|
|
7
|
-
def enclose_const(eq):
|
|
8
|
-
def req(eq, dic):
|
|
9
|
-
for key in dic.keys():
|
|
10
|
-
eq = replace(eq, dic[key], key)
|
|
11
|
-
return eq
|
|
12
|
-
alloclst = []
|
|
13
|
-
for i in range(0,26):
|
|
14
|
-
if "v_"+str(i) not in vlist(eq):
|
|
15
|
-
alloclst.append(tree_form("v_"+str(i)))
|
|
16
|
-
dic = {}
|
|
17
|
-
def helper(eq):
|
|
18
|
-
nonlocal alloclst, dic
|
|
19
|
-
if frac(eq) is not None:
|
|
20
|
-
return eq
|
|
21
|
-
|
|
22
|
-
if "v_" not in str_form(eq):
|
|
23
|
-
if eq not in dic.keys():
|
|
24
|
-
n = alloclst.pop(0)
|
|
25
|
-
dic[eq] = n
|
|
26
|
-
return dic[eq]
|
|
27
|
-
else:
|
|
28
|
-
if eq.name == "f_pow":
|
|
29
|
-
return TreeNode(eq.name, [helper(eq.children[0]), eq.children[1]])
|
|
30
|
-
return TreeNode(eq.name, [helper(child) for child in eq.children])
|
|
31
|
-
eq= helper(eq)
|
|
32
|
-
return eq, lambda x: req(x, dic)
|
|
33
|
-
|
|
34
|
-
def poly(eq, to_compute):
|
|
35
|
-
def substitute_val(eq, val, var="v_0"):
|
|
36
|
-
eq = replace(eq, tree_form(var), tree_form("d_"+str(val)))
|
|
37
|
-
return eq
|
|
38
|
-
def inv(eq):
|
|
39
|
-
if eq.name =="f_eq":
|
|
40
|
-
return False
|
|
41
|
-
if eq.name[2:] in ["sin", "cos", "log"] and contain(eq.children[0], tree_form(to_compute)):
|
|
42
|
-
return False
|
|
43
|
-
if eq.name == "f_pow" and contain(eq.children[0], tree_form(to_compute)) and\
|
|
44
|
-
(frac(eq.children[1]) is None or frac(eq.children[1]) < 0 or frac(eq.children[1]).denominator != 1):
|
|
45
|
-
return False
|
|
46
|
-
if eq.name == "f_abs":
|
|
47
|
-
return False
|
|
48
|
-
if any(not inv(child) for child in eq.children):
|
|
49
|
-
return False
|
|
50
|
-
return True
|
|
51
|
-
if not inv(eq):
|
|
52
|
-
return None
|
|
53
|
-
out = []
|
|
54
|
-
eq2 = eq
|
|
55
|
-
for i in range(8):
|
|
56
|
-
out.append(expand(simplify(eq2)))
|
|
57
|
-
eq2 = diff(eq2, to_compute)
|
|
58
|
-
for i in range(len(out)-1,-1,-1):
|
|
59
|
-
if out[i] == tree_form("d_0"):
|
|
60
|
-
out.pop(i)
|
|
61
|
-
else:
|
|
62
|
-
break
|
|
63
|
-
final = []
|
|
64
|
-
for index, item in enumerate(out):
|
|
65
|
-
final.append(substitute_val(item, 0, to_compute)/tree_form("d_"+str(math.factorial(index))))
|
|
66
|
-
|
|
67
|
-
return [expand(simplify(item)) for item in final][::-1]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|