mathai 0.4.6__tar.gz → 0.4.7__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.6 → mathai-0.4.7}/PKG-INFO +1 -1
- {mathai-0.4.6 → mathai-0.4.7}/mathai/__init__.py +2 -0
- {mathai-0.4.6 → mathai-0.4.7}/mathai/factor.py +84 -30
- {mathai-0.4.6 → mathai-0.4.7}/mathai/simplify.py +3 -1
- {mathai-0.4.6 → mathai-0.4.7}/mathai/tool.py +7 -2
- {mathai-0.4.6 → mathai-0.4.7}/mathai/trig.py +56 -46
- {mathai-0.4.6 → mathai-0.4.7}/mathai.egg-info/PKG-INFO +1 -1
- {mathai-0.4.6 → mathai-0.4.7}/setup.py +1 -1
- {mathai-0.4.6 → mathai-0.4.7}/README.md +0 -0
- {mathai-0.4.6 → mathai-0.4.7}/mathai/apart.py +0 -0
- {mathai-0.4.6 → mathai-0.4.7}/mathai/base.py +0 -0
- {mathai-0.4.6 → mathai-0.4.7}/mathai/console.py +0 -0
- {mathai-0.4.6 → mathai-0.4.7}/mathai/diff.py +0 -0
- {mathai-0.4.6 → mathai-0.4.7}/mathai/expand.py +0 -0
- {mathai-0.4.6 → mathai-0.4.7}/mathai/fraction.py +0 -0
- {mathai-0.4.6 → mathai-0.4.7}/mathai/integrate.py +0 -0
- {mathai-0.4.6 → mathai-0.4.7}/mathai/inverse.py +0 -0
- {mathai-0.4.6 → mathai-0.4.7}/mathai/limit.py +0 -0
- {mathai-0.4.6 → mathai-0.4.7}/mathai/linear.py +0 -0
- {mathai-0.4.6 → mathai-0.4.7}/mathai/logic.py +0 -0
- {mathai-0.4.6 → mathai-0.4.7}/mathai/ode.py +0 -0
- {mathai-0.4.6 → mathai-0.4.7}/mathai/parser.py +0 -0
- {mathai-0.4.6 → mathai-0.4.7}/mathai/printeq.py +0 -0
- {mathai-0.4.6 → mathai-0.4.7}/mathai/structure.py +0 -0
- {mathai-0.4.6 → mathai-0.4.7}/mathai/univariate_inequality.py +0 -0
- {mathai-0.4.6 → mathai-0.4.7}/mathai.egg-info/SOURCES.txt +0 -0
- {mathai-0.4.6 → mathai-0.4.7}/mathai.egg-info/dependency_links.txt +0 -0
- {mathai-0.4.6 → mathai-0.4.7}/mathai.egg-info/requires.txt +0 -0
- {mathai-0.4.6 → mathai-0.4.7}/mathai.egg-info/top_level.txt +0 -0
- {mathai-0.4.6 → mathai-0.4.7}/setup.cfg +0 -0
|
@@ -5,6 +5,7 @@ from .base import *
|
|
|
5
5
|
from .simplify import simplify,solve
|
|
6
6
|
from .expand import expand
|
|
7
7
|
import math
|
|
8
|
+
from .tool import poly
|
|
8
9
|
|
|
9
10
|
from collections import Counter
|
|
10
11
|
def multiset_intersection(*lists):
|
|
@@ -158,12 +159,6 @@ def rationalize_sqrt(eq):
|
|
|
158
159
|
return TreeNode(eq.name, [rationalize_sqrt(child) for child in eq.children])
|
|
159
160
|
def factorconst(eq):
|
|
160
161
|
return simplify(_factorconst(eq))
|
|
161
|
-
def factor_quad_formula_init():
|
|
162
|
-
var = ""
|
|
163
|
-
formula_list = [(f"(A*D^2+B*D+C)", f"A*(D-(-B+(B^2-4*A*C)^(1/2))/(2*A))*(D-(-B-(B^2-4*A*C)^(1/2))/(2*A))")]
|
|
164
|
-
formula_list = [[simplify(parse(y)) for y in x] for x in formula_list]
|
|
165
|
-
expr = [[parse("A"), parse("1")], [parse("B"), parse("0"), parse("1")], [parse("C"), parse("0")]]
|
|
166
|
-
return [formula_list, var, expr]
|
|
167
162
|
|
|
168
163
|
def factor_quar_formula_init():
|
|
169
164
|
var = ""
|
|
@@ -171,44 +166,103 @@ def factor_quar_formula_init():
|
|
|
171
166
|
formula_list = [[simplify(parse(y)) for y in x] for x in formula_list]
|
|
172
167
|
expr = [[parse("A")], [parse("B"), parse("0"), parse("1")], [parse("C"), parse("0")]]
|
|
173
168
|
return [formula_list, var, expr]
|
|
174
|
-
|
|
175
|
-
var = ""
|
|
176
|
-
formula_list = [(f"D^3+E", f"(D+E^(1/3))*(D^2-D*E^(1/3)+E^(2/3))"), (f"D^3-E", f"(D-E^(1/3))*(D^2+D*E^(1/3)+E^(2/3))"),\
|
|
177
|
-
(f"-D^3+E", f"(-D+E^(1/3))*(D^2+D*E^(1/3)+E^(2/3))")]
|
|
178
|
-
formula_list = [[simplify(parse(y)) for y in x] for x in formula_list]
|
|
179
|
-
expr = [[parse("A")], [parse("B")]]
|
|
180
|
-
return [formula_list, var, expr]
|
|
181
|
-
formula_gen2 = factor_quad_formula_init()
|
|
182
|
-
formula_gen3 = factor_cube_formula_init()
|
|
169
|
+
|
|
183
170
|
formula_gen9 = factor_quar_formula_init()
|
|
184
171
|
def factor_helper(equation, complexnum, power=2):
|
|
185
|
-
global
|
|
186
|
-
|
|
172
|
+
global formula_gen9
|
|
173
|
+
|
|
174
|
+
maxnum=1
|
|
175
|
+
alloclst = []
|
|
176
|
+
for i in range(0,26):
|
|
177
|
+
if "v_"+str(i) not in vlist(equation):
|
|
178
|
+
alloclst.append("v_"+str(i))
|
|
179
|
+
r = alloclst.pop(0)
|
|
180
|
+
fx = None
|
|
181
|
+
curr = None
|
|
187
182
|
def high(eq):
|
|
188
183
|
nonlocal maxnum
|
|
189
184
|
if eq.name == "f_pow" and eq.children[1].name[:2] == "d_":
|
|
190
185
|
n = int(eq.children[1].name[2:])
|
|
191
|
-
if n>power and n % power == 0:
|
|
192
|
-
|
|
186
|
+
if abs(n)>power and abs(n) % power == 0:
|
|
187
|
+
if abs(n)>abs(maxnum):
|
|
188
|
+
maxnum = n
|
|
193
189
|
for child in eq.children:
|
|
194
190
|
high(child)
|
|
195
191
|
def helper(eq):
|
|
196
|
-
nonlocal maxnum
|
|
192
|
+
nonlocal maxnum, fx, r
|
|
197
193
|
if eq.name == "f_pow" and eq.children[1].name[:2] == "d_":
|
|
198
194
|
n = int(eq.children[1].name[2:])
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
out= (eq.children[0]**tree_form("d_"+str(sgn*int(n/power))))**power
|
|
195
|
+
if maxnum !=1 and n % maxnum == 0:
|
|
196
|
+
fx = lambda x: replace(x, tree_form(r), curr**tree_form("d_"+str(maxnum)))
|
|
197
|
+
out= tree_form(r)**tree_form("d_"+str(int(n/maxnum)))
|
|
203
198
|
return out
|
|
204
199
|
return TreeNode(eq.name, [helper(child) for child in eq.children])
|
|
205
|
-
high(equation)
|
|
206
200
|
out = None
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
201
|
+
for i in range(2,4):
|
|
202
|
+
if power == i:
|
|
203
|
+
for curr in vlist(equation):
|
|
204
|
+
curr = tree_form(curr)
|
|
205
|
+
fx = None
|
|
206
|
+
maxnum = 1
|
|
207
|
+
high(equation)
|
|
208
|
+
|
|
209
|
+
if maxnum != 1:
|
|
210
|
+
maxnum= maxnum/power
|
|
211
|
+
maxnum = round(maxnum)
|
|
212
|
+
eq2 = helper(equation)
|
|
213
|
+
if not contain(eq2, tree_form(r)) or (contain(eq2, tree_form(r)) and not contain(eq2,curr)):
|
|
214
|
+
if not contain(eq2, tree_form(r)):
|
|
215
|
+
r = curr.name
|
|
216
|
+
fx = lambda x: x
|
|
217
|
+
|
|
218
|
+
lst = poly(eq2.copy_tree(), r)
|
|
219
|
+
if lst is not None and len(lst)==i+1:
|
|
220
|
+
|
|
221
|
+
success = True
|
|
222
|
+
if i == 2:
|
|
223
|
+
a, b, c = lst
|
|
224
|
+
x1 = (-b+(b**2 - 4*a*c)**(tree_form("d_2")**-1))/(2*a)
|
|
225
|
+
x2 = (-b-(b**2 - 4*a*c)**(tree_form("d_2")**-1))/(2*a)
|
|
226
|
+
x1 = simplify(x1)
|
|
227
|
+
x2 = simplify(x2)
|
|
228
|
+
eq2 = a*(tree_form(r)-x1)*(tree_form(r)-x2)
|
|
229
|
+
if not complexnum and (contain(x1, tree_form("s_i")) or contain(x2, tree_form("s_i"))):
|
|
230
|
+
success = False
|
|
231
|
+
else:
|
|
232
|
+
a, b, c, d = lst
|
|
233
|
+
B, C, D = b/a, c/a, d/a
|
|
234
|
+
p = C-(B**2)/3
|
|
235
|
+
q = 2*B**3/27-B*C/3+D
|
|
236
|
+
t = q**2/4+ p**3/27
|
|
237
|
+
u = (-q/2+t**(tree_form("d_2")**-1))**(tree_form("d_3")**-1)
|
|
238
|
+
v = (-q/2-t**(tree_form("d_2")**-1))**(tree_form("d_3")**-1)
|
|
239
|
+
y1 = u+v
|
|
240
|
+
three = 3**(tree_form("d_2")**-1)
|
|
241
|
+
y2 = -(u+v)/2+tree_form("s_i")*three*(u-v)/2
|
|
242
|
+
y3 = -(u+v)/2-tree_form("s_i")*three*(u-v)/2
|
|
243
|
+
x1,x2,x3 = y1-B/3 , y2-B/3, y3-B/3
|
|
244
|
+
x1,x2, x3 = simplify(x1), simplify(x2), simplify(x3)
|
|
245
|
+
out2 = None
|
|
246
|
+
if not complexnum:
|
|
247
|
+
for item in itertools.combinations([x1,x2,x3],2):
|
|
248
|
+
if all(contain(item2,tree_form("s_i")) for item2 in list(item)):
|
|
249
|
+
out2 = (tree_form(r)-item[0])*(tree_form(r)-item[1])
|
|
250
|
+
break
|
|
251
|
+
if out2 is not None:
|
|
252
|
+
out2 = simplify(expand(simplify(out2)))
|
|
253
|
+
out3 = None
|
|
254
|
+
for item in [x1, x2, x3]:
|
|
255
|
+
if not contain(item,tree_form("s_i")):
|
|
256
|
+
out3 = item
|
|
257
|
+
break
|
|
258
|
+
eq2 = a*(tree_form(r)-out3)*out2
|
|
259
|
+
|
|
260
|
+
else:
|
|
261
|
+
eq2 = a*(tree_form(r)-x1)*(tree_form(r)-x2)*(tree_form(r)-x3)
|
|
262
|
+
if success:
|
|
263
|
+
equation = fx(eq2)
|
|
264
|
+
break
|
|
265
|
+
if power == 4:
|
|
212
266
|
out = transform_formula(helper(equation), "v_0", formula_gen9[0], formula_gen9[1], formula_gen9[2])
|
|
213
267
|
if out is not None:
|
|
214
268
|
out = simplify(solve(out))
|
|
@@ -287,7 +287,9 @@ def simplify(eq):
|
|
|
287
287
|
error = True
|
|
288
288
|
else:
|
|
289
289
|
eq = tree_form("d_0")
|
|
290
|
-
|
|
290
|
+
if eq.name =="f_pow" and eq.children[0] == tree_form("s_i") and frac(eq.children[1])is not None and frac(eq.children[1]).denominator == 1:
|
|
291
|
+
n = frac(eq.children[1]).numerator
|
|
292
|
+
eq = {0:tree_form("d_1"), 1:tree_form("s_i"), 2:tree_form("d_-1"), 3:-tree_form("s_i")}[n%4]
|
|
291
293
|
if eq.name == "f_mul":
|
|
292
294
|
dic = {}
|
|
293
295
|
for child in eq.children:
|
|
@@ -36,7 +36,12 @@ def poly(eq, to_compute):
|
|
|
36
36
|
eq = replace(eq, tree_form(var), tree_form("d_"+str(val)))
|
|
37
37
|
return eq
|
|
38
38
|
def inv(eq):
|
|
39
|
-
if eq.name ==
|
|
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):
|
|
40
45
|
return False
|
|
41
46
|
if eq.name == "f_abs":
|
|
42
47
|
return False
|
|
@@ -47,7 +52,7 @@ def poly(eq, to_compute):
|
|
|
47
52
|
return None
|
|
48
53
|
out = []
|
|
49
54
|
eq2 = eq
|
|
50
|
-
for i in range(
|
|
55
|
+
for i in range(8):
|
|
51
56
|
out.append(expand(simplify(eq2)))
|
|
52
57
|
eq2 = diff(eq2, to_compute)
|
|
53
58
|
for i in range(len(out)-1,-1,-1):
|
|
@@ -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")
|
|
@@ -164,52 +167,59 @@ def _trig1(equation):
|
|
|
164
167
|
return TreeNode(equation.name, [_trig1(child) for child in equation.children])
|
|
165
168
|
def trig1(eq):
|
|
166
169
|
return simplify(_trig1(noneg_pow(eq)))
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
if
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
if len(
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
170
|
+
def trig4(eq):
|
|
171
|
+
done = False
|
|
172
|
+
def _trig4(eq, numer=True, chance="sin"):
|
|
173
|
+
nonlocal done
|
|
174
|
+
if eq.name == "f_sin":
|
|
175
|
+
if eq.children[0].name == "f_add" and len(eq.children[0].children)>=2:
|
|
176
|
+
r = len(eq.children[0].children)%2
|
|
177
|
+
a, b = TreeNode("f_add", eq.children[0].children[:round((len(eq.children[0].children)-r)/2)]),\
|
|
178
|
+
TreeNode("f_add", eq.children[0].children[round((len(eq.children[0].children)-r)/2):])
|
|
179
|
+
if len(a.children)==1:
|
|
180
|
+
a=a.children[0]
|
|
181
|
+
if len(b.children)==1:
|
|
182
|
+
b=b.children[0]
|
|
183
|
+
return a.fx("sin")*b.fx("cos") + a.fx("cos")*b.fx("sin")
|
|
184
|
+
if eq.children[0].name == "f_arccos":
|
|
185
|
+
a = eq.children[0].children[0]
|
|
186
|
+
return (1-a**2)**(tree_form("d_2")**-1)
|
|
187
|
+
if eq.children[0].name == "f_arctan":
|
|
188
|
+
a = eq.children[0].children[0]
|
|
189
|
+
return a/(1+a**2)**(tree_form("d_2")**-1)
|
|
190
|
+
if eq.name == "f_pow" and numer:
|
|
191
|
+
if eq.children[0].name == "f_cos" and chance == "cos":
|
|
192
|
+
a = eq.children[0].children[0]
|
|
193
|
+
if frac(eq.children[1]) == 2:
|
|
194
|
+
done = True
|
|
195
|
+
return 1 - a.fx("sin")**2
|
|
196
|
+
if eq.children[0].name == "f_sin" and chance == "cos":
|
|
197
|
+
a = eq.children[0].children[0]
|
|
198
|
+
if frac(eq.children[1]) == 2:
|
|
199
|
+
done = True
|
|
200
|
+
return 1 - a.fx("cos")**2
|
|
201
|
+
if eq.name == "f_cos":
|
|
202
|
+
if eq.children[0].name == "f_add" and len(eq.children[0].children)>=2:
|
|
203
|
+
r = len(eq.children[0].children)%2
|
|
204
|
+
a, b = TreeNode("f_add", eq.children[0].children[:round((len(eq.children[0].children)-r)/2)]),\
|
|
205
|
+
TreeNode("f_add", eq.children[0].children[round((len(eq.children[0].children)-r)/2):])
|
|
206
|
+
if len(a.children)==1:
|
|
207
|
+
a=a.children[0]
|
|
208
|
+
if len(b.children)==1:
|
|
209
|
+
b=b.children[0]
|
|
210
|
+
return a.fx("cos")*b.fx("cos") - a.fx("sin")*b.fx("sin")
|
|
211
|
+
if eq.children[0].name == "f_arcsin":
|
|
212
|
+
a = eq.children[0].children[0]
|
|
213
|
+
return (1-a**2)**(tree_form("d_2")**-1)
|
|
214
|
+
if eq.children[0].name == "f_arctan":
|
|
215
|
+
a = eq.children[0].children[0]
|
|
216
|
+
return tree_form("d_1")/(1+a**2)**(tree_form("d_2")**-1)
|
|
217
|
+
|
|
218
|
+
return TreeNode(eq.name, [_trig4(child, False, chance) if not numer or (eq.name == "f_pow" and frac(eq.children[1]) is not None and frac(eq.children[1]) < 0) else _trig4(child, True, chance) for child in eq.children])
|
|
219
|
+
eq= _trig4(eq)
|
|
220
|
+
if not done:
|
|
221
|
+
eq = _trig4(eq,"cos")
|
|
222
|
+
return eq
|
|
213
223
|
def trig2(eq):
|
|
214
224
|
# Base case: if not an addition, recurse into children
|
|
215
225
|
if eq.name != "f_add":
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|