mathai 0.4.8__py3-none-any.whl → 0.4.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 +0 -2
- mathai/base.py +3 -1
- mathai/factor.py +2 -1
- mathai/parser.py +29 -14
- mathai/tool.py +1 -0
- mathai/univariate_inequality.py +76 -11
- {mathai-0.4.8.dist-info → mathai-0.4.9.dist-info}/METADATA +1 -1
- {mathai-0.4.8.dist-info → mathai-0.4.9.dist-info}/RECORD +10 -11
- mathai/console.py +0 -84
- {mathai-0.4.8.dist-info → mathai-0.4.9.dist-info}/WHEEL +0 -0
- {mathai-0.4.8.dist-info → mathai-0.4.9.dist-info}/top_level.txt +0 -0
mathai/__init__.py
CHANGED
mathai/base.py
CHANGED
|
@@ -204,9 +204,11 @@ def compute(eq):
|
|
|
204
204
|
|
|
205
205
|
# Recursive case: compute child values
|
|
206
206
|
values = [compute(child) for child in eq.children]
|
|
207
|
+
|
|
208
|
+
|
|
207
209
|
if None in values:
|
|
208
210
|
return None
|
|
209
|
-
|
|
211
|
+
|
|
210
212
|
if eq.name == "f_add":
|
|
211
213
|
return sum(values)
|
|
212
214
|
elif eq.name == "f_sub":
|
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[2:] in "and or not eq le ge lt gt".split(" "):
|
|
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/parser.py
CHANGED
|
@@ -73,15 +73,9 @@ CNUMBER: /c[0-9]+/
|
|
|
73
73
|
%ignore WS_INLINE
|
|
74
74
|
"""
|
|
75
75
|
|
|
76
|
-
def parse(equation
|
|
76
|
+
def parse(equation):
|
|
77
77
|
equation = copy.copy(equation.replace(" ", ""))
|
|
78
78
|
grammar2 = copy.deepcopy(grammar)
|
|
79
|
-
if funclist is not None:
|
|
80
|
-
output = grammar2.split("\n")
|
|
81
|
-
for i in range(len(output)):
|
|
82
|
-
if "FUNC_NAME:" in output[i]:
|
|
83
|
-
output[i] = output[i].replace("FUNC_NAME: ", "FUNC_NAME: " + " | ".join(['"' + x + '"' for x in funclist]) + " | ")
|
|
84
|
-
grammar2 = "\n".join(output)
|
|
85
79
|
|
|
86
80
|
parser_main = Lark(grammar2, start='start', parser='lalr')
|
|
87
81
|
parse_tree = parser_main.parse(equation)
|
|
@@ -118,21 +112,42 @@ def parse(equation, funclist=None):
|
|
|
118
112
|
|
|
119
113
|
# Convert function names and constants
|
|
120
114
|
def fxchange(tree_node):
|
|
121
|
-
tmp3 =
|
|
115
|
+
tmp3 = []
|
|
116
|
+
|
|
117
|
+
# Handle negation
|
|
122
118
|
if tree_node.name == "neg":
|
|
123
119
|
child = fxchange(tree_node.children[0])
|
|
124
|
-
# if the child is a number, make it negative
|
|
125
120
|
if child.name.startswith("d_") and re.match(r"d_\d+(\.\d+)?$", child.name):
|
|
126
121
|
return TreeNode("d_" + str(-int(child.name[2:])))
|
|
127
122
|
else:
|
|
128
|
-
# otherwise subtract from zero
|
|
129
123
|
return TreeNode("f_sub", [tree_form("d_0"), child])
|
|
124
|
+
|
|
125
|
+
# Pass through node
|
|
130
126
|
if tree_node.name == "pass_through":
|
|
131
127
|
return fxchange(tree_node.children[0])
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
128
|
+
|
|
129
|
+
# Define function name categories
|
|
130
|
+
builtin_funcs = tmp3 + [
|
|
131
|
+
"try","ref","sqrt","imply","forall","exist","exclude","union","intersection","len",
|
|
132
|
+
"index","angle","charge","sum2","electricfield","line","point","sum","transpose",
|
|
133
|
+
"equationrhs","equationlhs","equation","covariance","variance","expect","error",
|
|
134
|
+
"laplace","dot","curl","pdif","diverge","gradient","rad","ge","le","gt","lt",
|
|
135
|
+
"eqtri","linesegment","midpoint","mag","point1","point2","point3","line1","line2",
|
|
136
|
+
"line3","log10","arcsin","arccos","arctan","list","cosec","sec","cot","equiv",
|
|
137
|
+
"or","not","and","circumcenter","eq","sub","add","sin","cos","tan","mul",
|
|
138
|
+
"integrate","dif","pow","div","log","abs"
|
|
139
|
+
]
|
|
140
|
+
|
|
141
|
+
# --- NEW: detect F + digits ---
|
|
142
|
+
if re.match(r"F\d+$", tree_node.name):
|
|
143
|
+
new_name = "f_" + tree_node.name # e.g., F12 → f_F12
|
|
144
|
+
elif tree_node.name in builtin_funcs:
|
|
145
|
+
new_name = "f_" + tree_node.name
|
|
146
|
+
else:
|
|
147
|
+
new_name = "d_" + tree_node.name
|
|
148
|
+
|
|
149
|
+
return TreeNode(new_name, [fxchange(child) for child in tree_node.children])
|
|
150
|
+
|
|
136
151
|
|
|
137
152
|
tree_node = fxchange(tree_node)
|
|
138
153
|
|
mathai/tool.py
CHANGED
mathai/univariate_inequality.py
CHANGED
|
@@ -9,7 +9,71 @@ from .expand import expand
|
|
|
9
9
|
from .fraction import fraction
|
|
10
10
|
import copy
|
|
11
11
|
from .diff import diff
|
|
12
|
-
|
|
12
|
+
|
|
13
|
+
from .factor import merge_sqrt
|
|
14
|
+
from .factor import rationalize_sqrt as rationalize
|
|
15
|
+
|
|
16
|
+
from functools import cmp_to_key
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def arithmetic(eq):
|
|
20
|
+
eq = dowhile(eq, lambda x: handle_sqrt(simplify(merge_sqrt(rationalize(x)))))
|
|
21
|
+
def helper(eq):
|
|
22
|
+
if eq.name[2:] in "le ge gt lt eq".split(" "):
|
|
23
|
+
a, b = frac(eq.children[0]), frac(eq.children[1])
|
|
24
|
+
|
|
25
|
+
if a is not None and b is not None:
|
|
26
|
+
out = {"le": lambda x, y: x <= y, "ge":lambda x, y: x >= y, "lt":lambda x, y: x < y,\
|
|
27
|
+
"gt":lambda x, y: x > y, "eq":lambda x, y: x == y}[eq.name[2:]](a, b)
|
|
28
|
+
if out:
|
|
29
|
+
return tree_form("s_true")
|
|
30
|
+
else:
|
|
31
|
+
return tree_form("s_false")
|
|
32
|
+
return TreeNode(eq.name, [helper(child) for child in eq.children])
|
|
33
|
+
def helper2(eq):
|
|
34
|
+
if eq.children == []:
|
|
35
|
+
if eq == tree_form("s_true"):
|
|
36
|
+
return True
|
|
37
|
+
elif eq == tree_form("s_false"):
|
|
38
|
+
return False
|
|
39
|
+
else:
|
|
40
|
+
return None
|
|
41
|
+
if eq.name == "f_or":
|
|
42
|
+
out = [helper2(child) for child in eq.children]
|
|
43
|
+
if None in out:
|
|
44
|
+
return None
|
|
45
|
+
return any(out)
|
|
46
|
+
if eq.name == "f_and":
|
|
47
|
+
out = [helper2(child) for child in eq.children]
|
|
48
|
+
if None in out:
|
|
49
|
+
return None
|
|
50
|
+
return all(out)
|
|
51
|
+
if eq.name == "f_not":
|
|
52
|
+
out = [helper2(child) for child in eq.children]
|
|
53
|
+
if None in out:
|
|
54
|
+
return None
|
|
55
|
+
return not out[0]
|
|
56
|
+
return None
|
|
57
|
+
|
|
58
|
+
return helper2(eq)
|
|
59
|
+
|
|
60
|
+
def less_than(eq1, eq2):
|
|
61
|
+
return arithmetic(TreeNode("f_le", [eq1,eq2]))
|
|
62
|
+
def equal_to(eq1, eq2):
|
|
63
|
+
return arithmetic(TreeNode("f_eq", [eq1,eq2]))
|
|
64
|
+
def custom_compare(a, b):
|
|
65
|
+
|
|
66
|
+
y = equal_to(a, b)
|
|
67
|
+
if y is not None:
|
|
68
|
+
if y:
|
|
69
|
+
return -1
|
|
70
|
+
x = less_than(a, b)
|
|
71
|
+
if x is not None:
|
|
72
|
+
if x:
|
|
73
|
+
return -1
|
|
74
|
+
else:
|
|
75
|
+
return 1
|
|
76
|
+
return 0
|
|
13
77
|
def intersection2(domain, lst):
|
|
14
78
|
domain = copy.deepcopy(domain)
|
|
15
79
|
if domain == [True]:
|
|
@@ -23,14 +87,14 @@ def intersection2(domain, lst):
|
|
|
23
87
|
|
|
24
88
|
if isinstance(domain[index], bool) and domain[index]:
|
|
25
89
|
|
|
26
|
-
if index == 0 and
|
|
90
|
+
if index == 0 and less_than(item2, domain[index+1]):
|
|
27
91
|
|
|
28
92
|
out.append(item2)
|
|
29
93
|
break
|
|
30
|
-
elif index == len(domain)-1 and
|
|
94
|
+
elif index == len(domain)-1 and less_than(domain[index-1], item2):
|
|
31
95
|
out.append(item2)
|
|
32
96
|
break
|
|
33
|
-
elif index != 0 and index != len(domain)-1 and
|
|
97
|
+
elif index != 0 and index != len(domain)-1 and less_than(domain[index-1], item2) and less_than(item2, domain[index+1]):
|
|
34
98
|
|
|
35
99
|
out.append(item2)
|
|
36
100
|
break
|
|
@@ -64,7 +128,8 @@ def intersection(domain_1, domain_2):
|
|
|
64
128
|
result = domain_1 + domain_2
|
|
65
129
|
result = [item for item in result if not isinstance(item, bool)]
|
|
66
130
|
result = list(set(result))
|
|
67
|
-
|
|
131
|
+
|
|
132
|
+
result = sorted(result, key=cmp_to_key(custom_compare))
|
|
68
133
|
i = len(result)
|
|
69
134
|
while i>=0:
|
|
70
135
|
result.insert(i, True)
|
|
@@ -216,7 +281,7 @@ def helper(eq, var="v_0"):
|
|
|
216
281
|
item = simplify(expand(item))
|
|
217
282
|
|
|
218
283
|
if len(vlist(item)) == 0:
|
|
219
|
-
if
|
|
284
|
+
if less_than(item, tree_form("d_0")):
|
|
220
285
|
sign = not sign
|
|
221
286
|
continue
|
|
222
287
|
v = vlist(item)[0]
|
|
@@ -230,12 +295,12 @@ def helper(eq, var="v_0"):
|
|
|
230
295
|
a = replace(diff(diff(item, v), v), tree_form(v), tree_form("d_0"))/tree_form("d_2")
|
|
231
296
|
if "v_" in str_form(a):
|
|
232
297
|
return None
|
|
233
|
-
if
|
|
298
|
+
if less_than(a, tree_form("d_0")):
|
|
234
299
|
sign = not sign
|
|
235
300
|
continue
|
|
236
301
|
else:
|
|
237
302
|
tmp2 = diff(copy.deepcopy(item))
|
|
238
|
-
if
|
|
303
|
+
if less_than(tmp2, tree_form("d_0")):
|
|
239
304
|
sign = not sign
|
|
240
305
|
item = simplify(item * tree_form("d_-1"))
|
|
241
306
|
out = inverse(item, vlist(item)[0])
|
|
@@ -247,12 +312,12 @@ def helper(eq, var="v_0"):
|
|
|
247
312
|
a = replace(diff(diff(item, v), v), tree_form(v), tree_form("d_0"))/tree_form("d_2")
|
|
248
313
|
if "v_" in str_form(a):
|
|
249
314
|
return None
|
|
250
|
-
if
|
|
315
|
+
if less_than(a, tree_form("d_0")):
|
|
251
316
|
sign = not sign
|
|
252
317
|
continue
|
|
253
318
|
else:
|
|
254
319
|
tmp2 = diff(copy.deepcopy(item))
|
|
255
|
-
if
|
|
320
|
+
if less_than(tmp2, tree_form("d_0")):
|
|
256
321
|
sign = not sign
|
|
257
322
|
item = simplify(item * tree_form("d_-1"))
|
|
258
323
|
out = inverse(item, vlist(item)[0])
|
|
@@ -264,7 +329,7 @@ def helper(eq, var="v_0"):
|
|
|
264
329
|
critical = [simplify(item) for item in critical]
|
|
265
330
|
critical = Counter(critical)
|
|
266
331
|
|
|
267
|
-
critical = sorted(critical.items(), key=lambda
|
|
332
|
+
critical = sorted(critical.items(), key=cmp_to_key(lambda a,b: custom_compare(a[0], b[0])))
|
|
268
333
|
|
|
269
334
|
i = len(critical)
|
|
270
335
|
element = sign
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
mathai/__init__.py,sha256=
|
|
1
|
+
mathai/__init__.py,sha256=_cw5FqfRBxoeFYc-9EDbRuZ7ZGTSBslgNcMO4zR31Bs,1418
|
|
2
2
|
mathai/apart.py,sha256=VSS3khE9PNuxiRvdU5JDl4IN-KJBSIFjwR17pkhviXI,4197
|
|
3
|
-
mathai/base.py,sha256=
|
|
4
|
-
mathai/console.py,sha256=Sn58iwYE79MLEh67s8X3q6vZjw6g7f9XM1T8_dBBR2o,3048
|
|
3
|
+
mathai/base.py,sha256=Di775V_upyhrel4--cNhG3Zskj5BKan0cAcjjFHjSzA,12721
|
|
5
4
|
mathai/diff.py,sha256=YUBpRsz0qmBkq5vGxeGnvR4nMKjdOQiIXlNMxpij2ns,3051
|
|
6
5
|
mathai/expand.py,sha256=SnBltkpIENMGkP0AYmbMlSc4H-CF5RslO2PcBEkn1BQ,3359
|
|
7
|
-
mathai/factor.py,sha256=
|
|
6
|
+
mathai/factor.py,sha256=6iXnm-TB4HRjzCki5dLi_NNhFIiRYE3h7_c4111zta8,11509
|
|
8
7
|
mathai/fraction.py,sha256=Q2ztsh5Bpz6YhML2QU0tfufbAs0Q6J319AhlzKephIY,4396
|
|
9
8
|
mathai/integrate.py,sha256=ewV46QDD0-oiTWpSkmcpcZhBz9StcntbTV1tBLCo1Wo,16502
|
|
10
9
|
mathai/inverse.py,sha256=QCvDrzKquWsZv-BDAzZd9HnU0c3gZvcc44UztHVO5LQ,2919
|
|
@@ -12,14 +11,14 @@ mathai/limit.py,sha256=bn7eofIOJv4AIh0-FmLppZ3DKnGfbwOzXks2XOPTOs0,4932
|
|
|
12
11
|
mathai/linear.py,sha256=BzSnm941Zlod_l6hON4Rs6J4pdAA3MGpRVqr6-66ZBk,5524
|
|
13
12
|
mathai/logic.py,sha256=UvHzRmKcO9AD51tRzHmpNSEhgW5gmaf4XPaQKFjGfC4,9653
|
|
14
13
|
mathai/ode.py,sha256=zxxTXAOpt7oSsfpgI4vHsCWKXevmM96ZOBZWWs-vj8Y,4801
|
|
15
|
-
mathai/parser.py,sha256=
|
|
14
|
+
mathai/parser.py,sha256=XEeWgfqRinTAXWKFg5NtkTQWvFgMgtr0BfrJmvyuPQM,6970
|
|
16
15
|
mathai/printeq.py,sha256=gIes-pstFOa6FcnpVIVvkjVKuWdsVdo11LlEnmHhakU,1303
|
|
17
16
|
mathai/simplify.py,sha256=nR5IReewrJ7HbxEUzQ2zg9xoFcwI1R5lGjWnX1pBKko,16885
|
|
18
17
|
mathai/structure.py,sha256=4Ww2IAx62RcQSO7_17TZES-DjMWBpcFQtL939FBIHwY,4103
|
|
19
|
-
mathai/tool.py,sha256=
|
|
18
|
+
mathai/tool.py,sha256=ivU4urQ9QxvfIO6bXqNtOvza4HnuZZfaO2m-bCuHaWc,6068
|
|
20
19
|
mathai/trig.py,sha256=BQd_Gl_u0g5ZuZIwKozuXKbMinqb6K-OYicrtftn7eg,11174
|
|
21
|
-
mathai/univariate_inequality.py,sha256=
|
|
22
|
-
mathai-0.4.
|
|
23
|
-
mathai-0.4.
|
|
24
|
-
mathai-0.4.
|
|
25
|
-
mathai-0.4.
|
|
20
|
+
mathai/univariate_inequality.py,sha256=4Uwzneoofb-q8hFg6TsqK1SZTBCnGHbYUU9XoyspA5M,16996
|
|
21
|
+
mathai-0.4.9.dist-info/METADATA,sha256=C4r7cP1Tp2SpN22TaTyobAKHaSGdW2FeyJ4ie3A9X54,7103
|
|
22
|
+
mathai-0.4.9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
23
|
+
mathai-0.4.9.dist-info/top_level.txt,sha256=ROP4l3OhGYw3ihkQGASr18xM9GsK4z3_6whV5AyXLwE,7
|
|
24
|
+
mathai-0.4.9.dist-info/RECORD,,
|
mathai/console.py
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import copy
|
|
2
|
-
from .expand import expand
|
|
3
|
-
from .parser import parse
|
|
4
|
-
from .printeq import printeq, printeq_log
|
|
5
|
-
from .simplify import solve, simplify
|
|
6
|
-
|
|
7
|
-
from .diff import diff
|
|
8
|
-
from .base import *
|
|
9
|
-
from .factor import _factorconst, factor
|
|
10
|
-
from .fraction import fraction
|
|
11
|
-
from .inverse import inverse
|
|
12
|
-
from .trig import trig0, trig1, trig2, trig3, trig4
|
|
13
|
-
from .logic import logic0, logic1, logic2, logic3
|
|
14
|
-
from .apart import apart
|
|
15
|
-
|
|
16
|
-
def console():
|
|
17
|
-
eq = None
|
|
18
|
-
orig = None
|
|
19
|
-
while True:
|
|
20
|
-
command = input(">>> ")
|
|
21
|
-
try:
|
|
22
|
-
orig = copy.deepcopy(eq)
|
|
23
|
-
if command == "expand":
|
|
24
|
-
eq = expand(eq)
|
|
25
|
-
elif command.split(" ")[0] == "inverse":
|
|
26
|
-
eq=simplify(eq)
|
|
27
|
-
if eq.name == "f_eq":
|
|
28
|
-
eq3 = eq.children[0]-eq.children[1]
|
|
29
|
-
eq2 = parse(command.split(" ")[1])
|
|
30
|
-
out = inverse(eq3, str_form(eq2))
|
|
31
|
-
eq = TreeNode(eq.name, [eq2,out])
|
|
32
|
-
elif command == "apart":
|
|
33
|
-
eq = apart(eq, vlist(eq)[0])
|
|
34
|
-
elif command == "rawprint":
|
|
35
|
-
print(eq)
|
|
36
|
-
elif command == "logic0":
|
|
37
|
-
eq = logic0(eq)
|
|
38
|
-
elif command == "logic1":
|
|
39
|
-
eq = logic1(eq)
|
|
40
|
-
elif command == "logic2":
|
|
41
|
-
eq = logic2(eq)
|
|
42
|
-
elif command == "logic3":
|
|
43
|
-
eq = logic3(eq)
|
|
44
|
-
elif command == "trig0":
|
|
45
|
-
eq = trig0(eq)
|
|
46
|
-
elif command == "trig1":
|
|
47
|
-
eq = trig1(eq)
|
|
48
|
-
elif command == "factor":
|
|
49
|
-
eq = factor(eq)
|
|
50
|
-
elif command == "trig2":
|
|
51
|
-
eq = trig2(eq)
|
|
52
|
-
elif command == "trig3":
|
|
53
|
-
eq = trig3(eq)
|
|
54
|
-
elif command == "trig4":
|
|
55
|
-
eq = trig4(eq)
|
|
56
|
-
elif command == "simplify":
|
|
57
|
-
eq = _factorconst(eq)
|
|
58
|
-
eq = simplify(eq)
|
|
59
|
-
elif command == "fraction":
|
|
60
|
-
eq = fraction(eq)
|
|
61
|
-
elif command.split(" ")[0] in ["integrate", "sqint", "byparts"]:
|
|
62
|
-
if command.split(" ")[0] == "sqint":
|
|
63
|
-
typesqint()
|
|
64
|
-
elif command.split(" ")[0] == "byparts":
|
|
65
|
-
typebyparts()
|
|
66
|
-
elif command.split(" ")[0] == "integrate":
|
|
67
|
-
typeintegrate()
|
|
68
|
-
out = integrate(eq, parse(command.split(" ")[1]).name)
|
|
69
|
-
if out is None:
|
|
70
|
-
print("failed to integrate")
|
|
71
|
-
else:
|
|
72
|
-
eq, logs = out
|
|
73
|
-
eq = simplify(eq)
|
|
74
|
-
printeq_log(logs)
|
|
75
|
-
print()
|
|
76
|
-
elif command.split(" ")[0] == "diff":
|
|
77
|
-
eq = diff(eq, parse(command.split(" ")[1]).name)
|
|
78
|
-
else:
|
|
79
|
-
eq = parse(command)
|
|
80
|
-
eq = copy.deepcopy(eq)
|
|
81
|
-
printeq(eq)
|
|
82
|
-
except:
|
|
83
|
-
eq = copy.deepcopy(orig)
|
|
84
|
-
print("error")
|
|
File without changes
|
|
File without changes
|