mathai 0.6.6__py3-none-any.whl → 0.6.8__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/base.py +2 -0
- mathai/expand.py +65 -60
- mathai/matrix.py +6 -1
- mathai/parser.py +2 -1
- mathai/simplify.py +2 -0
- {mathai-0.6.6.dist-info → mathai-0.6.8.dist-info}/METADATA +1 -1
- {mathai-0.6.6.dist-info → mathai-0.6.8.dist-info}/RECORD +9 -9
- {mathai-0.6.6.dist-info → mathai-0.6.8.dist-info}/WHEEL +0 -0
- {mathai-0.6.6.dist-info → mathai-0.6.8.dist-info}/top_level.txt +0 -0
mathai/base.py
CHANGED
mathai/expand.py
CHANGED
|
@@ -41,84 +41,89 @@ def _expand(equation):
|
|
|
41
41
|
return lone_children
|
|
42
42
|
return eq
|
|
43
43
|
'''
|
|
44
|
+
def is_expandable(child):
|
|
45
|
+
if child.name == "f_add":
|
|
46
|
+
return True
|
|
47
|
+
if child.name == "f_pow" and child.children[0].name == "f_add":
|
|
48
|
+
n = frac(child.children[1])
|
|
49
|
+
return n is not None and n.denominator == 1 and n.numerator > 1
|
|
50
|
+
return False
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def expand_terms(child):
|
|
54
|
+
if child.name == "f_add":
|
|
55
|
+
return child.children
|
|
56
|
+
n = frac(child.children[1]).numerator
|
|
57
|
+
return child.children[0].children * n
|
|
58
|
+
|
|
59
|
+
|
|
44
60
|
def _expand(equation):
|
|
45
|
-
"""Iterative version of _expand without recursion."""
|
|
46
|
-
# Stack: (node, child_index, partially_processed_children)
|
|
47
61
|
stack = [(equation, 0, [])]
|
|
48
62
|
|
|
49
63
|
while stack:
|
|
50
|
-
node,
|
|
64
|
+
node, idx, done = stack.pop()
|
|
51
65
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
# Replace children with processed versions
|
|
55
|
-
node.children = processed_children
|
|
66
|
+
if idx >= len(node.children):
|
|
67
|
+
node.children = done
|
|
56
68
|
|
|
57
|
-
#
|
|
69
|
+
# ===== f_pow =====
|
|
58
70
|
if node.name == "f_pow":
|
|
59
71
|
n = frac(node.children[1])
|
|
60
|
-
if n
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
# Flatten tree
|
|
65
|
-
node = flatten_tree(new_node)
|
|
66
|
-
# Push it back for further processing
|
|
72
|
+
if n and n.denominator == 1 and n.numerator > 1:
|
|
73
|
+
node = flatten_tree(
|
|
74
|
+
TreeNode("f_mul", [node.children[0]] * n.numerator)
|
|
75
|
+
)
|
|
67
76
|
stack.append((node, 0, []))
|
|
68
77
|
continue
|
|
69
78
|
|
|
70
|
-
#
|
|
79
|
+
# ===== f_mul =====
|
|
71
80
|
elif node.name == "f_mul":
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
node = lone_children
|
|
106
|
-
|
|
107
|
-
# === Return node to parent ===
|
|
81
|
+
children = node.children
|
|
82
|
+
k = len(children)
|
|
83
|
+
|
|
84
|
+
# ---- find expandable index (L→R, then R→L) ----
|
|
85
|
+
idxs = list(range(k)) + list(reversed(range(k)))
|
|
86
|
+
seen = set()
|
|
87
|
+
expand_i = None
|
|
88
|
+
|
|
89
|
+
for i in idxs:
|
|
90
|
+
if i in seen:
|
|
91
|
+
continue
|
|
92
|
+
seen.add(i)
|
|
93
|
+
if is_expandable(children[i]):
|
|
94
|
+
expand_i = i
|
|
95
|
+
break
|
|
96
|
+
|
|
97
|
+
if expand_i is not None:
|
|
98
|
+
left = children[:expand_i]
|
|
99
|
+
right = children[expand_i + 1:]
|
|
100
|
+
expandable = children[expand_i]
|
|
101
|
+
|
|
102
|
+
out = tree_form("d_0")
|
|
103
|
+
for term in expand_terms(expandable):
|
|
104
|
+
prod = term
|
|
105
|
+
for r in right:
|
|
106
|
+
prod = prod * r
|
|
107
|
+
for l in reversed(left):
|
|
108
|
+
prod = l * prod
|
|
109
|
+
out = out + prod
|
|
110
|
+
|
|
111
|
+
node = flatten_tree(simplify(out))
|
|
112
|
+
|
|
113
|
+
# ===== return =====
|
|
108
114
|
if stack:
|
|
109
|
-
parent,
|
|
110
|
-
|
|
111
|
-
stack.append((parent,
|
|
115
|
+
parent, pidx, acc = stack.pop()
|
|
116
|
+
acc.append(node)
|
|
117
|
+
stack.append((parent, pidx + 1, acc))
|
|
112
118
|
else:
|
|
113
|
-
# Root node fully expanded
|
|
114
119
|
return node
|
|
115
120
|
|
|
116
121
|
else:
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
# Push the child to process next
|
|
120
|
-
child = flatten_tree(node.children[child_index])
|
|
122
|
+
stack.append((node, idx, done))
|
|
123
|
+
child = flatten_tree(node.children[idx])
|
|
121
124
|
stack.append((child, 0, []))
|
|
122
125
|
|
|
123
126
|
def expand(eq):
|
|
127
|
+
if TreeNode.matmul == True:
|
|
128
|
+
eq = tree_form(str_form(eq).replace("f_wmul", "f_mul"))
|
|
124
129
|
return _expand(eq)
|
mathai/matrix.py
CHANGED
|
@@ -70,6 +70,10 @@ def contains_neg(node):
|
|
|
70
70
|
return True
|
|
71
71
|
# ---------- multiplication (fully simplified) ----------
|
|
72
72
|
def multiply(left,right):
|
|
73
|
+
if left == tree_form("d_1"):
|
|
74
|
+
return right
|
|
75
|
+
if right == tree_form("d_1"):
|
|
76
|
+
return left
|
|
73
77
|
left2, right2 = left, right
|
|
74
78
|
if left2.name != "f_pow":
|
|
75
79
|
left2 = left2 ** 1
|
|
@@ -217,7 +221,8 @@ def use(eq):
|
|
|
217
221
|
def _matrix_solve(eq):
|
|
218
222
|
if TreeNode.matmul == True:
|
|
219
223
|
TreeNode.matmul = False
|
|
220
|
-
eq =
|
|
224
|
+
eq = use(eq)
|
|
225
|
+
eq = dowhile(eq, lambda x: fold_wmul(flat(x)))
|
|
221
226
|
TreeNode.matmul = True
|
|
222
227
|
return eq
|
|
223
228
|
def matrix_solve(eq):
|
mathai/parser.py
CHANGED
|
@@ -152,11 +152,12 @@ def parse(equation, funclist=None):
|
|
|
152
152
|
return tree_form("v_" + str(int(tree_node.name[3:])+100))
|
|
153
153
|
tree_node.children = [rfx(child) for child in tree_node.children]
|
|
154
154
|
return tree_node
|
|
155
|
+
|
|
155
156
|
tree_node = rfx(tree_node)
|
|
156
157
|
tree_node = flatten_tree(tree_node, ["f_wmul"])
|
|
157
158
|
if TreeNode.matmul == True:
|
|
158
159
|
TreeNode.matmul = False
|
|
159
|
-
tree_node = tree_form(str_form(tree_node).replace("f_w","f_"))
|
|
160
|
+
tree_node = use(tree_form(str_form(tree_node).replace("f_w","f_")))
|
|
160
161
|
TreeNode.matmul = True
|
|
161
162
|
else:
|
|
162
163
|
tree_node = tree_form(str_form(tree_node).replace("f_w","f_"))
|
mathai/simplify.py
CHANGED
|
@@ -503,6 +503,8 @@ def simplify(eq, basic=True):
|
|
|
503
503
|
orig = TreeNode.matmul
|
|
504
504
|
if TreeNode.matmul == True:
|
|
505
505
|
TreeNode.matmul = False
|
|
506
|
+
eq = use(tree_form(str_form(eq).replace("f_w","f_")))
|
|
507
|
+
|
|
506
508
|
if eq.name == "f_and" or eq.name == "f_not" or eq.name == "f_or":
|
|
507
509
|
new_children = []
|
|
508
510
|
for child in eq.children:
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
mathai/__init__.py,sha256=gzddzgNCG3Bg5BnqrDYvO71SzK4hu9fbo4nGEaDaG5Q,1554
|
|
2
2
|
mathai/apart.py,sha256=VSS3khE9PNuxiRvdU5JDl4IN-KJBSIFjwR17pkhviXI,4197
|
|
3
|
-
mathai/base.py,sha256=
|
|
3
|
+
mathai/base.py,sha256=9TfeBem7rrPwuJAEhrD-a5Mqzd9a0z-5aDa90Sl6LHg,15655
|
|
4
4
|
mathai/bivariate_inequality.py,sha256=Da-A1kqVynR0tNOlEI7GSTf5T2vNkcF4etL9-EoyPJg,11415
|
|
5
5
|
mathai/console.py,sha256=Sn58iwYE79MLEh67s8X3q6vZjw6g7f9XM1T8_dBBR2o,3048
|
|
6
6
|
mathai/diff.py,sha256=RSTwlfeddvYXUDShCeRdcPjsmAS8Vf5OkYJAaUBPaiM,3060
|
|
7
|
-
mathai/expand.py,sha256=
|
|
7
|
+
mathai/expand.py,sha256=Bh9slVYXV9OAPSpTyuFWKVlJXqnN4eAF2z6y6MFjdGo,4799
|
|
8
8
|
mathai/factor.py,sha256=4NF2xep0TpS307Z8WaFGmVSjfDGjlpLUuzFJAJKjJn4,12522
|
|
9
9
|
mathai/fraction.py,sha256=88xvRpDGfFi8tbe1QIyejdSP91HcErrN4VS2MxzbhrY,4392
|
|
10
10
|
mathai/integrate.py,sha256=C_lqYgQN4UiriCb_LDkpwtKx7XJhp_K8T9skCkxWqas,17208
|
|
@@ -12,17 +12,17 @@ mathai/inverse.py,sha256=ya7P8WjzfaAL3UXL7xqOh5GaIsXLDZ-F6lZFy3IEgaQ,2931
|
|
|
12
12
|
mathai/limit.py,sha256=9F8i9UZh2xb-V8A5Sd1gdhDf9c2RFgpE1GdNn9MvbWI,5703
|
|
13
13
|
mathai/linear.py,sha256=viGlPU8BPrjLWHlyNUvnfPHNH5d4ZBImiQMdyXaKGg0,5702
|
|
14
14
|
mathai/logic.py,sha256=Ndz4Fd6aNCmzFlqoPyyIpSmV_BXmYHsurePjLyZJoNc,9809
|
|
15
|
-
mathai/matrix.py,sha256=
|
|
15
|
+
mathai/matrix.py,sha256=05GEi6K3hyu3UP_CFZfPnwDVIB52YGmlzCtCoZPh_iw,7305
|
|
16
16
|
mathai/ode.py,sha256=zxxTXAOpt7oSsfpgI4vHsCWKXevmM96ZOBZWWs-vj8Y,4801
|
|
17
|
-
mathai/parser.py,sha256=
|
|
17
|
+
mathai/parser.py,sha256=nEAdSSJeapBOhvjbkXJFtCEBU8izajXZAITV8rbslic,7314
|
|
18
18
|
mathai/parsetab.py,sha256=TL-4jvRM_Tx6ipwet8CFJc2DkjR4tGsbrGF_r4IC8xI,9651
|
|
19
19
|
mathai/printeq.py,sha256=MKsR6-qXig80R07vLnFPYHQMeS41FrMVj3n3arrhJpQ,1329
|
|
20
|
-
mathai/simplify.py,sha256=
|
|
20
|
+
mathai/simplify.py,sha256=J4M81rOuzgOrRElKAFR1dx1BD7zK2CfmgdWw8z-az2w,19796
|
|
21
21
|
mathai/structure.py,sha256=wrU7kqphSN7CqaVffyHHXD2-3t5My_Z_TtYFoUe_lTU,4099
|
|
22
22
|
mathai/tool.py,sha256=ozcXTXLbKUnyPM9r9kz9M43YA2CBcWezcqLZfEs8rpc,6051
|
|
23
23
|
mathai/trig.py,sha256=fnBbfiopcQzFg4ya1BoO5M0X_aCBnse2bjnKh1juw4I,11223
|
|
24
24
|
mathai/univariate_inequality.py,sha256=LPFdWgC1y5zBwnsy1wwZxj-yP_SbqFDhCmTTzhuwoiY,16469
|
|
25
|
-
mathai-0.6.
|
|
26
|
-
mathai-0.6.
|
|
27
|
-
mathai-0.6.
|
|
28
|
-
mathai-0.6.
|
|
25
|
+
mathai-0.6.8.dist-info/METADATA,sha256=qlUlg0g6-rOvYKNeanb7r4GDXdsOJYuN6qP_Jrd94gY,7103
|
|
26
|
+
mathai-0.6.8.dist-info/WHEEL,sha256=qELbo2s1Yzl39ZmrAibXA2jjPLUYfnVhUNTlyF1rq0Y,92
|
|
27
|
+
mathai-0.6.8.dist-info/top_level.txt,sha256=ROP4l3OhGYw3ihkQGASr18xM9GsK4z3_6whV5AyXLwE,7
|
|
28
|
+
mathai-0.6.8.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|