mathai 0.6.0__tar.gz → 0.6.1__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.6.0 → mathai-0.6.1}/PKG-INFO +1 -1
- {mathai-0.6.0 → mathai-0.6.1}/mathai/__init__.py +1 -1
- {mathai-0.6.0 → mathai-0.6.1}/mathai/base.py +52 -19
- {mathai-0.6.0 → mathai-0.6.1}/mathai/factor.py +1 -0
- {mathai-0.6.0 → mathai-0.6.1}/mathai/integrate.py +4 -1
- mathai-0.6.1/mathai/matrix.py +96 -0
- {mathai-0.6.0 → mathai-0.6.1}/mathai/parser.py +7 -7
- mathai-0.6.1/mathai/parsetab.py +61 -0
- {mathai-0.6.0 → mathai-0.6.1}/mathai.egg-info/PKG-INFO +1 -1
- {mathai-0.6.0 → mathai-0.6.1}/mathai.egg-info/SOURCES.txt +1 -0
- {mathai-0.6.0 → mathai-0.6.1}/setup.py +1 -1
- mathai-0.6.0/mathai/matrix.py +0 -22
- {mathai-0.6.0 → mathai-0.6.1}/README.md +0 -0
- {mathai-0.6.0 → mathai-0.6.1}/mathai/apart.py +0 -0
- {mathai-0.6.0 → mathai-0.6.1}/mathai/bivariate_inequality.py +0 -0
- {mathai-0.6.0 → mathai-0.6.1}/mathai/console.py +0 -0
- {mathai-0.6.0 → mathai-0.6.1}/mathai/diff.py +0 -0
- {mathai-0.6.0 → mathai-0.6.1}/mathai/expand.py +0 -0
- {mathai-0.6.0 → mathai-0.6.1}/mathai/fraction.py +0 -0
- {mathai-0.6.0 → mathai-0.6.1}/mathai/inverse.py +0 -0
- {mathai-0.6.0 → mathai-0.6.1}/mathai/limit.py +0 -0
- {mathai-0.6.0 → mathai-0.6.1}/mathai/linear.py +0 -0
- {mathai-0.6.0 → mathai-0.6.1}/mathai/logic.py +0 -0
- {mathai-0.6.0 → mathai-0.6.1}/mathai/ode.py +0 -0
- {mathai-0.6.0 → mathai-0.6.1}/mathai/printeq.py +0 -0
- {mathai-0.6.0 → mathai-0.6.1}/mathai/simplify.py +0 -0
- {mathai-0.6.0 → mathai-0.6.1}/mathai/structure.py +0 -0
- {mathai-0.6.0 → mathai-0.6.1}/mathai/tool.py +0 -0
- {mathai-0.6.0 → mathai-0.6.1}/mathai/trig.py +0 -0
- {mathai-0.6.0 → mathai-0.6.1}/mathai/univariate_inequality.py +0 -0
- {mathai-0.6.0 → mathai-0.6.1}/mathai.egg-info/dependency_links.txt +0 -0
- {mathai-0.6.0 → mathai-0.6.1}/mathai.egg-info/requires.txt +0 -0
- {mathai-0.6.0 → mathai-0.6.1}/mathai.egg-info/top_level.txt +0 -0
- {mathai-0.6.0 → mathai-0.6.1}/setup.cfg +0 -0
|
@@ -44,7 +44,7 @@ from .limit import limit1, limit2, limit0, limit3
|
|
|
44
44
|
from .univariate_inequality import wavycurvy, absolute, domain, handle_sqrt, prepare
|
|
45
45
|
from .bivariate_inequality import inequality_solve
|
|
46
46
|
|
|
47
|
-
from .matrix import
|
|
47
|
+
from .matrix import matrix_solve
|
|
48
48
|
|
|
49
49
|
from .base import *
|
|
50
50
|
|
|
@@ -1,23 +1,56 @@
|
|
|
1
1
|
import copy
|
|
2
2
|
from fractions import Fraction
|
|
3
|
-
|
|
3
|
+
def contains_list_or_neg(node):
|
|
4
|
+
if node.name == "f_list" or node.name.startswith("v_-"):
|
|
5
|
+
return True
|
|
6
|
+
for child in node.children:
|
|
7
|
+
if contains_list_or_neg(child):
|
|
8
|
+
return True
|
|
9
|
+
return False
|
|
4
10
|
class TreeNode:
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
11
|
+
matmul = True
|
|
12
|
+
|
|
13
|
+
def __init__(self, name, children=None):
|
|
14
|
+
if children is None:
|
|
15
|
+
children = []
|
|
16
|
+
|
|
17
|
+
# copy once
|
|
18
|
+
children = copy.deepcopy(children)
|
|
8
19
|
self.name = name
|
|
9
|
-
|
|
10
|
-
|
|
20
|
+
|
|
21
|
+
if name == "f_add" or (name == "f_mul" and TreeNode.matmul):
|
|
22
|
+
keyed = [(str_form(c), c) for c in children]
|
|
23
|
+
self.children = [c for _, c in sorted(keyed)]
|
|
24
|
+
|
|
25
|
+
elif name == "f_mul":
|
|
26
|
+
sortable = []
|
|
27
|
+
fixed = []
|
|
28
|
+
for c in children:
|
|
29
|
+
if not contains_list_or_neg(c):
|
|
30
|
+
sortable.append(c)
|
|
31
|
+
else:
|
|
32
|
+
fixed.append(c)
|
|
33
|
+
if len(fixed) > 1:
|
|
34
|
+
fixed = TreeNode("f_wmul", fixed)
|
|
35
|
+
elif len(fixed) == 1:
|
|
36
|
+
fixed = fixed[0]
|
|
37
|
+
if isinstance(fixed, TreeNode):
|
|
38
|
+
sortable.append(fixed)
|
|
39
|
+
if len(sortable)==1 and name == "f_mul":
|
|
40
|
+
self.name = sortable[0].name
|
|
41
|
+
if self.name in ["f_add", "f_mul"]:
|
|
42
|
+
self.children = list(sorted(sortable[0].children, key=lambda x: str_form(x)))
|
|
43
|
+
else:
|
|
44
|
+
self.children = sortable[0].children
|
|
45
|
+
|
|
46
|
+
else:
|
|
47
|
+
self.children = list(sorted(sortable, key=lambda x: str_form(x)))
|
|
11
48
|
else:
|
|
12
49
|
self.children = children
|
|
13
50
|
|
|
51
|
+
|
|
14
52
|
def fx(self, fxname):
|
|
15
53
|
return TreeNode("f_" + fxname, [self])
|
|
16
|
-
def copy_tree(node):
|
|
17
|
-
if node is None:
|
|
18
|
-
return None
|
|
19
|
-
|
|
20
|
-
return tree_form(str_form(node))
|
|
21
54
|
|
|
22
55
|
def __repr__(self):
|
|
23
56
|
return string_equation(str_form(self))
|
|
@@ -325,30 +358,30 @@ def product(lst):
|
|
|
325
358
|
for item in lst[1:]:
|
|
326
359
|
s *= item
|
|
327
360
|
return s
|
|
328
|
-
def flatten_tree(node):
|
|
361
|
+
def flatten_tree(node, add=[]):
|
|
329
362
|
if not node.children:
|
|
330
363
|
return node
|
|
331
|
-
if node.name in
|
|
364
|
+
if node.name in ["f_add", "f_mul", "f_and", "f_or"]+add:
|
|
332
365
|
merged_children = []
|
|
333
366
|
for child in node.children:
|
|
334
|
-
flattened_child = flatten_tree(child)
|
|
367
|
+
flattened_child = flatten_tree(child, add)
|
|
335
368
|
if flattened_child.name == node.name:
|
|
336
369
|
merged_children.extend(flattened_child.children)
|
|
337
370
|
else:
|
|
338
371
|
merged_children.append(flattened_child)
|
|
339
372
|
return TreeNode(node.name, merged_children)
|
|
340
373
|
else:
|
|
341
|
-
node.children = [flatten_tree(child) for child in node.children]
|
|
374
|
+
node.children = [flatten_tree(child, add) for child in node.children]
|
|
342
375
|
return node
|
|
343
376
|
def dowhile(eq, fx):
|
|
344
377
|
if eq is None:
|
|
345
378
|
return None
|
|
346
379
|
while True:
|
|
347
|
-
orig =
|
|
380
|
+
orig = copy.deepcopy(eq)
|
|
348
381
|
eq2 = fx(eq)
|
|
349
382
|
if eq2 is None:
|
|
350
383
|
return None
|
|
351
|
-
eq =
|
|
384
|
+
eq = copy.deepcopy(eq2)
|
|
352
385
|
if eq == orig:
|
|
353
386
|
return orig
|
|
354
387
|
def tree_form(tabbed_strings):
|
|
@@ -384,7 +417,7 @@ def string_equation_helper(equation_tree):
|
|
|
384
417
|
s = "("
|
|
385
418
|
if len(equation_tree.children) == 1 or equation_tree.name[2:] in [chr(ord("A")+i) for i in range(26)]+["limitpinf", "subs", "try", "ref","limit", "integrate", "exist", "forall", "sum2", "int", "pdif", "dif", "A", "B", "C", "covariance", "sum"]:
|
|
386
419
|
s = equation_tree.name[2:] + s
|
|
387
|
-
sign = {"f_not":"~", "
|
|
420
|
+
sign = {"f_not":"~", "f_wadd":"+", "f_wmul":"*", "f_intersection":"&", "f_union":"|", "f_sum2":",", "f_exist":",", "f_forall":",", "f_sum":",","f_covariance": ",", "f_B":",", "f_imply":"->", "f_ge":">=", "f_le":"<=", "f_gt":">", "f_lt":"<", "f_cosec":"?" , "f_equiv": "<->", "f_sec":"?", "f_cot": "?", "f_dot": ".", "f_circumcenter":"?", "f_transpose":"?", "f_exp":"?", "f_abs":"?", "f_log":"?", "f_and":"&", "f_or":"|", "f_sub":"-", "f_neg":"?", "f_inv":"?", "f_add": "+", "f_mul": "*", "f_pow": "^", "f_poly": ",", "f_div": "/", "f_sub": "-", "f_dif": ",", "f_sin": "?", "f_cos": "?", "f_tan": "?", "f_eq": "=", "f_sqrt": "?"}
|
|
388
421
|
arr = []
|
|
389
422
|
k = None
|
|
390
423
|
if equation_tree.name not in sign.keys():
|
|
@@ -392,7 +425,7 @@ def string_equation_helper(equation_tree):
|
|
|
392
425
|
else:
|
|
393
426
|
k = sign[equation_tree.name]
|
|
394
427
|
for child in equation_tree.children:
|
|
395
|
-
arr.append(string_equation_helper(
|
|
428
|
+
arr.append(string_equation_helper(copy.deepcopy(child)))
|
|
396
429
|
outfinal = s + k.join(arr) + ")"+extra
|
|
397
430
|
|
|
398
431
|
return outfinal.replace("+-", "-")
|
|
@@ -174,6 +174,7 @@ def factor_quar_formula_init():
|
|
|
174
174
|
return [formula_list, var, expr]
|
|
175
175
|
|
|
176
176
|
formula_gen9 = factor_quar_formula_init()
|
|
177
|
+
|
|
177
178
|
def factor_helper(equation, complexnum, power=2):
|
|
178
179
|
global formula_gen9
|
|
179
180
|
if equation.name in ["f_or", "f_and", "f_not", "f_eq", "f_gt", "f_lt", "f_ge", "f_le"]:
|
|
@@ -380,7 +380,6 @@ def integration_formula_init():
|
|
|
380
380
|
formula_list = [[simplify(parse(y)) for y in x] for x in formula_list]
|
|
381
381
|
expr = [[parse("A"), parse("1")], [parse("B"), parse("0")]]
|
|
382
382
|
return [formula_list, var, expr]
|
|
383
|
-
formula_gen = integration_formula_init()
|
|
384
383
|
def integration_formula_trig():
|
|
385
384
|
var = "x"
|
|
386
385
|
formula_list = [(f"(A+B*sin({var})+C*cos({var}))/(D+E*sin({var})+F*cos({var}))", f"((B*E+C*F)/(E^2+F^2))*{var}+((C*E-B*F)/(E^2+F^2))*log(D+E*sin({var})+F*cos({var}))")]
|
|
@@ -389,8 +388,12 @@ def integration_formula_trig():
|
|
|
389
388
|
[parse("C"), parse("0"), parse("1")], [parse("D"), parse("0"), parse("1")],\
|
|
390
389
|
[parse("E"), parse("0"), parse("1")], [parse("F"), parse("0"), parse("1")]]
|
|
391
390
|
return [formula_list, var, expr]
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
formula_gen = integration_formula_init()
|
|
392
394
|
formula_gen4 = integration_formula_trig()
|
|
393
395
|
|
|
396
|
+
|
|
394
397
|
def integration_formula_ex():
|
|
395
398
|
var = "x"
|
|
396
399
|
formula_list = [
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
from .base import *
|
|
2
|
+
import copy
|
|
3
|
+
from .simplify import simplify
|
|
4
|
+
import itertools
|
|
5
|
+
|
|
6
|
+
# ---------- tree <-> python list ----------
|
|
7
|
+
def tree_to_py(node):
|
|
8
|
+
if node.name=="f_list":
|
|
9
|
+
return [tree_to_py(c) for c in node.children]
|
|
10
|
+
return node
|
|
11
|
+
|
|
12
|
+
def py_to_tree(obj):
|
|
13
|
+
if isinstance(obj,list):
|
|
14
|
+
return TreeNode("f_list",[py_to_tree(x) for x in obj])
|
|
15
|
+
return obj
|
|
16
|
+
|
|
17
|
+
# ---------- shape detection ----------
|
|
18
|
+
def is_vector(x):
|
|
19
|
+
return isinstance(x,list) and all(isinstance(item,TreeNode) for item in x)
|
|
20
|
+
def is_mat(x):
|
|
21
|
+
return isinstance(x,list) and all(isinstance(item,list) for item in x)
|
|
22
|
+
def is_matrix(x):
|
|
23
|
+
return isinstance(x, list) and all(isinstance(item, list) and (is_mat(item) or is_vector(item)) for item in x)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# ---------- algebra primitives ----------
|
|
27
|
+
def dot(u,v):
|
|
28
|
+
if len(u)!=len(v):
|
|
29
|
+
raise ValueError("Vector size mismatch")
|
|
30
|
+
s = tree_form("d_0")
|
|
31
|
+
for a,b in zip(u,v):
|
|
32
|
+
s = TreeNode("f_add",[s,TreeNode("f_mul",[a,b])])
|
|
33
|
+
return s
|
|
34
|
+
|
|
35
|
+
def matmul(A,B):
|
|
36
|
+
n,m,p = len(A), len(A[0]), len(B[0])
|
|
37
|
+
if m!=len(B):
|
|
38
|
+
raise ValueError("Matrix dimension mismatch")
|
|
39
|
+
z = tree_form("d_0")
|
|
40
|
+
C = [[z for _ in range(p)] for _ in range(n)]
|
|
41
|
+
for i in range(n):
|
|
42
|
+
for j in range(p):
|
|
43
|
+
for k in range(m):
|
|
44
|
+
C[i][j] = TreeNode("f_add",[C[i][j], TreeNode("f_mul",[A[i][k], B[k][j]])])
|
|
45
|
+
return C
|
|
46
|
+
|
|
47
|
+
# ---------- promotion ----------
|
|
48
|
+
def promote(node):
|
|
49
|
+
if node.name=="f_list":
|
|
50
|
+
return tree_to_py(node)
|
|
51
|
+
return node
|
|
52
|
+
def contains_neg(node):
|
|
53
|
+
if isinstance(node, list):
|
|
54
|
+
return False
|
|
55
|
+
if node.name.startswith("v_-"):
|
|
56
|
+
return False
|
|
57
|
+
for child in node.children:
|
|
58
|
+
if not contains_neg(child):
|
|
59
|
+
return False
|
|
60
|
+
return True
|
|
61
|
+
# ---------- multiplication (fully simplified) ----------
|
|
62
|
+
def multiply(left,right):
|
|
63
|
+
A,B = promote(left), promote(right)
|
|
64
|
+
|
|
65
|
+
# vector · vector
|
|
66
|
+
if is_vector(A) and is_vector(B):
|
|
67
|
+
return dot(A,B)
|
|
68
|
+
# matrix × matrix
|
|
69
|
+
if is_matrix(A) and is_matrix(B):
|
|
70
|
+
return py_to_tree(matmul(A,B))
|
|
71
|
+
# scalar × vector
|
|
72
|
+
for _ in range(2):
|
|
73
|
+
if contains_neg(A) and is_vector(B):
|
|
74
|
+
return py_to_tree([TreeNode("f_mul",[A,x]) for x in B])
|
|
75
|
+
# scalar × matrix
|
|
76
|
+
if contains_neg(A) and is_matrix(B):
|
|
77
|
+
return py_to_tree([[TreeNode("f_mul",[A,x]) for x in row] for row in B])
|
|
78
|
+
A, B = B, A
|
|
79
|
+
return None
|
|
80
|
+
|
|
81
|
+
def fold_wmul(eq):
|
|
82
|
+
if eq.name=="f_wmul" and any(item.name=="f_list" or item.name.startswith("v_-") for item in eq.children):
|
|
83
|
+
i = len(eq.children)-1
|
|
84
|
+
while i>0:
|
|
85
|
+
out = multiply(eq.children[i], eq.children[i-1])
|
|
86
|
+
if out is not None:
|
|
87
|
+
eq.children.pop(i)
|
|
88
|
+
eq.children.pop(i-1)
|
|
89
|
+
eq.children.append(out)
|
|
90
|
+
i = i-1
|
|
91
|
+
return eq
|
|
92
|
+
return TreeNode(eq.name, [fold_wmul(child) for child in eq.children])
|
|
93
|
+
def flat(eq):
|
|
94
|
+
return flatten_tree(tree_form(str_form(eq).replace("f_w","f_")))
|
|
95
|
+
def matrix_solve(eq):
|
|
96
|
+
return flat(dowhile(eq, lambda x: fold_wmul(flat(x))))
|
|
@@ -33,11 +33,11 @@ grammar = """
|
|
|
33
33
|
| comparison "<=" arithmetic -> le
|
|
34
34
|
| comparison ">=" arithmetic -> ge
|
|
35
35
|
|
|
36
|
-
?arithmetic: arithmetic "+" term ->
|
|
36
|
+
?arithmetic: arithmetic "+" term -> wadd
|
|
37
37
|
| arithmetic "-" term -> sub
|
|
38
38
|
| term
|
|
39
39
|
|
|
40
|
-
?term: term "*" power ->
|
|
40
|
+
?term: term "*" power -> wmul
|
|
41
41
|
| term "/" power -> div
|
|
42
42
|
| term "." power -> dot
|
|
43
43
|
| power
|
|
@@ -85,7 +85,7 @@ def parse(equation, funclist=None):
|
|
|
85
85
|
|
|
86
86
|
parser_main = Lark(grammar2, start='start', parser='lalr')
|
|
87
87
|
parse_tree = parser_main.parse(equation)
|
|
88
|
-
|
|
88
|
+
|
|
89
89
|
# Convert Lark tree to TreeNode
|
|
90
90
|
def convert_to_treenode(parse_tree):
|
|
91
91
|
if isinstance(parse_tree, Tree):
|
|
@@ -130,7 +130,7 @@ def parse(equation, funclist=None):
|
|
|
130
130
|
if tree_node.name == "pass_through":
|
|
131
131
|
return fxchange(tree_node.children[0])
|
|
132
132
|
return TreeNode(
|
|
133
|
-
"f_" + tree_node.name if tree_node.name in tmp3 + ["limitpinf", "limit", "try", "ref", "sqrt","imply","forall","exist","exclude","union","intersection","len","index","angle","charge","sum2","electricfield","line","point","sum","transpose","equationrhs","equationlhs","equation","covariance","variance","expect","error","laplace","dot","curl","pdif","diverge","gradient","rad","ge","le","gt","lt","eqtri","linesegment","midpoint","mag","point1","point2","point3","line1","line2","line3","log10","arcsin","arccos","arctan","list","cosec","sec","cot","equiv","or","not","and","circumcenter","eq","sub","
|
|
133
|
+
"f_" + tree_node.name if tree_node.name in tmp3 + ["limitpinf", "limit", "try", "ref", "sqrt","imply","forall","exist","exclude","union","intersection","len","index","angle","charge","sum2","electricfield","line","point","sum","transpose","equationrhs","equationlhs","equation","covariance","variance","expect","error","laplace","dot","curl","pdif","diverge","gradient","rad","ge","le","gt","lt","eqtri","linesegment","midpoint","mag","point1","point2","point3","line1","line2","line3","log10","arcsin","arccos","arctan","list","cosec","sec","cot","equiv","or","not","and","circumcenter","eq","sub","wadd","sin","cos","tan","wmul","integrate","dif","pow","div","log","abs"] else "d_" + tree_node.name,
|
|
134
134
|
[fxchange(child) for child in tree_node.children]
|
|
135
135
|
)
|
|
136
136
|
|
|
@@ -146,13 +146,13 @@ def parse(equation, funclist=None):
|
|
|
146
146
|
for i, c in enumerate([chr(x+ord("A")) for x in range(0,26)]):
|
|
147
147
|
tree_node = replace(tree_node, tree_form("d_"+c), tree_form("v_-"+str(i+1)))
|
|
148
148
|
tree_node = replace(tree_node, tree_form("f_"+c), tree_form("v_-"+str(i+1)))
|
|
149
|
-
|
|
150
|
-
# Final recursive replacements
|
|
149
|
+
|
|
151
150
|
def rfx(tree_node):
|
|
152
151
|
if tree_node.name[:3] == "d_c":
|
|
153
152
|
return tree_form("v_" + str(int(tree_node.name[3:])+100))
|
|
154
153
|
tree_node.children = [rfx(child) for child in tree_node.children]
|
|
155
154
|
return tree_node
|
|
156
|
-
|
|
157
155
|
tree_node = rfx(tree_node)
|
|
156
|
+
tree_node = flatten_tree(tree_node, ["f_wmul","f_wadd"])
|
|
157
|
+
tree_node = tree_form(str_form(tree_node).replace("f_w","f_"))
|
|
158
158
|
return tree_node
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
|
|
2
|
+
# parsetab.py
|
|
3
|
+
# This file is automatically generated. Do not edit.
|
|
4
|
+
# pylint: disable=W,C,R
|
|
5
|
+
_tabversion = '3.10'
|
|
6
|
+
|
|
7
|
+
_lr_method = 'LALR'
|
|
8
|
+
|
|
9
|
+
_lr_signature = 'leftEQUIVleftIMPLYleftORleftANDleftEQLTGTLEGEleftPLUSMINUSleftTIMESDIVDOTrightPOWrightNOTUMINUSUPLUSAND CAPITAL_ID CNUMBER COMMA DIV DOT EQ EQUIV GE GT IMPLY LBRACK LE LPAREN LT MINUS NOT NUMBER OR PLUS POW RBRACK RPAREN STRING TIMES VARIABLEstart : exprexpr : expr EQUIV exprexpr : expr IMPLY exprexpr : expr OR exprexpr : expr AND exprexpr : NOT exprexpr : expr EQ expr\n | expr LT expr\n | expr GT expr\n | expr LE expr\n | expr GE exprexpr : expr PLUS expr\n | expr MINUS exprexpr : expr TIMES expr\n | expr DIV expr\n | expr DOT exprexpr : expr POW exprexpr : MINUS expr %prec UMINUSexpr : PLUS expr %prec UPLUSexpr : atomexpr : LPAREN expr RPARENexpr : LBRACK expr_list RBRACKexpr : LBRACK RBRACKexpr_list : expr_list COMMA exprexpr_list : exprexpr : VARIABLE LPAREN expr_list RPARENatom : VARIABLE\n | CAPITAL_ID\n | NUMBER\n | CNUMBER\n | STRING'
|
|
10
|
+
|
|
11
|
+
_lr_action_items = {'NOT':([0,3,4,5,7,8,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,36,54,],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,]),'MINUS':([0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,56,57,],[5,24,5,5,5,-20,5,5,-27,-28,-29,-30,-31,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,-6,-19,-18,24,-23,24,5,24,24,24,24,24,24,24,24,24,-12,-13,-14,-15,-16,-17,-21,-22,5,24,-26,]),'PLUS':([0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,56,57,],[4,23,4,4,4,-20,4,4,-27,-28,-29,-30,-31,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,-6,-19,-18,23,-23,23,4,23,23,23,23,23,23,23,23,23,-12,-13,-14,-15,-16,-17,-21,-22,4,23,-26,]),'LPAREN':([0,3,4,5,7,8,9,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,36,54,],[7,7,7,7,7,7,36,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,]),'LBRACK':([0,3,4,5,7,8,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,36,54,],[8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,]),'VARIABLE':([0,3,4,5,7,8,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,36,54,],[9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,]),'CAPITAL_ID':([0,3,4,5,7,8,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,36,54,],[10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,]),'NUMBER':([0,3,4,5,7,8,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,36,54,],[11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,]),'CNUMBER':([0,3,4,5,7,8,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,36,54,],[12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,]),'STRING':([0,3,4,5,7,8,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,36,54,],[13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,]),'$end':([1,2,6,9,10,11,12,13,29,30,31,34,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,57,],[0,-1,-20,-27,-28,-29,-30,-31,-6,-19,-18,-23,-2,-3,-4,-5,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-21,-22,-26,]),'EQUIV':([2,6,9,10,11,12,13,29,30,31,32,34,35,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,56,57,],[14,-20,-27,-28,-29,-30,-31,-6,-19,-18,14,-23,14,-2,-3,-4,-5,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-21,-22,14,-26,]),'IMPLY':([2,6,9,10,11,12,13,29,30,31,32,34,35,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,56,57,],[15,-20,-27,-28,-29,-30,-31,-6,-19,-18,15,-23,15,15,-3,-4,-5,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-21,-22,15,-26,]),'OR':([2,6,9,10,11,12,13,29,30,31,32,34,35,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,56,57,],[16,-20,-27,-28,-29,-30,-31,-6,-19,-18,16,-23,16,16,16,-4,-5,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-21,-22,16,-26,]),'AND':([2,6,9,10,11,12,13,29,30,31,32,34,35,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,56,57,],[17,-20,-27,-28,-29,-30,-31,-6,-19,-18,17,-23,17,17,17,17,-5,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-21,-22,17,-26,]),'EQ':([2,6,9,10,11,12,13,29,30,31,32,34,35,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,56,57,],[18,-20,-27,-28,-29,-30,-31,-6,-19,-18,18,-23,18,18,18,18,18,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-21,-22,18,-26,]),'LT':([2,6,9,10,11,12,13,29,30,31,32,34,35,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,56,57,],[19,-20,-27,-28,-29,-30,-31,-6,-19,-18,19,-23,19,19,19,19,19,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-21,-22,19,-26,]),'GT':([2,6,9,10,11,12,13,29,30,31,32,34,35,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,56,57,],[20,-20,-27,-28,-29,-30,-31,-6,-19,-18,20,-23,20,20,20,20,20,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-21,-22,20,-26,]),'LE':([2,6,9,10,11,12,13,29,30,31,32,34,35,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,56,57,],[21,-20,-27,-28,-29,-30,-31,-6,-19,-18,21,-23,21,21,21,21,21,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-21,-22,21,-26,]),'GE':([2,6,9,10,11,12,13,29,30,31,32,34,35,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,56,57,],[22,-20,-27,-28,-29,-30,-31,-6,-19,-18,22,-23,22,22,22,22,22,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-21,-22,22,-26,]),'TIMES':([2,6,9,10,11,12,13,29,30,31,32,34,35,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,56,57,],[25,-20,-27,-28,-29,-30,-31,-6,-19,-18,25,-23,25,25,25,25,25,25,25,25,25,25,25,25,-14,-15,-16,-17,-21,-22,25,-26,]),'DIV':([2,6,9,10,11,12,13,29,30,31,32,34,35,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,56,57,],[26,-20,-27,-28,-29,-30,-31,-6,-19,-18,26,-23,26,26,26,26,26,26,26,26,26,26,26,26,-14,-15,-16,-17,-21,-22,26,-26,]),'DOT':([2,6,9,10,11,12,13,29,30,31,32,34,35,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,56,57,],[27,-20,-27,-28,-29,-30,-31,-6,-19,-18,27,-23,27,27,27,27,27,27,27,27,27,27,27,27,-14,-15,-16,-17,-21,-22,27,-26,]),'POW':([2,6,9,10,11,12,13,29,30,31,32,34,35,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,56,57,],[28,-20,-27,-28,-29,-30,-31,-6,-19,-18,28,-23,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,-21,-22,28,-26,]),'RPAREN':([6,9,10,11,12,13,29,30,31,32,34,35,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,55,56,57,],[-20,-27,-28,-29,-30,-31,-6,-19,-18,52,-23,-25,-2,-3,-4,-5,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-21,-22,57,-24,-26,]),'RBRACK':([6,8,9,10,11,12,13,29,30,31,33,34,35,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,56,57,],[-20,34,-27,-28,-29,-30,-31,-6,-19,-18,53,-23,-25,-2,-3,-4,-5,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-21,-22,-24,-26,]),'COMMA':([6,9,10,11,12,13,29,30,31,33,34,35,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,55,56,57,],[-20,-27,-28,-29,-30,-31,-6,-19,-18,54,-23,-25,-2,-3,-4,-5,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-21,-22,54,-24,-26,]),}
|
|
12
|
+
|
|
13
|
+
_lr_action = {}
|
|
14
|
+
for _k, _v in _lr_action_items.items():
|
|
15
|
+
for _x,_y in zip(_v[0],_v[1]):
|
|
16
|
+
if not _x in _lr_action: _lr_action[_x] = {}
|
|
17
|
+
_lr_action[_x][_k] = _y
|
|
18
|
+
del _lr_action_items
|
|
19
|
+
|
|
20
|
+
_lr_goto_items = {'start':([0,],[1,]),'expr':([0,3,4,5,7,8,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,36,54,],[2,29,30,31,32,35,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,35,56,]),'atom':([0,3,4,5,7,8,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,36,54,],[6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,]),'expr_list':([8,36,],[33,55,]),}
|
|
21
|
+
|
|
22
|
+
_lr_goto = {}
|
|
23
|
+
for _k, _v in _lr_goto_items.items():
|
|
24
|
+
for _x, _y in zip(_v[0], _v[1]):
|
|
25
|
+
if not _x in _lr_goto: _lr_goto[_x] = {}
|
|
26
|
+
_lr_goto[_x][_k] = _y
|
|
27
|
+
del _lr_goto_items
|
|
28
|
+
_lr_productions = [
|
|
29
|
+
("S' -> start","S'",1,None,None,None),
|
|
30
|
+
('start -> expr','start',1,'p_start','parser.py',98),
|
|
31
|
+
('expr -> expr EQUIV expr','expr',3,'p_expr_equiv','parser.py',105),
|
|
32
|
+
('expr -> expr IMPLY expr','expr',3,'p_expr_imply','parser.py',109),
|
|
33
|
+
('expr -> expr OR expr','expr',3,'p_expr_or','parser.py',113),
|
|
34
|
+
('expr -> expr AND expr','expr',3,'p_expr_and','parser.py',117),
|
|
35
|
+
('expr -> NOT expr','expr',2,'p_expr_not','parser.py',121),
|
|
36
|
+
('expr -> expr EQ expr','expr',3,'p_expr_cmp','parser.py',128),
|
|
37
|
+
('expr -> expr LT expr','expr',3,'p_expr_cmp','parser.py',129),
|
|
38
|
+
('expr -> expr GT expr','expr',3,'p_expr_cmp','parser.py',130),
|
|
39
|
+
('expr -> expr LE expr','expr',3,'p_expr_cmp','parser.py',131),
|
|
40
|
+
('expr -> expr GE expr','expr',3,'p_expr_cmp','parser.py',132),
|
|
41
|
+
('expr -> expr PLUS expr','expr',3,'p_expr_add','parser.py',146),
|
|
42
|
+
('expr -> expr MINUS expr','expr',3,'p_expr_add','parser.py',147),
|
|
43
|
+
('expr -> expr TIMES expr','expr',3,'p_expr_mul','parser.py',154),
|
|
44
|
+
('expr -> expr DIV expr','expr',3,'p_expr_mul','parser.py',155),
|
|
45
|
+
('expr -> expr DOT expr','expr',3,'p_expr_mul','parser.py',156),
|
|
46
|
+
('expr -> expr POW expr','expr',3,'p_expr_pow','parser.py',165),
|
|
47
|
+
('expr -> MINUS expr','expr',2,'p_expr_uminus','parser.py',172),
|
|
48
|
+
('expr -> PLUS expr','expr',2,'p_expr_uplus','parser.py',176),
|
|
49
|
+
('expr -> atom','expr',1,'p_expr_atom','parser.py',183),
|
|
50
|
+
('expr -> LPAREN expr RPAREN','expr',3,'p_expr_paren','parser.py',187),
|
|
51
|
+
('expr -> LBRACK expr_list RBRACK','expr',3,'p_expr_list','parser.py',191),
|
|
52
|
+
('expr -> LBRACK RBRACK','expr',2,'p_expr_list_single','parser.py',195),
|
|
53
|
+
('expr_list -> expr_list COMMA expr','expr_list',3,'p_expr_list_list','parser.py',199),
|
|
54
|
+
('expr_list -> expr','expr_list',1,'p_expr_list_item','parser.py',203),
|
|
55
|
+
('expr -> VARIABLE LPAREN expr_list RPAREN','expr',4,'p_expr_func','parser.py',207),
|
|
56
|
+
('atom -> VARIABLE','atom',1,'p_atom_var','parser.py',214),
|
|
57
|
+
('atom -> CAPITAL_ID','atom',1,'p_atom_var','parser.py',215),
|
|
58
|
+
('atom -> NUMBER','atom',1,'p_atom_var','parser.py',216),
|
|
59
|
+
('atom -> CNUMBER','atom',1,'p_atom_var','parser.py',217),
|
|
60
|
+
('atom -> STRING','atom',1,'p_atom_var','parser.py',218),
|
|
61
|
+
]
|
mathai-0.6.0/mathai/matrix.py
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
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]
|
|
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
|