mathai 0.5.0__py3-none-any.whl → 0.5.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 +2 -0
- mathai/bivariate_inequality.py +32 -11
- mathai/factor.py +2 -1
- mathai/linear.py +20 -12
- mathai/matrix.py +22 -0
- mathai/simplify.py +6 -1
- mathai/univariate_inequality.py +9 -1
- {mathai-0.5.0.dist-info → mathai-0.5.2.dist-info}/METADATA +1 -1
- {mathai-0.5.0.dist-info → mathai-0.5.2.dist-info}/RECORD +11 -10
- {mathai-0.5.0.dist-info → mathai-0.5.2.dist-info}/WHEEL +0 -0
- {mathai-0.5.0.dist-info → mathai-0.5.2.dist-info}/top_level.txt +0 -0
mathai/__init__.py
CHANGED
mathai/bivariate_inequality.py
CHANGED
|
@@ -4,6 +4,9 @@ from functools import reduce
|
|
|
4
4
|
import operator
|
|
5
5
|
from .base import *
|
|
6
6
|
from .simplify import simplify
|
|
7
|
+
from .expand import expand
|
|
8
|
+
from .logic import logic0
|
|
9
|
+
|
|
7
10
|
def shoelace_area(vertices):
|
|
8
11
|
n = len(vertices)
|
|
9
12
|
area = 0.0
|
|
@@ -73,8 +76,6 @@ def deterministic_middle_point(vertices, grid_resolution=100):
|
|
|
73
76
|
return best_point
|
|
74
77
|
|
|
75
78
|
def build(eq):
|
|
76
|
-
if len(eq) <= 1:
|
|
77
|
-
return None
|
|
78
79
|
eq = TreeNode("f_or", eq)
|
|
79
80
|
eq = flatten_tree(eq)
|
|
80
81
|
orig = eq.copy_tree()
|
|
@@ -85,15 +86,21 @@ def build(eq):
|
|
|
85
86
|
eq = fxhelper3(eq)
|
|
86
87
|
|
|
87
88
|
result = linear_or(eq)
|
|
89
|
+
|
|
90
|
+
if result is None:
|
|
91
|
+
return None
|
|
92
|
+
|
|
88
93
|
maxnum = tree_form("d_2")
|
|
89
94
|
if len(result[1]) != 0:
|
|
90
95
|
maxnum = max([max([simplify(item2.fx("abs")) for item2 in item], key=lambda x: compute(x)) for item in result[1]], key=lambda x: compute(x))
|
|
91
96
|
maxnum += 1
|
|
92
97
|
maxnum = simplify(maxnum)
|
|
93
98
|
eq = flatten_tree(eq | simplify(TreeNode("f_or", [TreeNode("f_eq", [tree_form(item)+maxnum, tree_form("d_0")])|\
|
|
94
|
-
TreeNode("f_eq", [tree_form(item)-maxnum, tree_form("d_0")]) for item in
|
|
99
|
+
TreeNode("f_eq", [tree_form(item)-maxnum, tree_form("d_0")]) for item in ["v_0","v_1"]])))
|
|
95
100
|
result2 = linear_or(eq)
|
|
96
|
-
|
|
101
|
+
if result2 is None:
|
|
102
|
+
return None
|
|
103
|
+
|
|
97
104
|
point_lst = result2[2]
|
|
98
105
|
|
|
99
106
|
def gen(point):
|
|
@@ -175,6 +182,7 @@ def build(eq):
|
|
|
175
182
|
cycles.pop(i)
|
|
176
183
|
|
|
177
184
|
point_lst = [index for index, item in enumerate(result2[1]) if item in result[1]]
|
|
185
|
+
|
|
178
186
|
border = []
|
|
179
187
|
for item in start:
|
|
180
188
|
for item2 in graph[item]:
|
|
@@ -185,7 +193,9 @@ def build(eq):
|
|
|
185
193
|
continue
|
|
186
194
|
if a[1] == b[1] and simplify(a[1].fx("abs") - maxnum) == 0:
|
|
187
195
|
continue
|
|
196
|
+
|
|
188
197
|
border.append(tuple(sorted([item, item2])))
|
|
198
|
+
|
|
189
199
|
line = []
|
|
190
200
|
for key in graph.keys():
|
|
191
201
|
for item in list(set(point_lst)&set(graph[key])):
|
|
@@ -193,8 +203,6 @@ def build(eq):
|
|
|
193
203
|
line = list(set(line+border))
|
|
194
204
|
point_in = [deterministic_middle_point([[compute(item3) for item3 in result2[1][item2]] for item2 in item]) for item in cycles]
|
|
195
205
|
def work(eq, point):
|
|
196
|
-
if "f_eq" in str_form(eq):
|
|
197
|
-
return False
|
|
198
206
|
nonlocal result2
|
|
199
207
|
if eq.name[:2] == "d_":
|
|
200
208
|
return float(eq.name[2:])
|
|
@@ -204,12 +212,20 @@ def build(eq):
|
|
|
204
212
|
return sum(work(item, point) for item in eq.children)
|
|
205
213
|
if eq.name == "f_mul":
|
|
206
214
|
return math.prod(work(item, point) for item in eq.children)
|
|
207
|
-
|
|
215
|
+
if eq.name == "f_sub":
|
|
216
|
+
return work(eq.children[0], point) - work(eq.children[1], point)
|
|
217
|
+
return {"eq": lambda a,b: abs(a-b)<0.001, "gt":lambda a,b: False if abs(a-b)<0.001 else a>b, "lt":lambda a,b: False if abs(a-b)<0.001 else a<b}[eq.name[2:]](work(eq.children[0], point), work(eq.children[1], point))
|
|
208
218
|
|
|
209
219
|
data = []
|
|
210
220
|
for index, item in enumerate(result2[2][:-4]):
|
|
211
|
-
a = tuple(
|
|
212
|
-
|
|
221
|
+
a = tuple([item for item in point_lst if work(orig.children[index], [compute(item2) for item2 in result2[1][item]])])
|
|
222
|
+
#a = tuple(set(item) & set(point_lst))
|
|
223
|
+
#b = tuple(set([tuple(sorted([item[i], item[i+1]])) for i in range(len(item)-1)]) & set(line))
|
|
224
|
+
b = None
|
|
225
|
+
if orig.children[index] == "f_eq":
|
|
226
|
+
b = tuple([tuple(item) for item in line if work(orig.children[index], [compute(item2) for item2 in result2[1][item[1]]]) and work(orig.children[index], [compute(item2) for item2 in result2[1][item[0]]])])
|
|
227
|
+
else:
|
|
228
|
+
b = tuple([tuple(item) for item in line if work(orig.children[index], [compute(item2) for item2 in result2[1][item[1]]]) or work(orig.children[index], [compute(item2) for item2 in result2[1][item[0]]])])
|
|
213
229
|
c = tuple([tuple(item) for index2, item in enumerate(cycles) if work(orig.children[index], point_in[index2])])
|
|
214
230
|
data.append((a,b,c))
|
|
215
231
|
|
|
@@ -220,16 +236,19 @@ def build(eq):
|
|
|
220
236
|
return final, total, result2[1]
|
|
221
237
|
|
|
222
238
|
def inequality_solve(eq):
|
|
239
|
+
|
|
240
|
+
eq = logic0(eq)
|
|
223
241
|
element = []
|
|
224
242
|
def helper(eq):
|
|
225
243
|
nonlocal element
|
|
244
|
+
|
|
226
245
|
if eq.name[2:] in "le ge lt gt eq".split(" ") and "v_" in str_form(eq):
|
|
227
246
|
element.append(eq)
|
|
228
247
|
return TreeNode(eq.name, [helper(child) for child in eq.children])
|
|
229
248
|
helper(eq)
|
|
230
249
|
|
|
231
250
|
out = build(list(set(element)))
|
|
232
|
-
|
|
251
|
+
|
|
233
252
|
if out is None:
|
|
234
253
|
return eq
|
|
235
254
|
|
|
@@ -284,11 +303,13 @@ def inequality_solve(eq):
|
|
|
284
303
|
a,b,c= eq2
|
|
285
304
|
d,e,f= [set(item) for item in out[1]]
|
|
286
305
|
return [d-a,e-b,f-c]
|
|
306
|
+
return helper2(dowhile(eq, lambda x: logic0(expand(simplify(eq)))))
|
|
287
307
|
out2 = helper2(eq)
|
|
288
308
|
|
|
289
309
|
out = list(out)
|
|
290
310
|
out[1] = [set(item) for item in out[1]]
|
|
291
|
-
|
|
311
|
+
if tuple(out[1]) == (set(), set(), set()):
|
|
312
|
+
return eq
|
|
292
313
|
if tuple(out[1]) == tuple(out2):
|
|
293
314
|
return tree_form("s_true")
|
|
294
315
|
if tuple(out2) == (set(), set(), set()):
|
mathai/factor.py
CHANGED
|
@@ -171,7 +171,8 @@ def factor_quar_formula_init():
|
|
|
171
171
|
formula_gen9 = factor_quar_formula_init()
|
|
172
172
|
def factor_helper(equation, complexnum, power=2):
|
|
173
173
|
global formula_gen9
|
|
174
|
-
|
|
174
|
+
if equation.name in ["f_or", "f_and", "f_not", "f_eq", "f_gt", "f_lt", "f_ge", "f_le"]:
|
|
175
|
+
return TreeNode(equation.name, [factor_helper(child, complexnum, power) for child in equation.children])
|
|
175
176
|
maxnum=1
|
|
176
177
|
alloclst = []
|
|
177
178
|
for i in range(0,26):
|
mathai/linear.py
CHANGED
|
@@ -6,6 +6,7 @@ from .fraction import fraction
|
|
|
6
6
|
from .expand import expand
|
|
7
7
|
from .base import *
|
|
8
8
|
from .factor import factorconst
|
|
9
|
+
from .tool import poly
|
|
9
10
|
def ss(eq):
|
|
10
11
|
return dowhile(eq, lambda x: fraction(expand(simplify(x))))
|
|
11
12
|
def rref(matrix):
|
|
@@ -33,17 +34,16 @@ def rref(matrix):
|
|
|
33
34
|
return matrix
|
|
34
35
|
def islinear(eq, fxconst):
|
|
35
36
|
eq =simplify(eq)
|
|
36
|
-
if eq
|
|
37
|
-
return
|
|
38
|
-
|
|
39
|
-
out = islinear(child, fxconst)
|
|
40
|
-
if not out:
|
|
41
|
-
return out
|
|
42
|
-
return True
|
|
37
|
+
if all(fxconst(tree_form(item)) and poly(eq, item) is not None and len(poly(eq, item)) <= 2 for item in vlist(eq)):
|
|
38
|
+
return True
|
|
39
|
+
return False
|
|
43
40
|
def linear(eqlist, fxconst):
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
orig = [item.copy_tree() for item in eqlist]
|
|
42
|
+
#eqlist = [eq for eq in eqlist if fxconst(eq)]
|
|
43
|
+
|
|
44
|
+
if eqlist == [] or not all(islinear(eq, fxconst) for eq in eqlist):
|
|
45
|
+
return None
|
|
46
|
+
#return TreeNode("f_and", [TreeNode("f_eq", [x, tree_form("d_0")]) for x in orig])
|
|
47
47
|
vl = []
|
|
48
48
|
def varlist(eq, fxconst):
|
|
49
49
|
nonlocal vl
|
|
@@ -111,7 +111,6 @@ def order_collinear_indices(points, idx):
|
|
|
111
111
|
sorted_idx = sorted(idx, key=projection_factor)
|
|
112
112
|
return list(sorted_idx)
|
|
113
113
|
def linear_or(eq):
|
|
114
|
-
eq = simplify(eq)
|
|
115
114
|
eqlst =[]
|
|
116
115
|
if eq.name != "f_or":
|
|
117
116
|
eqlst = [eq]
|
|
@@ -125,8 +124,13 @@ def linear_or(eq):
|
|
|
125
124
|
for item in itertools.combinations(enumerate(eqlst), 2):
|
|
126
125
|
x, y = item[0][0], item[1][0]
|
|
127
126
|
item = [item[0][1], item[1][1]]
|
|
127
|
+
|
|
128
128
|
out = linear_solve(TreeNode("f_and", list(item)))
|
|
129
|
-
|
|
129
|
+
|
|
130
|
+
if out is None:
|
|
131
|
+
return None
|
|
132
|
+
|
|
133
|
+
if out.name == "f_and" and all(len(vlist(child)) == 1 for child in out.children) and set(vlist(out)) == set(v) and all(len(vlist(simplify(child))) >0 for child in out.children):
|
|
130
134
|
t = {}
|
|
131
135
|
for child in out.children:
|
|
132
136
|
t[v.index(vlist(child)[0])] = simplify(inverse(child.children[0], vlist(child)[0]))
|
|
@@ -141,11 +145,13 @@ def linear_or(eq):
|
|
|
141
145
|
line2 = []
|
|
142
146
|
for key in sorted(line.keys()):
|
|
143
147
|
line2.append(order_collinear_indices(p, list(set(line[key]))))
|
|
148
|
+
|
|
144
149
|
return v, p, line2, eqlst
|
|
145
150
|
def linear_solve(eq, lst=None):
|
|
146
151
|
eq = simplify(eq)
|
|
147
152
|
eqlist = []
|
|
148
153
|
if eq.name =="f_and" and all(child.name == "f_eq" and child.children[1] == 0 for child in eq.children):
|
|
154
|
+
|
|
149
155
|
eqlist = [child.children[0] for child in eq.children]
|
|
150
156
|
else:
|
|
151
157
|
return eq
|
|
@@ -154,4 +160,6 @@ def linear_solve(eq, lst=None):
|
|
|
154
160
|
out = linear(copy.deepcopy(eqlist), lambda x: "v_" in str_form(x))
|
|
155
161
|
else:
|
|
156
162
|
out = linear(copy.deepcopy(eqlist), lambda x: any(contain(x, item) for item in lst))
|
|
163
|
+
if out is None:
|
|
164
|
+
return None
|
|
157
165
|
return simplify(out)
|
mathai/matrix.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
def uncommute(eq, inside=False):
|
|
2
|
+
if not inside and eq.name in ["f_add", "f_mul"]:
|
|
3
|
+
return TreeNode(eq.name[:2]+"w"+eq.name[2:], [uncommute(child) for child in eq.children])
|
|
4
|
+
return TreeNode(eq.name, [uncommute(child, True) if eq.name == "f_list" else uncommute(child, inside) for child in eq.children])
|
|
5
|
+
|
|
6
|
+
def matrix_solve(eq):
|
|
7
|
+
if eq.name == "f_wadd":
|
|
8
|
+
output = None
|
|
9
|
+
output2 = []
|
|
10
|
+
for child in eq.children:
|
|
11
|
+
if child.name == "f_list":
|
|
12
|
+
if output is None:
|
|
13
|
+
output = []
|
|
14
|
+
for i in range(len(child.children)):
|
|
15
|
+
output.append([child.children[i]])
|
|
16
|
+
else:
|
|
17
|
+
for i in range(len(child.children)):
|
|
18
|
+
output[i] += [child.children[i]]
|
|
19
|
+
output.append(child)
|
|
20
|
+
else:
|
|
21
|
+
output2.append(child)
|
|
22
|
+
output = [summation(item) for item in output]
|
mathai/simplify.py
CHANGED
|
@@ -159,7 +159,12 @@ def clear_div(eq, denom=False):
|
|
|
159
159
|
if len(lst3) % 2 == 1:
|
|
160
160
|
sign = False
|
|
161
161
|
if denom:
|
|
162
|
-
|
|
162
|
+
eq2 = [item for item in lst if "v_" not in str_form(item)]
|
|
163
|
+
eq3 = [item for item in lst if "v_" in str_form(item)]
|
|
164
|
+
if eq3 == []:
|
|
165
|
+
return solve(product(eq2)),True
|
|
166
|
+
return solve(product(eq3)),sign
|
|
167
|
+
#return eq if sign else -eq, sign
|
|
163
168
|
lst = [item for item in lst if not(item.name == "f_pow" and frac(item.children[1]) is not None and frac(item.children[1]) == -1)]
|
|
164
169
|
|
|
165
170
|
lst2 = [item for item in lst if "v_" in str_form(item)]
|
mathai/univariate_inequality.py
CHANGED
|
@@ -361,7 +361,9 @@ def absolute(equation):
|
|
|
361
361
|
equation = TreeNode("f_or", out2)
|
|
362
362
|
return equation
|
|
363
363
|
def handle_sqrt(eq):
|
|
364
|
+
d= []
|
|
364
365
|
def helper2(eq):
|
|
366
|
+
nonlocal d
|
|
365
367
|
if eq.name in ["f_lt", "f_gt", "f_le", "f_ge","f_eq"]:
|
|
366
368
|
out = []
|
|
367
369
|
def helper(eq):
|
|
@@ -378,11 +380,17 @@ def handle_sqrt(eq):
|
|
|
378
380
|
eq2, sgn = inverse(simplify(eq.children[0]), str_form(item), True)
|
|
379
381
|
if sgn == False:
|
|
380
382
|
n = tree_form("d_-1")
|
|
383
|
+
d.append(TreeNode("f_ge", [eq2,tree_form("d_0")]))
|
|
384
|
+
#d.append(TreeNode("f_ge", [item.children[0],tree_form("d_0")]))
|
|
381
385
|
eq3 = simplify(expand(simplify(eq2**2)))
|
|
382
386
|
|
|
383
387
|
return simplify(TreeNode(eq.name, [simplify(n*item.children[0]-eq3*n), tree_form("d_0")]))
|
|
388
|
+
|
|
384
389
|
return TreeNode(eq.name, [helper2(child) for child in eq.children])
|
|
385
|
-
|
|
390
|
+
out = helper2(eq)
|
|
391
|
+
if len(d) == 0:
|
|
392
|
+
return out
|
|
393
|
+
return TreeNode("f_and", [helper2(eq)]+d)
|
|
386
394
|
def domain(eq):
|
|
387
395
|
eq = solve(eq, True)
|
|
388
396
|
out = []
|
|
@@ -1,26 +1,27 @@
|
|
|
1
|
-
mathai/__init__.py,sha256=
|
|
1
|
+
mathai/__init__.py,sha256=GciRnhsCDfd_xjC2VoDWVmbapNtR4YlVGEa4ibJi32w,1514
|
|
2
2
|
mathai/apart.py,sha256=VSS3khE9PNuxiRvdU5JDl4IN-KJBSIFjwR17pkhviXI,4197
|
|
3
3
|
mathai/base.py,sha256=Ma1oCRbaZP0bp0Qnt_ZjKAh3rt9nZXQ_rmJL0sAoz5c,12730
|
|
4
|
-
mathai/bivariate_inequality.py,sha256=
|
|
4
|
+
mathai/bivariate_inequality.py,sha256=FJOC2zKU5zWCMybCrhEQ7nVDgRO_w19Zko8WPTaDTSo,11411
|
|
5
5
|
mathai/console.py,sha256=Sn58iwYE79MLEh67s8X3q6vZjw6g7f9XM1T8_dBBR2o,3048
|
|
6
6
|
mathai/diff.py,sha256=YUBpRsz0qmBkq5vGxeGnvR4nMKjdOQiIXlNMxpij2ns,3051
|
|
7
7
|
mathai/expand.py,sha256=SnBltkpIENMGkP0AYmbMlSc4H-CF5RslO2PcBEkn1BQ,3359
|
|
8
|
-
mathai/factor.py,sha256=
|
|
8
|
+
mathai/factor.py,sha256=muPDOcClrqc2XyVlbyIrhiIqI0QxauYL3e2mq3qa6OI,11533
|
|
9
9
|
mathai/fraction.py,sha256=Q2ztsh5Bpz6YhML2QU0tfufbAs0Q6J319AhlzKephIY,4396
|
|
10
10
|
mathai/integrate.py,sha256=ewV46QDD0-oiTWpSkmcpcZhBz9StcntbTV1tBLCo1Wo,16502
|
|
11
11
|
mathai/inverse.py,sha256=QCvDrzKquWsZv-BDAzZd9HnU0c3gZvcc44UztHVO5LQ,2919
|
|
12
12
|
mathai/limit.py,sha256=bn7eofIOJv4AIh0-FmLppZ3DKnGfbwOzXks2XOPTOs0,4932
|
|
13
|
-
mathai/linear.py,sha256=
|
|
13
|
+
mathai/linear.py,sha256=Mmmnn4IdnADRMuv6crB0a_Ba2drGUFXOh7eqIIkirYA,5709
|
|
14
14
|
mathai/logic.py,sha256=UvHzRmKcO9AD51tRzHmpNSEhgW5gmaf4XPaQKFjGfC4,9653
|
|
15
|
+
mathai/matrix.py,sha256=dWIXF5oInIL3SZ3naRzKN5ElI5drXJNiVTDM48hfZOw,972
|
|
15
16
|
mathai/ode.py,sha256=zxxTXAOpt7oSsfpgI4vHsCWKXevmM96ZOBZWWs-vj8Y,4801
|
|
16
17
|
mathai/parser.py,sha256=f7bemieFmp0sbup1NlraMLvZDVFvqKGFknEVtlFRMVk,6979
|
|
17
18
|
mathai/printeq.py,sha256=gIes-pstFOa6FcnpVIVvkjVKuWdsVdo11LlEnmHhakU,1303
|
|
18
|
-
mathai/simplify.py,sha256=
|
|
19
|
+
mathai/simplify.py,sha256=EGyEld0ZpOuHLeMmOKhvv0rTejEWjfkwkNJQx3lHSQc,17127
|
|
19
20
|
mathai/structure.py,sha256=4Ww2IAx62RcQSO7_17TZES-DjMWBpcFQtL939FBIHwY,4103
|
|
20
21
|
mathai/tool.py,sha256=r8ejBY4Bnk_t8USYQCuxwmmJ4M-5H5OR6A3VbV7W-5w,6066
|
|
21
22
|
mathai/trig.py,sha256=BQd_Gl_u0g5ZuZIwKozuXKbMinqb6K-OYicrtftn7eg,11174
|
|
22
|
-
mathai/univariate_inequality.py,sha256=
|
|
23
|
-
mathai-0.5.
|
|
24
|
-
mathai-0.5.
|
|
25
|
-
mathai-0.5.
|
|
26
|
-
mathai-0.5.
|
|
23
|
+
mathai/univariate_inequality.py,sha256=3Yr7d9mE-mUNkwOPQyFPBDp0-gKkqrpzEYeHFQ8JcXA,15060
|
|
24
|
+
mathai-0.5.2.dist-info/METADATA,sha256=sjO-RkjnEu_-D6ahvZq-z_Ad0ZX9GSkM1qZICMmPcmg,7103
|
|
25
|
+
mathai-0.5.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
26
|
+
mathai-0.5.2.dist-info/top_level.txt,sha256=ROP4l3OhGYw3ihkQGASr18xM9GsK4z3_6whV5AyXLwE,7
|
|
27
|
+
mathai-0.5.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|