mathai 0.5.4__py3-none-any.whl → 0.5.5__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 CHANGED
@@ -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 solve, simplify, solve2
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
 
mathai/base.py CHANGED
@@ -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 isinstance(a, Fraction) and isinstance(b, Fraction) and b.denominator==1:
158
- if a == 0 and b <= 0:
159
- return None
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
- output.append(child.children[0]**-1)
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
- t = item
252
- if t.name == "f_pow" and "v_" not in str_form(t.children[1]) and compute(t.children[1]) < 0:
253
-
254
- den = den*item
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 [num, tree_form("d_1")/den]
303
+ return num, den
258
304
 
259
305
  def summation(lst):
260
306
  if len(lst) == 0:
mathai/diff.py CHANGED
@@ -1,9 +1,9 @@
1
- from .simplify import solve
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 = solve(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 solve(equation)
68
+ return simplify(equation)
mathai/expand.py CHANGED
@@ -1,96 +1,124 @@
1
1
  import itertools
2
2
  from .base import *
3
- from .simplify import solve, simplify
4
-
5
- def expand(eq):
6
- if eq is None:
7
- return None
8
-
9
- stack = [(eq, 0)] # (node, stage)
10
- result_map = {} # id(node) -> expanded TreeNode
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, [])]
11
48
 
12
49
  while stack:
13
- node, stage = stack.pop()
14
- node_id = id(node)
15
-
16
- # Leaf node
17
- if not node.children and stage == 0:
18
- result_map[node_id] = TreeNode(node.name, [])
19
- continue
20
-
21
- if stage == 0:
22
- # Stage 0: push node back for stage 1 after children
23
- stack.append((node, 1))
24
- # Push children to stack
25
- for child in reversed(node.children):
26
- if id(child) not in result_map:
27
- stack.append((child, 0))
28
- else:
29
- # Stage 1: all children processed
30
- children_expanded = [result_map[id(child)] for child in node.children]
31
-
32
- # Only f_mul or f_pow need special expansion
33
- if node.name in ["f_mul", "f_pow"]:
34
- current_eq = TreeNode(node.name, children_expanded)
35
-
36
- if node.name == "f_pow":
37
- current_eq = TreeNode("f_pow", [current_eq])
38
-
39
- ac = []
40
- addchild = []
41
-
42
- for child in current_eq.children:
43
- tmp5 = [solve(x) for x in factor_generation(child)]
44
- ac += tmp5
45
-
46
- tmp3 = []
47
- for child in ac:
48
- tmp2 = []
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):
49
78
  if child.name == "f_add":
50
- if child.children != []:
51
- tmp2.extend(child.children)
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])
52
85
  else:
53
- tmp2 = [child]
86
+ lone_children = lone_children * child
54
87
  else:
55
- tmp3.append(child)
56
- if tmp2 != []:
57
- addchild.append(tmp2)
58
-
59
- tmp4 = 1
60
- for item in tmp3:
61
- tmp4 = tmp4 * item
62
- addchild.append([tmp4])
63
-
64
- def flatten(lst):
65
- flat_list = []
66
- for item in lst:
67
- if isinstance(item, list) and item == []:
68
- continue
69
- if isinstance(item, list):
70
- flat_list.extend(flatten(item))
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
71
100
  else:
72
- flat_list.append(item)
73
- return flat_list
101
+ tmp = tmp + bc * lone_children
102
+ # Simplify after each distribution
103
+ lone_children = flatten_tree(simplify(tmp))
74
104
 
75
- if len(flatten(addchild)) > 0:
76
- add = 0
77
- for prod_items in itertools.product(*addchild):
78
- mul = 1
79
- for item2 in prod_items:
80
- mul = mul * item2
81
- mul = simplify(mul)
82
- add = add + mul
83
- add = simplify(add)
84
- current_eq = simplify(add)
85
- else:
86
- current_eq = simplify(current_eq)
105
+ node = lone_children
87
106
 
88
- # Store expanded result
89
- result_map[node_id] = current_eq
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))
90
112
  else:
91
- # Default: reconstruct node with children
92
- result_map[node_id] = TreeNode(node.name, children_expanded)
113
+ # Root node fully expanded
114
+ return node
93
115
 
94
- # Return final expanded eq
95
- return result_map[id(eq)]
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, []))
96
122
 
123
+ def expand(eq):
124
+ return _expand(eq)
mathai/factor.py CHANGED
@@ -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,solve
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 solve(term_common2(eq))
35
- return solve(product([term_common2(item) for item in factor_generation(eq)]))
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(solve(summation([item2 for index, item2 in enumerate(eq.children) if index not in item]) + eq2))
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
- hcf = math.gcd(hcf, num)
60
- return hcf
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
- u = (-q/2+t**(tree_form("d_2")**-1))**(tree_form("d_3")**-1)
241
- v = (-q/2-t**(tree_form("d_2")**-1))**(tree_form("d_3")**-1)
242
- y1 = u+v
243
- three = 3**(tree_form("d_2")**-1)
244
- y2 = -(u+v)/2+tree_form("s_i")*three*(u-v)/2
245
- y3 = -(u+v)/2-tree_form("s_i")*three*(u-v)/2
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,x2, x3 = simplify(x1), simplify(x2), simplify(x3)
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(solve(out))
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 solve(take_common2(simplify(equation)))
298
+ return simplify(take_common2(simplify(equation)))
299
+
281
300
  def factor2(equation, complexnum=False):
282
- return solve(factor_helper(solve(factor_helper(simplify(factor_helper(simplify(equation), complexnum, 2)), complexnum, 3)), complexnum, 4))
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))
mathai/fraction.py CHANGED
@@ -1,5 +1,5 @@
1
1
  from .base import *
2
- from .simplify import solve, simplify
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 solve(result_map[eq])
103
+ return simplify(result_map[eq])
mathai/integrate.py CHANGED
@@ -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 solve, simplify
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 = solve(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 = solve(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 expr_str.count("f_sin") + expr_str.count("f_cos") > 2:
446
- out = transform_formula(integrand, wrt.name, formula_gen4[0], formula_gen4[1], formula_gen4[2])
447
- if out is not None:
448
-
449
- return out
450
- if "f_cos" in expr_str and contain(integrand, tree_form("s_e")):
451
- out = transform_formula(integrand, wrt.name, formula_gen11[0], formula_gen11[1], formula_gen11[2])
452
- if out is not None:
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])
mathai/inverse.py CHANGED
@@ -1,5 +1,5 @@
1
1
  from .base import *
2
- from .simplify import solve
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 = solve(expand(rhs*term**-1))
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 solve(lhs)
65
- return solve(lhs), sign
64
+ return simplify(lhs)
65
+ return simplify(lhs), sign
mathai/limit.py CHANGED
@@ -1,7 +1,7 @@
1
1
  from .structure import structure
2
2
  from .base import *
3
3
  from .parser import parse
4
- from .simplify import simplify, solve
4
+ from .simplify import simplify
5
5
  from .expand import expand
6
6
  from .diff import diff
7
7
  from .trig import trig0
mathai/linear.py CHANGED
@@ -1,7 +1,7 @@
1
1
  from .inverse import inverse
2
2
  import itertools
3
3
  from .diff import diff
4
- from .simplify import simplify, solve
4
+ from .simplify import simplify
5
5
  from .fraction import fraction
6
6
  from .expand import expand
7
7
  from .base import *
mathai/logic.py CHANGED
@@ -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