mathai 0.5.4__tar.gz → 0.5.5__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.5.4 → mathai-0.5.5}/PKG-INFO +1 -1
- {mathai-0.5.4 → mathai-0.5.5}/mathai/__init__.py +3 -3
- {mathai-0.5.4 → mathai-0.5.5}/mathai/base.py +63 -17
- {mathai-0.5.4 → mathai-0.5.5}/mathai/diff.py +3 -3
- mathai-0.5.5/mathai/expand.py +124 -0
- {mathai-0.5.4 → mathai-0.5.5}/mathai/factor.py +43 -21
- {mathai-0.5.4 → mathai-0.5.5}/mathai/fraction.py +2 -2
- {mathai-0.5.4 → mathai-0.5.5}/mathai/integrate.py +19 -15
- {mathai-0.5.4 → mathai-0.5.5}/mathai/inverse.py +4 -4
- {mathai-0.5.4 → mathai-0.5.5}/mathai/limit.py +1 -1
- {mathai-0.5.4 → mathai-0.5.5}/mathai/linear.py +1 -1
- {mathai-0.5.4 → mathai-0.5.5}/mathai/logic.py +7 -1
- {mathai-0.5.4 → mathai-0.5.5}/mathai/printeq.py +4 -4
- mathai-0.5.5/mathai/simplify.py +516 -0
- {mathai-0.5.4 → mathai-0.5.5}/mathai/structure.py +2 -2
- {mathai-0.5.4 → mathai-0.5.5}/mathai/tool.py +2 -2
- {mathai-0.5.4 → mathai-0.5.5}/mathai/trig.py +42 -25
- {mathai-0.5.4 → mathai-0.5.5}/mathai/univariate_inequality.py +11 -8
- {mathai-0.5.4 → mathai-0.5.5}/mathai.egg-info/PKG-INFO +1 -1
- {mathai-0.5.4 → mathai-0.5.5}/setup.py +1 -1
- mathai-0.5.4/mathai/expand.py +0 -96
- mathai-0.5.4/mathai/simplify.py +0 -408
- {mathai-0.5.4 → mathai-0.5.5}/README.md +0 -0
- {mathai-0.5.4 → mathai-0.5.5}/mathai/apart.py +0 -0
- {mathai-0.5.4 → mathai-0.5.5}/mathai/bivariate_inequality.py +0 -0
- {mathai-0.5.4 → mathai-0.5.5}/mathai/console.py +0 -0
- {mathai-0.5.4 → mathai-0.5.5}/mathai/matrix.py +0 -0
- {mathai-0.5.4 → mathai-0.5.5}/mathai/ode.py +0 -0
- {mathai-0.5.4 → mathai-0.5.5}/mathai/parser.py +0 -0
- {mathai-0.5.4 → mathai-0.5.5}/mathai.egg-info/SOURCES.txt +0 -0
- {mathai-0.5.4 → mathai-0.5.5}/mathai.egg-info/dependency_links.txt +0 -0
- {mathai-0.5.4 → mathai-0.5.5}/mathai.egg-info/requires.txt +0 -0
- {mathai-0.5.4 → mathai-0.5.5}/mathai.egg-info/top_level.txt +0 -0
- {mathai-0.5.4 → mathai-0.5.5}/setup.cfg +0 -0
|
@@ -9,7 +9,7 @@ from .parser import parse
|
|
|
9
9
|
|
|
10
10
|
from .printeq import printeq, printeq_log, printeq_str
|
|
11
11
|
|
|
12
|
-
from .simplify import
|
|
12
|
+
from .simplify import simplify
|
|
13
13
|
|
|
14
14
|
from .integrate import ref as integrate_save
|
|
15
15
|
from .integrate import integrate_subs_main as integrate_subs
|
|
@@ -24,7 +24,7 @@ from .integrate import integrate_formula
|
|
|
24
24
|
from .diff import diff
|
|
25
25
|
|
|
26
26
|
from .factor import factor as factor1
|
|
27
|
-
from .factor import factor2
|
|
27
|
+
from .factor import factor2, factor3
|
|
28
28
|
from .factor import rationalize_sqrt as rationalize
|
|
29
29
|
from .factor import merge_sqrt
|
|
30
30
|
from .factor import factorconst as factor0
|
|
@@ -35,7 +35,7 @@ from .inverse import inverse
|
|
|
35
35
|
|
|
36
36
|
from .trig import trig0, trig1, trig2, trig3, trig4
|
|
37
37
|
|
|
38
|
-
from .logic import logic0, logic1, logic2, logic3
|
|
38
|
+
from .logic import logic0, logic1, logic2, logic3, logic_n
|
|
39
39
|
|
|
40
40
|
from .apart import apart, apart2
|
|
41
41
|
|
|
@@ -126,6 +126,44 @@ def remove_duplicates_custom(lst, rcustom):
|
|
|
126
126
|
if not any(rcustom(item, x) for x in result):
|
|
127
127
|
result.append(item)
|
|
128
128
|
return result
|
|
129
|
+
def frac_to_tree(f):
|
|
130
|
+
if isinstance(f, int):
|
|
131
|
+
f = Fraction(f)
|
|
132
|
+
if f.numerator == 0:
|
|
133
|
+
return tree_form("d_0")
|
|
134
|
+
if f.numerator == 1:
|
|
135
|
+
if f.denominator == 1:
|
|
136
|
+
return tree_form("d_1")
|
|
137
|
+
return tree_form("d_"+str(f.denominator))**tree_form("d_-1")
|
|
138
|
+
if f.denominator == 1:
|
|
139
|
+
return tree_form("d_"+str(f.numerator))
|
|
140
|
+
else:
|
|
141
|
+
return tree_form("d_"+str(f.numerator))/tree_form("d_"+str(f.denominator))
|
|
142
|
+
def perfect_root(n, r):
|
|
143
|
+
if r <= 0 or (n < 0 and r % 2 == 0):
|
|
144
|
+
return False, None
|
|
145
|
+
|
|
146
|
+
lo = 0
|
|
147
|
+
hi = n if n > 1 else 1
|
|
148
|
+
|
|
149
|
+
while lo <= hi:
|
|
150
|
+
mid = lo + (hi - lo) // 2
|
|
151
|
+
pow_val = 1
|
|
152
|
+
|
|
153
|
+
for _ in range(r):
|
|
154
|
+
pow_val *= mid
|
|
155
|
+
if pow_val > n:
|
|
156
|
+
break
|
|
157
|
+
|
|
158
|
+
if pow_val == n:
|
|
159
|
+
return True, mid
|
|
160
|
+
elif pow_val < n:
|
|
161
|
+
lo = mid + 1
|
|
162
|
+
else:
|
|
163
|
+
hi = mid - 1
|
|
164
|
+
|
|
165
|
+
return False, None
|
|
166
|
+
|
|
129
167
|
def frac(eq):
|
|
130
168
|
if eq.name[:2] == "d_":
|
|
131
169
|
return Fraction(int(eq.name[2:]))
|
|
@@ -154,12 +192,17 @@ def frac(eq):
|
|
|
154
192
|
if eq.name == "f_pow":
|
|
155
193
|
a = frac(eq.children[0])
|
|
156
194
|
b = frac(eq.children[1])
|
|
157
|
-
if
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
return a**b
|
|
161
|
-
else:
|
|
195
|
+
if a is None or b is None:
|
|
196
|
+
return None
|
|
197
|
+
if a == 0 and b <= 0:
|
|
162
198
|
return None
|
|
199
|
+
if b.denominator == 1:
|
|
200
|
+
return a ** b.numerator
|
|
201
|
+
found_c, c = perfect_root(a.numerator, b.denominator)
|
|
202
|
+
found_d, d = perfect_root(a.denominator, b.denominator)
|
|
203
|
+
if found_c and found_d:
|
|
204
|
+
return Fraction(c,d) ** b.numerator
|
|
205
|
+
return None
|
|
163
206
|
return None
|
|
164
207
|
def factor_generation(eq):
|
|
165
208
|
output = []
|
|
@@ -168,11 +211,6 @@ def factor_generation(eq):
|
|
|
168
211
|
if eq.name == "f_mul":
|
|
169
212
|
for child in eq.children:
|
|
170
213
|
if child.name == "f_pow":
|
|
171
|
-
'''
|
|
172
|
-
if child.children[0].name[:2] == "s_":
|
|
173
|
-
output.append(child)
|
|
174
|
-
continue
|
|
175
|
-
'''
|
|
176
214
|
if child.children[1].name[:2] != "d_":
|
|
177
215
|
output.append(child)
|
|
178
216
|
continue
|
|
@@ -180,7 +218,10 @@ def factor_generation(eq):
|
|
|
180
218
|
n = int(child.children[1].name[2:])
|
|
181
219
|
if n < 0:
|
|
182
220
|
for i in range(-n):
|
|
183
|
-
|
|
221
|
+
out = factor_generation(child.children[0])
|
|
222
|
+
out = [x**-1 for x in out]
|
|
223
|
+
output += out
|
|
224
|
+
#output.append(child.children[0]**-1)
|
|
184
225
|
else:
|
|
185
226
|
for i in range(n):
|
|
186
227
|
output.append(child.children[0])
|
|
@@ -247,14 +288,19 @@ def num_dem(equation):
|
|
|
247
288
|
num = tree_form("d_1")
|
|
248
289
|
den = tree_form("d_1")
|
|
249
290
|
for item in factor_generation(equation):
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
291
|
+
if item.name == "f_pow":
|
|
292
|
+
c = frac(item.children[1])
|
|
293
|
+
if c is not None and c < 0:
|
|
294
|
+
t = frac_to_tree(-c)
|
|
295
|
+
if t == tree_form("d_1"):
|
|
296
|
+
den = den * item.children[0]
|
|
297
|
+
else:
|
|
298
|
+
den = den * item.children[0]**t
|
|
299
|
+
else:
|
|
300
|
+
den = den * item
|
|
255
301
|
else:
|
|
256
302
|
num = num*item
|
|
257
|
-
return
|
|
303
|
+
return num, den
|
|
258
304
|
|
|
259
305
|
def summation(lst):
|
|
260
306
|
if len(lst) == 0:
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
from .simplify import
|
|
1
|
+
from .simplify import simplify
|
|
2
2
|
from .base import *
|
|
3
3
|
from .trig import trig0
|
|
4
4
|
def diff(equation, var="v_0"):
|
|
5
5
|
def diffeq(eq):
|
|
6
|
-
eq =
|
|
6
|
+
eq = simplify(eq)
|
|
7
7
|
if "v_" not in str_form(eq):
|
|
8
8
|
return tree_form("d_0")
|
|
9
9
|
if eq.name == "f_add":
|
|
@@ -65,4 +65,4 @@ def diff(equation, var="v_0"):
|
|
|
65
65
|
return TreeNode(equation.name, [helper(child, var) for child in equation.children])
|
|
66
66
|
equation = diffeq(trig0(equation))
|
|
67
67
|
equation = helper(equation, var)
|
|
68
|
-
return
|
|
68
|
+
return simplify(equation)
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import itertools
|
|
2
|
+
from .base import *
|
|
3
|
+
from .simplify import simplify
|
|
4
|
+
'''
|
|
5
|
+
def _expand(equation):
|
|
6
|
+
eq = equation
|
|
7
|
+
eq.children = [_expand(flatten_tree(child)) for child in eq.children]
|
|
8
|
+
if eq.name == "f_pow":
|
|
9
|
+
n = frac(eq.children[1])
|
|
10
|
+
if n is not None and n.denominator == 1 and n.numerator > 1:
|
|
11
|
+
power_children = []
|
|
12
|
+
for i in range(n.numerator):
|
|
13
|
+
power_children.append(eq.children[0])
|
|
14
|
+
return _expand(flatten_tree(TreeNode("f_mul", power_children)))
|
|
15
|
+
if eq.name == "f_mul":
|
|
16
|
+
lone_children = tree_form("d_1")
|
|
17
|
+
bracket_children = []
|
|
18
|
+
for i in range(len(eq.children)-1,-1,-1):
|
|
19
|
+
if eq.children[i].name == "f_add":
|
|
20
|
+
bracket_children.append(eq.children[i])
|
|
21
|
+
elif eq.children[i].name == "f_pow" and eq.children[i].children[0].name == "f_add":
|
|
22
|
+
n = frac(eq.children[i].children[1])
|
|
23
|
+
if n is not None and n.denominator == 1 and n.numerator > 1:
|
|
24
|
+
for j in range(n.numerator):
|
|
25
|
+
bracket_children.append(eq.children[i].children[0])
|
|
26
|
+
else:
|
|
27
|
+
lone_children = lone_children * eq.children[i]
|
|
28
|
+
else:
|
|
29
|
+
lone_children = lone_children * eq.children[i]
|
|
30
|
+
lone_children = simplify(lone_children)
|
|
31
|
+
while bracket_children != []:
|
|
32
|
+
tmp = tree_form("d_0")
|
|
33
|
+
for i in range(len(bracket_children[0].children)):
|
|
34
|
+
if lone_children.name == "f_add":
|
|
35
|
+
for j in range(len(lone_children.children)):
|
|
36
|
+
tmp = tmp + bracket_children[0].children[i] * lone_children.children[j]
|
|
37
|
+
else:
|
|
38
|
+
tmp = tmp + lone_children * bracket_children[0].children[i]
|
|
39
|
+
lone_children = flatten_tree(simplify(tmp))
|
|
40
|
+
bracket_children.pop(0)
|
|
41
|
+
return lone_children
|
|
42
|
+
return eq
|
|
43
|
+
'''
|
|
44
|
+
def _expand(equation):
|
|
45
|
+
"""Iterative version of _expand without recursion."""
|
|
46
|
+
# Stack: (node, child_index, partially_processed_children)
|
|
47
|
+
stack = [(equation, 0, [])]
|
|
48
|
+
|
|
49
|
+
while stack:
|
|
50
|
+
node, child_index, processed_children = stack.pop()
|
|
51
|
+
|
|
52
|
+
# If all children are processed
|
|
53
|
+
if child_index >= len(node.children):
|
|
54
|
+
# Replace children with processed versions
|
|
55
|
+
node.children = processed_children
|
|
56
|
+
|
|
57
|
+
# === Handle f_pow ===
|
|
58
|
+
if node.name == "f_pow":
|
|
59
|
+
n = frac(node.children[1])
|
|
60
|
+
if n is not None and n.denominator == 1 and n.numerator > 1:
|
|
61
|
+
# Convert power to repeated multiplication
|
|
62
|
+
power_children = [node.children[0] for _ in range(n.numerator)]
|
|
63
|
+
new_node = TreeNode("f_mul", power_children)
|
|
64
|
+
# Flatten tree
|
|
65
|
+
node = flatten_tree(new_node)
|
|
66
|
+
# Push it back for further processing
|
|
67
|
+
stack.append((node, 0, []))
|
|
68
|
+
continue
|
|
69
|
+
|
|
70
|
+
# === Handle f_mul ===
|
|
71
|
+
elif node.name == "f_mul":
|
|
72
|
+
# Separate lone children and bracket children
|
|
73
|
+
lone_children = tree_form("d_1")
|
|
74
|
+
bracket_children = []
|
|
75
|
+
|
|
76
|
+
# Iterate in reverse (like original)
|
|
77
|
+
for child in reversed(node.children):
|
|
78
|
+
if child.name == "f_add":
|
|
79
|
+
bracket_children.append(child)
|
|
80
|
+
elif child.name == "f_pow" and child.children[0].name == "f_add":
|
|
81
|
+
n = frac(child.children[1])
|
|
82
|
+
if n is not None and n.denominator == 1 and n.numerator > 1:
|
|
83
|
+
for _ in range(n.numerator):
|
|
84
|
+
bracket_children.append(child.children[0])
|
|
85
|
+
else:
|
|
86
|
+
lone_children = lone_children * child
|
|
87
|
+
else:
|
|
88
|
+
lone_children = lone_children * child
|
|
89
|
+
|
|
90
|
+
lone_children = simplify(lone_children)
|
|
91
|
+
|
|
92
|
+
# Distribute bracket children over lone children iteratively
|
|
93
|
+
while bracket_children:
|
|
94
|
+
tmp = tree_form("d_0")
|
|
95
|
+
bracket = bracket_children.pop(0)
|
|
96
|
+
for bc in bracket.children:
|
|
97
|
+
if lone_children.name == "f_add":
|
|
98
|
+
for lc in lone_children.children:
|
|
99
|
+
tmp = tmp + bc * lc
|
|
100
|
+
else:
|
|
101
|
+
tmp = tmp + bc * lone_children
|
|
102
|
+
# Simplify after each distribution
|
|
103
|
+
lone_children = flatten_tree(simplify(tmp))
|
|
104
|
+
|
|
105
|
+
node = lone_children
|
|
106
|
+
|
|
107
|
+
# === Return node to parent ===
|
|
108
|
+
if stack:
|
|
109
|
+
parent, idx, parent_children = stack.pop()
|
|
110
|
+
parent_children.append(node)
|
|
111
|
+
stack.append((parent, idx + 1, parent_children))
|
|
112
|
+
else:
|
|
113
|
+
# Root node fully expanded
|
|
114
|
+
return node
|
|
115
|
+
|
|
116
|
+
else:
|
|
117
|
+
# Push current node back for next child
|
|
118
|
+
stack.append((node, child_index, processed_children))
|
|
119
|
+
# Push the child to process next
|
|
120
|
+
child = flatten_tree(node.children[child_index])
|
|
121
|
+
stack.append((child, 0, []))
|
|
122
|
+
|
|
123
|
+
def expand(eq):
|
|
124
|
+
return _expand(eq)
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import itertools
|
|
2
|
+
from .trig import trig0
|
|
2
3
|
from .parser import parse
|
|
3
4
|
from .structure import transform_formula
|
|
4
5
|
from .base import *
|
|
5
|
-
from .simplify import simplify
|
|
6
|
+
from .simplify import simplify
|
|
6
7
|
from .expand import expand
|
|
7
8
|
import math
|
|
8
9
|
from .tool import poly
|
|
9
|
-
|
|
10
|
+
from .fraction import fraction
|
|
11
|
+
from .printeq import printeq
|
|
10
12
|
from collections import Counter
|
|
11
13
|
def multiset_intersection(*lists):
|
|
12
14
|
counters = list(map(Counter, lists))
|
|
@@ -31,8 +33,8 @@ def term_common2(eq):
|
|
|
31
33
|
return product(s)*summation([product(subtract_sublist(factor_generation(child), s)) for child in eq.children])
|
|
32
34
|
def term_common(eq):
|
|
33
35
|
if eq.name == "f_add":
|
|
34
|
-
return
|
|
35
|
-
return
|
|
36
|
+
return simplify(term_common2(eq))
|
|
37
|
+
return simplify(product([term_common2(item) for item in factor_generation(eq)]))
|
|
36
38
|
def take_common(eq):
|
|
37
39
|
if eq.name == "f_add":
|
|
38
40
|
eq = term_common(eq)
|
|
@@ -42,7 +44,7 @@ def take_common(eq):
|
|
|
42
44
|
eq2 = summation([item2 for index, item2 in enumerate(eq.children) if index in item])
|
|
43
45
|
eq2 = term_common(eq2)
|
|
44
46
|
if eq2.name == "f_mul":
|
|
45
|
-
return take_common(
|
|
47
|
+
return take_common(simplify(summation([item2 for index, item2 in enumerate(eq.children) if index not in item]) + eq2))
|
|
46
48
|
break
|
|
47
49
|
return eq
|
|
48
50
|
return term_common(eq)
|
|
@@ -54,10 +56,13 @@ def _factorconst(eq):
|
|
|
54
56
|
def hcf_list(numbers):
|
|
55
57
|
if not numbers:
|
|
56
58
|
return None # empty list
|
|
59
|
+
n = 1
|
|
57
60
|
hcf = numbers[0]
|
|
58
61
|
for num in numbers[1:]:
|
|
59
|
-
|
|
60
|
-
|
|
62
|
+
if num < 0:
|
|
63
|
+
n = -1
|
|
64
|
+
hcf = math.gcd(hcf, abs(num))
|
|
65
|
+
return hcf*n
|
|
61
66
|
def extractnum(eq):
|
|
62
67
|
lst = factor_generation(eq)
|
|
63
68
|
for item in lst:
|
|
@@ -226,8 +231,8 @@ def factor_helper(equation, complexnum, power=2):
|
|
|
226
231
|
a, b, c = lst
|
|
227
232
|
x1 = (-b+(b**2 - 4*a*c)**(tree_form("d_2")**-1))/(2*a)
|
|
228
233
|
x2 = (-b-(b**2 - 4*a*c)**(tree_form("d_2")**-1))/(2*a)
|
|
229
|
-
x1 = simplify(x1)
|
|
230
|
-
x2 = simplify(x2)
|
|
234
|
+
x1 = expand(simplify(x1))
|
|
235
|
+
x2 = expand(simplify(x2))
|
|
231
236
|
eq2 = a*(tree_form(r)-x1)*(tree_form(r)-x2)
|
|
232
237
|
if not complexnum and (contain(x1, tree_form("s_i")) or contain(x2, tree_form("s_i"))):
|
|
233
238
|
success = False
|
|
@@ -237,14 +242,27 @@ def factor_helper(equation, complexnum, power=2):
|
|
|
237
242
|
p = C-(B**2)/3
|
|
238
243
|
q = 2*B**3/27-B*C/3+D
|
|
239
244
|
t = q**2/4+ p**3/27
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
245
|
+
|
|
246
|
+
if compute(t) > 0:
|
|
247
|
+
u = (-q/2+t**(tree_form("d_2")**-1))**(tree_form("d_3")**-1)
|
|
248
|
+
v = (-q/2-t**(tree_form("d_2")**-1))**(tree_form("d_3")**-1)
|
|
249
|
+
y1 = u+v
|
|
250
|
+
three = 3**(tree_form("d_2")**-1)
|
|
251
|
+
y2 = -(u+v)/2+tree_form("s_i")*three*(u-v)/2
|
|
252
|
+
y3 = -(u+v)/2-tree_form("s_i")*three*(u-v)/2
|
|
253
|
+
|
|
254
|
+
else:
|
|
255
|
+
ar = 2*(-p/3)**(tree_form("d_2")**-1)
|
|
256
|
+
phi = ((3*q/(2*p))*(-3/p)**(tree_form("d_2")**-1)).fx("arccos")
|
|
257
|
+
y1 = ar*(phi/3).fx("cos")
|
|
258
|
+
y2 = ar*((phi+2*tree_form("s_pi"))/3).fx("cos")
|
|
259
|
+
y3 = ar*((phi+4*tree_form("s_pi"))/3).fx("cos")
|
|
260
|
+
|
|
246
261
|
x1,x2,x3 = y1-B/3 , y2-B/3, y3-B/3
|
|
247
|
-
x1
|
|
262
|
+
x1 = simplify(trig0(simplify(x1)))
|
|
263
|
+
x2 = simplify(trig0(simplify(x2)))
|
|
264
|
+
x3 = simplify(trig0(simplify(x3)))
|
|
265
|
+
|
|
248
266
|
out2 = None
|
|
249
267
|
if not complexnum:
|
|
250
268
|
for item in itertools.combinations([x1,x2,x3],2):
|
|
@@ -252,7 +270,7 @@ def factor_helper(equation, complexnum, power=2):
|
|
|
252
270
|
out2 = (tree_form(r)-item[0])*(tree_form(r)-item[1])
|
|
253
271
|
break
|
|
254
272
|
if out2 is not None:
|
|
255
|
-
out2 = simplify(expand(simplify(out2)))
|
|
273
|
+
out2 = simplify(fraction(expand(simplify(out2))))
|
|
256
274
|
out3 = None
|
|
257
275
|
for item in [x1, x2, x3]:
|
|
258
276
|
if not contain(item,tree_form("s_i")):
|
|
@@ -266,17 +284,21 @@ def factor_helper(equation, complexnum, power=2):
|
|
|
266
284
|
equation = fx(eq2)
|
|
267
285
|
break
|
|
268
286
|
|
|
269
|
-
if power == 4:
|
|
287
|
+
if False and power == 4:
|
|
270
288
|
|
|
271
289
|
out = transform_formula(helper(equation), "v_0", formula_gen9[0], formula_gen9[1], formula_gen9[2])
|
|
272
290
|
|
|
273
291
|
if out is not None:
|
|
274
|
-
out = simplify(
|
|
292
|
+
out = simplify(out)
|
|
275
293
|
if out is not None and (complexnum or (not complexnum and not contain(out, tree_form("s_i")))):
|
|
276
294
|
return out
|
|
277
295
|
|
|
278
296
|
return TreeNode(equation.name, [factor_helper(child, complexnum, power) for child in equation.children])
|
|
279
297
|
def factor(equation):
|
|
280
|
-
return
|
|
298
|
+
return simplify(take_common2(simplify(equation)))
|
|
299
|
+
|
|
281
300
|
def factor2(equation, complexnum=False):
|
|
282
|
-
return
|
|
301
|
+
return simplify(factor_helper(simplify(equation), complexnum, 2))
|
|
302
|
+
|
|
303
|
+
def factor3(equation, complexnum=False):
|
|
304
|
+
return simplify(factor_helper(simplify(factor_helper(simplify(equation), complexnum, 2)), complexnum, 3))
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from .base import *
|
|
2
|
-
from .simplify import
|
|
2
|
+
from .simplify import simplify
|
|
3
3
|
from .expand import expand
|
|
4
4
|
|
|
5
5
|
def fraction(eq):
|
|
@@ -100,4 +100,4 @@ def fraction(eq):
|
|
|
100
100
|
result_map[node] = TreeNode(node.name, children_processed)
|
|
101
101
|
|
|
102
102
|
# Final return
|
|
103
|
-
return
|
|
103
|
+
return simplify(result_map[eq])
|
|
@@ -3,7 +3,7 @@ from .parser import parse
|
|
|
3
3
|
import itertools
|
|
4
4
|
from .diff import diff
|
|
5
5
|
from .fraction import fraction
|
|
6
|
-
from .simplify import
|
|
6
|
+
from .simplify import simplify
|
|
7
7
|
from .expand import expand
|
|
8
8
|
from .base import *
|
|
9
9
|
from .printeq import printeq_str
|
|
@@ -169,7 +169,7 @@ def integrate_subs(equation, term, v1, v2):
|
|
|
169
169
|
orig = equation.copy_tree()
|
|
170
170
|
none = TreeNode("f_integrate",[orig, tree_form(v1)])
|
|
171
171
|
origv2 = copy.deepcopy(v2)
|
|
172
|
-
equation =
|
|
172
|
+
equation = simplify(equation)
|
|
173
173
|
eq = equation
|
|
174
174
|
termeq = term
|
|
175
175
|
t = inverse(copy.deepcopy(termeq), v1)
|
|
@@ -187,13 +187,13 @@ def integrate_subs(equation, term, v1, v2):
|
|
|
187
187
|
|
|
188
188
|
eq2 = replace(diff(g, v1), tree_form(v1), t)
|
|
189
189
|
equation = eq/eq2
|
|
190
|
-
equation =
|
|
190
|
+
equation = simplify(equation)
|
|
191
191
|
|
|
192
192
|
if v1 in str_form(equation):
|
|
193
193
|
|
|
194
194
|
return none
|
|
195
195
|
|
|
196
|
-
return TreeNode("f_subs", [TreeNode("f_integrate", [simplify(equation), tree_form(origv2)]),tree_form(origv2) ,g])
|
|
196
|
+
return dowhile(TreeNode("f_subs", [TreeNode("f_integrate", [simplify(equation), tree_form(origv2)]),tree_form(origv2) ,g]), trig0)
|
|
197
197
|
|
|
198
198
|
def integrate_subs_main(equation):
|
|
199
199
|
if equation.name == "f_ref":
|
|
@@ -411,6 +411,7 @@ def rm_const(equation):
|
|
|
411
411
|
if eq2.name == "f_integrate" and contain(eq2.children[0], eq2.children[1]):
|
|
412
412
|
equation = eq2.children[0]
|
|
413
413
|
wrt = eq2.children[1]
|
|
414
|
+
|
|
414
415
|
lst = factor_generation(equation)
|
|
415
416
|
|
|
416
417
|
lst_const = [item for item in lst if not contain(item, wrt)]
|
|
@@ -426,6 +427,10 @@ def rm_const(equation):
|
|
|
426
427
|
equation = eq2
|
|
427
428
|
return TreeNode(equation.name, [rm_const(child) for child in equation.children])
|
|
428
429
|
|
|
430
|
+
def shorten(eq):
|
|
431
|
+
if eq.name.startswith("d_"):
|
|
432
|
+
return tree_form("d_0")
|
|
433
|
+
return TreeNode(eq.name, [shorten(child) for child in eq.children])
|
|
429
434
|
def integrate_formula(equation):
|
|
430
435
|
if equation.name == "f_ref":
|
|
431
436
|
return equation.copy_tree()
|
|
@@ -441,15 +446,14 @@ def integrate_formula(equation):
|
|
|
441
446
|
if out is not None:
|
|
442
447
|
|
|
443
448
|
return out
|
|
444
|
-
expr_str = str_form(integrand)
|
|
445
|
-
if
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
return out
|
|
449
|
+
expr_str = str_form(shorten(integrand))
|
|
450
|
+
if len(expr_str) < 30:
|
|
451
|
+
if expr_str.count("f_sin") + expr_str.count("f_cos") > 2:
|
|
452
|
+
out = transform_formula(integrand, wrt.name, formula_gen4[0], formula_gen4[1], formula_gen4[2])
|
|
453
|
+
if out is not None:
|
|
454
|
+
return out
|
|
455
|
+
if "f_cos" in expr_str and contain(integrand, tree_form("s_e")):
|
|
456
|
+
out = transform_formula(integrand, wrt.name, formula_gen11[0], formula_gen11[1], formula_gen11[2])
|
|
457
|
+
if out is not None:
|
|
458
|
+
return out
|
|
455
459
|
return TreeNode(eq2.name, [integrate_formula(child) for child in eq2.children])
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from .base import *
|
|
2
|
-
from .simplify import
|
|
2
|
+
from .simplify import simplify
|
|
3
3
|
from .expand import expand
|
|
4
4
|
def inverse(rhs,term, sign=None):
|
|
5
5
|
term = tree_form(term)
|
|
@@ -9,7 +9,7 @@ def inverse(rhs,term, sign=None):
|
|
|
9
9
|
while not rhs==term:
|
|
10
10
|
if rhs.name == "f_add":
|
|
11
11
|
if all(term in factor_generation(child) for child in rhs.children):
|
|
12
|
-
newrhs =
|
|
12
|
+
newrhs = simplify(expand(rhs*term**-1))
|
|
13
13
|
if not contain(newrhs, term):
|
|
14
14
|
rhs = term * newrhs
|
|
15
15
|
else:
|
|
@@ -61,5 +61,5 @@ def inverse(rhs,term, sign=None):
|
|
|
61
61
|
if count == 0:
|
|
62
62
|
return None
|
|
63
63
|
if sign is None:
|
|
64
|
-
return
|
|
65
|
-
return
|
|
64
|
+
return simplify(lhs)
|
|
65
|
+
return simplify(lhs), sign
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import itertools
|
|
2
2
|
from .base import *
|
|
3
|
-
|
|
3
|
+
def c(eq):
|
|
4
|
+
eq = logic1(eq)
|
|
5
|
+
eq = dowhile(eq, logic0)
|
|
6
|
+
eq = dowhile(eq, logic2)
|
|
7
|
+
return eq
|
|
8
|
+
def logic_n(eq):
|
|
9
|
+
return dowhile(eq, c)
|
|
4
10
|
def logic0(eq):
|
|
5
11
|
if eq.children is None or len(eq.children)==0:
|
|
6
12
|
return eq
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from .base import *
|
|
2
|
-
from .simplify import
|
|
2
|
+
from .simplify import simplify
|
|
3
3
|
import copy
|
|
4
4
|
from fractions import Fraction
|
|
5
5
|
def abstractexpr(eq):
|
|
@@ -11,14 +11,14 @@ def abstractexpr(eq):
|
|
|
11
11
|
|
|
12
12
|
lst = factor_generation(eq)
|
|
13
13
|
deno = [item.children[0]**int(item.children[1].name[3:]) for item in lst if item.name == "f_pow" and item.children[1].name[:3] == "d_-"]
|
|
14
|
-
if eq.name == "f_mul" and any(item
|
|
15
|
-
return
|
|
14
|
+
if eq.name == "f_mul" and any(frac(item) is not None and frac(item) < 0 for item in lst):
|
|
15
|
+
return simplify(-eq, False).fx("neg")
|
|
16
16
|
if deno != []:
|
|
17
17
|
|
|
18
18
|
num = [item for item in lst if item.name != "f_pow" or item.children[1].name[:3] != "d_-"]
|
|
19
19
|
if num == []:
|
|
20
20
|
num = [tree_form("d_1")]
|
|
21
|
-
return TreeNode("f_div", [
|
|
21
|
+
return TreeNode("f_div", [simplify(product(num), False), simplify(product(deno), False)])
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
return TreeNode(eq.name, [abstractexpr(child) for child in eq.children])
|