mathai 0.4.0__py3-none-any.whl → 0.6.9__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 +18 -11
- mathai/apart.py +41 -12
- mathai/base.py +141 -38
- mathai/bivariate_inequality.py +317 -0
- mathai/diff.py +3 -3
- mathai/expand.py +92 -93
- mathai/factor.py +213 -41
- mathai/fraction.py +2 -2
- mathai/integrate.py +96 -34
- mathai/inverse.py +4 -4
- mathai/limit.py +96 -70
- mathai/linear.py +96 -84
- mathai/logic.py +7 -1
- mathai/matrix.py +228 -0
- mathai/ode.py +124 -0
- mathai/parser.py +13 -7
- mathai/parsetab.py +61 -0
- mathai/printeq.py +12 -9
- mathai/simplify.py +511 -333
- mathai/structure.py +2 -2
- mathai/tool.py +105 -4
- mathai/trig.py +134 -72
- mathai/univariate_inequality.py +78 -30
- {mathai-0.4.0.dist-info → mathai-0.6.9.dist-info}/METADATA +4 -1
- mathai-0.6.9.dist-info/RECORD +28 -0
- {mathai-0.4.0.dist-info → mathai-0.6.9.dist-info}/WHEEL +1 -1
- mathai/search.py +0 -117
- mathai-0.4.0.dist-info/RECORD +0 -25
- {mathai-0.4.0.dist-info → mathai-0.6.9.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
|
@@ -4,6 +4,102 @@ from .simplify import simplify
|
|
|
4
4
|
from .base import *
|
|
5
5
|
import math
|
|
6
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])
|
|
7
103
|
def enclose_const(eq):
|
|
8
104
|
def req(eq, dic):
|
|
9
105
|
for key in dic.keys():
|
|
@@ -31,12 +127,17 @@ def enclose_const(eq):
|
|
|
31
127
|
eq= helper(eq)
|
|
32
128
|
return eq, lambda x: req(x, dic)
|
|
33
129
|
|
|
34
|
-
def poly(eq, to_compute):
|
|
130
|
+
def poly(eq, to_compute, m=10):
|
|
35
131
|
def substitute_val(eq, val, var="v_0"):
|
|
36
132
|
eq = replace(eq, tree_form(var), tree_form("d_"+str(val)))
|
|
37
133
|
return eq
|
|
38
134
|
def inv(eq):
|
|
39
|
-
if eq.name == "
|
|
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):
|
|
40
141
|
return False
|
|
41
142
|
if eq.name == "f_abs":
|
|
42
143
|
return False
|
|
@@ -47,7 +148,7 @@ def poly(eq, to_compute):
|
|
|
47
148
|
return None
|
|
48
149
|
out = []
|
|
49
150
|
eq2 = eq
|
|
50
|
-
for i in range(
|
|
151
|
+
for i in range(m):
|
|
51
152
|
out.append(expand(simplify(eq2)))
|
|
52
153
|
eq2 = diff(eq2, to_compute)
|
|
53
154
|
for i in range(len(out)-1,-1,-1):
|
|
@@ -58,5 +159,5 @@ def poly(eq, to_compute):
|
|
|
58
159
|
final = []
|
|
59
160
|
for index, item in enumerate(out):
|
|
60
161
|
final.append(substitute_val(item, 0, to_compute)/tree_form("d_"+str(math.factorial(index))))
|
|
61
|
-
|
|
162
|
+
|
|
62
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
|
|
@@ -58,6 +58,9 @@ def trig0(eq):
|
|
|
58
58
|
if a > b:
|
|
59
59
|
a = 2*b - a
|
|
60
60
|
return a, b
|
|
61
|
+
if eq.name == "f_arccosec":
|
|
62
|
+
return (1/eq.children[0]).fx("arcsin")
|
|
63
|
+
|
|
61
64
|
if eq.name == "f_arctan":
|
|
62
65
|
if eq.children[0].name == "d_0":
|
|
63
66
|
return tree_form("d_0")
|
|
@@ -82,7 +85,7 @@ def trig0(eq):
|
|
|
82
85
|
if any(isneg(item) for item in lst):
|
|
83
86
|
return -(eq.children[0]*-1).fx("sin")
|
|
84
87
|
out=single_pi(lst)
|
|
85
|
-
if out is not None:
|
|
88
|
+
if out is not None and tuple(out) in trig_sin_table.keys():
|
|
86
89
|
return trig_sin_table[tuple(out)]
|
|
87
90
|
|
|
88
91
|
if eq.name == "f_cos":
|
|
@@ -96,31 +99,48 @@ def trig0(eq):
|
|
|
96
99
|
if tuple(out) in trig_cos_table.keys():
|
|
97
100
|
return trig_cos_table[tuple(out)]
|
|
98
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:
|
|
99
117
|
|
|
100
|
-
|
|
101
|
-
lst = factor_generation(eq)
|
|
102
|
-
if len(lst) == 1:
|
|
103
|
-
return lst[0]
|
|
118
|
+
return dowhile(expr, cog)
|
|
104
119
|
if len(lst) == 2:
|
|
105
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]
|
|
106
125
|
if a.name == "f_sin" and b.name == "f_sin":
|
|
107
|
-
|
|
126
|
+
out =((A - B).fx("cos") - (A + B).fx("cos")) / tree_form("d_2")
|
|
108
127
|
elif a.name == "f_cos" and b.name == "f_cos":
|
|
109
|
-
|
|
128
|
+
out =((A - B).fx("cos") + (A + B).fx("cos")) / tree_form("d_2")
|
|
110
129
|
elif a.name == "f_sin" and b.name == "f_cos":
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
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
|
+
|
|
124
144
|
def trig_formula_init():
|
|
125
145
|
var = ""
|
|
126
146
|
formula_list = [(f"A*sin(B)+C*sin(B)", f"(A^2+C^2)^(1/2)*sin(B+arctan(C/A))"),\
|
|
@@ -159,56 +179,98 @@ def noneg_pow(eq):
|
|
|
159
179
|
if eq.name == "f_pow" and frac(eq.children[1]) is not None and frac(eq.children[1])<0:
|
|
160
180
|
return (eq.children[0]**(simplify(-eq.children[1])))**-1
|
|
161
181
|
return TreeNode(eq.name, [noneg_pow(child) for child in eq.children])
|
|
162
|
-
def _trig1(equation):
|
|
163
|
-
equation = product_to_sum(equation)
|
|
164
|
-
return TreeNode(equation.name, [_trig1(child) for child in equation.children])
|
|
165
|
-
def trig1(eq):
|
|
166
|
-
return simplify(_trig1(noneg_pow(eq)))
|
|
167
182
|
|
|
168
|
-
def
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
return 1
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
183
|
+
def trig1(eq):
|
|
184
|
+
eq = noneg_pow(eq)
|
|
185
|
+
return product_to_sum(eq)
|
|
186
|
+
|
|
187
|
+
def trig4(eq):
|
|
188
|
+
done = False
|
|
189
|
+
def _trig4(eq, numer=True, chance="sin"):
|
|
190
|
+
nonlocal done
|
|
191
|
+
if eq.name == "f_sin":
|
|
192
|
+
if eq.children[0].name == "f_add" and len(eq.children[0].children)>=2:
|
|
193
|
+
r = len(eq.children[0].children)%2
|
|
194
|
+
a, b = TreeNode("f_add", eq.children[0].children[:round((len(eq.children[0].children)-r)/2)]),\
|
|
195
|
+
TreeNode("f_add", eq.children[0].children[round((len(eq.children[0].children)-r)/2):])
|
|
196
|
+
if len(a.children)==1:
|
|
197
|
+
a=a.children[0]
|
|
198
|
+
if len(b.children)==1:
|
|
199
|
+
b=b.children[0]
|
|
200
|
+
return a.fx("sin")*b.fx("cos") + a.fx("cos")*b.fx("sin")
|
|
201
|
+
if eq.children[0].name == "f_arccos":
|
|
202
|
+
a = eq.children[0].children[0]
|
|
203
|
+
return (1-a**2)**(tree_form("d_2")**-1)
|
|
204
|
+
if eq.children[0].name == "f_arctan":
|
|
205
|
+
a = eq.children[0].children[0]
|
|
206
|
+
return a/(1+a**2)**(tree_form("d_2")**-1)
|
|
207
|
+
if eq.name == "f_pow" and numer:
|
|
208
|
+
if eq.children[0].name == "f_cos" and chance == "cos":
|
|
209
|
+
a = eq.children[0].children[0]
|
|
210
|
+
if frac(eq.children[1]) == 2:
|
|
211
|
+
done = True
|
|
212
|
+
return 1 - a.fx("sin")**2
|
|
213
|
+
if eq.children[0].name == "f_sin" and chance == "cos":
|
|
214
|
+
a = eq.children[0].children[0]
|
|
215
|
+
if frac(eq.children[1]) == 2:
|
|
216
|
+
done = True
|
|
217
|
+
return 1 - a.fx("cos")**2
|
|
218
|
+
if eq.name == "f_cos":
|
|
219
|
+
if eq.children[0].name == "f_add" and len(eq.children[0].children)>=2:
|
|
220
|
+
r = len(eq.children[0].children)%2
|
|
221
|
+
a, b = TreeNode("f_add", eq.children[0].children[:round((len(eq.children[0].children)-r)/2)]),\
|
|
222
|
+
TreeNode("f_add", eq.children[0].children[round((len(eq.children[0].children)-r)/2):])
|
|
223
|
+
if len(a.children)==1:
|
|
224
|
+
a=a.children[0]
|
|
225
|
+
if len(b.children)==1:
|
|
226
|
+
b=b.children[0]
|
|
227
|
+
return a.fx("cos")*b.fx("cos") - a.fx("sin")*b.fx("sin")
|
|
228
|
+
if eq.children[0].name == "f_arcsin":
|
|
229
|
+
a = eq.children[0].children[0]
|
|
230
|
+
return (1-a**2)**(tree_form("d_2")**-1)
|
|
231
|
+
if eq.children[0].name == "f_arctan":
|
|
232
|
+
a = eq.children[0].children[0]
|
|
233
|
+
return tree_form("d_1")/(1+a**2)**(tree_form("d_2")**-1)
|
|
234
|
+
|
|
235
|
+
return TreeNode(eq.name, [_trig4(child, False, chance) if eq.name != "f_add" and\
|
|
236
|
+
(not numer or (eq.name == "f_pow" and frac(eq.children[1]) is not None and frac(eq.children[1]) < 0))\
|
|
237
|
+
else _trig4(child, True, chance) for child in eq.children])
|
|
238
|
+
eq= _trig4(eq)
|
|
239
|
+
if not done:
|
|
240
|
+
eq = _trig4(eq,"cos")
|
|
241
|
+
return eq
|
|
202
242
|
def trig2(eq):
|
|
203
|
-
if
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
243
|
+
# Base case: if not an addition, recurse into children
|
|
244
|
+
if eq.name != "f_add":
|
|
245
|
+
return TreeNode(eq.name, [trig2(child) for child in eq.children])
|
|
246
|
+
|
|
247
|
+
# Try all pairs in the addition
|
|
248
|
+
for i, j in itertools.combinations(range(len(eq.children)), 2):
|
|
249
|
+
c1, c2 = eq.children[i], eq.children[j]
|
|
250
|
+
|
|
251
|
+
# Combine only sin/sin or cos/cos
|
|
252
|
+
if c1.name in ["f_sin", "f_cos"] and c2.name in ["f_sin", "f_cos"]:
|
|
253
|
+
A, B = c1.children[0], c2.children[0]
|
|
254
|
+
rest = [eq.children[k] for k in range(len(eq.children)) if k not in (i, j)]
|
|
255
|
+
rest_tree = summation(rest) if rest else tree_form("d_0")
|
|
256
|
+
|
|
257
|
+
two = tree_form("d_2")
|
|
258
|
+
|
|
259
|
+
# sinA + sinB
|
|
260
|
+
if c1.name == "f_sin" and c2.name == "f_sin":
|
|
261
|
+
combined = two * ((A + B) / two).fx("sin") * ((A - B) / two).fx("cos")
|
|
262
|
+
|
|
263
|
+
# cosA + cosB
|
|
264
|
+
elif c1.name == "f_cos" and c2.name == "f_cos":
|
|
265
|
+
combined = two * ((A + B) / two).fx("cos") * ((A - B) / two).fx("cos")
|
|
266
|
+
|
|
267
|
+
# sinA + cosB (leave unchanged)
|
|
268
|
+
else:
|
|
269
|
+
continue
|
|
270
|
+
|
|
271
|
+
new_expr = rest_tree + combined
|
|
272
|
+
# Re-run trig2 in case there are more sin/cos sums to simplify
|
|
273
|
+
return trig2(new_expr)
|
|
274
|
+
|
|
275
|
+
# If no sin/cos pairs found, just recurse on children
|
|
214
276
|
return TreeNode(eq.name, [trig2(child) for child in eq.children])
|
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
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mathai
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.6.9
|
|
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.
|
|
@@ -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=mk5LTVcgOpd-Zh0VBGQmZQOBlH5G3XFQI_TzwXYaRss,15794
|
|
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=NCe4LfM3-ndW78Zg8ZjlEVujb3-lG7_0H81ncRQizvw,2760
|
|
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=Owv7Xbn2emrSWqrvaqSHeWX5xPuQF5tkZICCuTbQAyQ,7288
|
|
16
|
+
mathai/ode.py,sha256=zxxTXAOpt7oSsfpgI4vHsCWKXevmM96ZOBZWWs-vj8Y,4801
|
|
17
|
+
mathai/parser.py,sha256=nEAdSSJeapBOhvjbkXJFtCEBU8izajXZAITV8rbslic,7314
|
|
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.6.9.dist-info/METADATA,sha256=6Q_imbUXwELM1E1VZap8NoO2fm9SFAhalIoi0nWsULg,7103
|
|
26
|
+
mathai-0.6.9.dist-info/WHEEL,sha256=qELbo2s1Yzl39ZmrAibXA2jjPLUYfnVhUNTlyF1rq0Y,92
|
|
27
|
+
mathai-0.6.9.dist-info/top_level.txt,sha256=ROP4l3OhGYw3ihkQGASr18xM9GsK4z3_6whV5AyXLwE,7
|
|
28
|
+
mathai-0.6.9.dist-info/RECORD,,
|