mathai 0.1.4__tar.gz → 0.1.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.
Files changed (27) hide show
  1. {mathai-0.1.4 → mathai-0.1.5}/PKG-INFO +1 -1
  2. {mathai-0.1.4 → mathai-0.1.5}/mathai/__init__.py +3 -3
  3. {mathai-0.1.4 → mathai-0.1.5}/mathai/apart.py +1 -1
  4. {mathai-0.1.4 → mathai-0.1.5}/mathai/console.py +6 -2
  5. {mathai-0.1.4 → mathai-0.1.5}/mathai/factor.py +11 -6
  6. {mathai-0.1.4 → mathai-0.1.5}/mathai/integrate.py +75 -20
  7. {mathai-0.1.4 → mathai-0.1.5}/mathai/simplify.py +13 -2
  8. {mathai-0.1.4 → mathai-0.1.5}/mathai.egg-info/PKG-INFO +1 -1
  9. {mathai-0.1.4 → mathai-0.1.5}/setup.py +1 -1
  10. {mathai-0.1.4 → mathai-0.1.5}/README.md +0 -0
  11. {mathai-0.1.4 → mathai-0.1.5}/mathai/base.py +0 -0
  12. {mathai-0.1.4 → mathai-0.1.5}/mathai/diff.py +0 -0
  13. {mathai-0.1.4 → mathai-0.1.5}/mathai/expand.py +0 -0
  14. {mathai-0.1.4 → mathai-0.1.5}/mathai/fraction.py +0 -0
  15. {mathai-0.1.4 → mathai-0.1.5}/mathai/inverse.py +0 -0
  16. {mathai-0.1.4 → mathai-0.1.5}/mathai/linear.py +0 -0
  17. {mathai-0.1.4 → mathai-0.1.5}/mathai/logic.py +0 -0
  18. {mathai-0.1.4 → mathai-0.1.5}/mathai/parser.py +0 -0
  19. {mathai-0.1.4 → mathai-0.1.5}/mathai/printeq.py +0 -0
  20. {mathai-0.1.4 → mathai-0.1.5}/mathai/structure.py +0 -0
  21. {mathai-0.1.4 → mathai-0.1.5}/mathai/tool.py +0 -0
  22. {mathai-0.1.4 → mathai-0.1.5}/mathai/trig.py +0 -0
  23. {mathai-0.1.4 → mathai-0.1.5}/mathai.egg-info/SOURCES.txt +0 -0
  24. {mathai-0.1.4 → mathai-0.1.5}/mathai.egg-info/dependency_links.txt +0 -0
  25. {mathai-0.1.4 → mathai-0.1.5}/mathai.egg-info/requires.txt +0 -0
  26. {mathai-0.1.4 → mathai-0.1.5}/mathai.egg-info/top_level.txt +0 -0
  27. {mathai-0.1.4 → mathai-0.1.5}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: mathai
3
- Version: 0.1.4
3
+ Version: 0.1.5
4
4
  Summary: Mathematics solving Ai tailored to NCERT
5
5
  Home-page: https://github.com/infinity390/mathai4
6
6
  Author: educated indians are having a low iq and are good for nothing
@@ -1,10 +1,10 @@
1
1
  from .expand import expand
2
2
  from .parser import parse
3
- from .printeq import printeq, printeq_log
3
+ from .printeq import printeq, printeq_log, printeq_str
4
4
  from .simplify import solve, simplify
5
- from .integrate import integrate, typesqint
5
+ from .integrate import integrate, sqint, byparts
6
6
  from .diff import diff
7
- from .factor import factor
7
+ from .factor import factor, factor2
8
8
  from .fraction import fraction
9
9
  from .inverse import inverse
10
10
  from .trig import trig0, trig1, trig2, trig3, trig4
@@ -7,7 +7,7 @@ from .base import *
7
7
  import math
8
8
  from .tool import poly
9
9
 
10
- def apart(eq, v):
10
+ def apart(eq, v="v_0"):
11
11
  eq = simplify(eq)
12
12
  if eq.name != "f_mul":
13
13
  return eq
@@ -3,7 +3,7 @@ from .expand import expand
3
3
  from .parser import parse
4
4
  from .printeq import printeq, printeq_log
5
5
  from .simplify import solve, simplify
6
- from .integrate import integrate, typesqint
6
+ from .integrate import integrate, typesqint, typebyparts, typeintegrate
7
7
  from .diff import diff
8
8
  from .base import *
9
9
  from .factor import _factorconst, factor
@@ -58,9 +58,13 @@ def console():
58
58
  eq = simplify(eq)
59
59
  elif command == "fraction":
60
60
  eq = fraction(eq)
61
- elif command.split(" ")[0] in ["integrate", "sqint"]:
61
+ elif command.split(" ")[0] in ["integrate", "sqint", "byparts"]:
62
62
  if command.split(" ")[0] == "sqint":
63
63
  typesqint()
64
+ elif command.split(" ")[0] == "byparts":
65
+ typebyparts()
66
+ elif command.split(" ")[0] == "integrate":
67
+ typeintegrate()
64
68
  out = integrate(eq, parse(command.split(" ")[1]).name)
65
69
  if out is None:
66
70
  print("failed to integrate")
@@ -79,8 +79,9 @@ def factor_quad_formula_init():
79
79
  return [formula_list, var, expr]
80
80
 
81
81
  def factor_cube_formula_init():
82
- var = "x"
83
- formula_list = [(f"D^3+E", f"(D+E^(1/3))*(D^2-D*E^(1/3)+E^(2/3))"), (f"D^3-E", f"(D-E^(1/3))*(D^2+D*E^(1/3)+E^(2/3))")]
82
+ var = ""
83
+ formula_list = [(f"D^3+E", f"(D+E^(1/3))*(D^2-D*E^(1/3)+E^(2/3))"), (f"D^3-E", f"(D-E^(1/3))*(D^2+D*E^(1/3)+E^(2/3))"),\
84
+ (f"-D^3+E", f"(-D+E^(1/3))*(D^2+D*E^(1/3)+E^(2/3))")]
84
85
  formula_list = [[simplify(parse(y)) for y in x] for x in formula_list]
85
86
  expr = [[parse("A")], [parse("B")]]
86
87
  return [formula_list, var, expr]
@@ -101,8 +102,11 @@ def factor_helper(equation, complexnum, power=2):
101
102
  nonlocal maxnum
102
103
  if eq.name == "f_pow" and eq.children[1].name[:2] == "d_":
103
104
  n = int(eq.children[1].name[2:])
105
+ sgn = round(abs(n)/n)
106
+ n = abs(n)
104
107
  if n>power and n % power == 0 and maxnum==n:
105
- return (eq.children[0]**tree_form("d_"+str(int(n/power))))**power
108
+ out= (eq.children[0]**tree_form("d_"+str(sgn*int(n/power))))**power
109
+ return out
106
110
  return TreeNode(eq.name, [helper(child) for child in eq.children])
107
111
  high(equation)
108
112
  out = None
@@ -114,7 +118,8 @@ def factor_helper(equation, complexnum, power=2):
114
118
  out = simplify(solve(out))
115
119
  if out is not None and (complexnum or (not complexnum and not contain(out, tree_form("s_i")))):
116
120
  return out
117
- else:
118
- return TreeNode(equation.name, [factor_helper(child, complexnum, power) for child in equation.children])
121
+ return TreeNode(equation.name, [factor_helper(child, complexnum, power) for child in equation.children])
119
122
  def factor(equation, complexnum=False):
120
- return solve(take_common2(solve(factor_helper(simplify(solve(factor_helper(simplify(equation), complexnum, 2))), complexnum, 3))))
123
+ return solve(take_common2(simplify(factor_helper(simplify(equation), complexnum, 2))))
124
+ def factor2(equation, complexnum=False):
125
+ return solve(factor_helper(simplify(factor_helper(simplify(equation), complexnum, 2)), complexnum, 3))
@@ -9,8 +9,11 @@ from .printeq import printeq_str
9
9
  from .structure import transform_formula
10
10
  from .inverse import inverse
11
11
  from .tool import poly
12
+ from fractions import Fraction
13
+ from .printeq import printeq
12
14
  def integrate_summation(equation, wrt, tab, inf):
13
15
  logs= []
16
+ orig = copy.deepcopy(equation)
14
17
  for i in range(2):
15
18
 
16
19
  if equation.name == "f_add":
@@ -25,17 +28,23 @@ def integrate_summation(equation, wrt, tab, inf):
25
28
  return summation(answer), logs
26
29
  if i == 0:
27
30
 
28
- tmp = expand(equation)
31
+ tmp = expand(simplify(fraction(simplify(equation))))
32
+
29
33
  logs += [(tab, f"integrating {printeq_str(simplify(equation))} will be the same thing as integrating {printeq_str(simplify(tmp))}")]
34
+
30
35
  equation = tmp
36
+ if equation.name != "f_add" and orig != equation:
37
+ out = integrate(equation, wrt, tab+1, inf)
38
+ if out is None:
39
+ return None
40
+ return out[0], logs+out[1]
31
41
  return None
32
42
 
33
43
  def subs_heuristic(eq, var):
34
44
  output = []
35
45
  def collect2(eq):
36
- if eq.name == "f_pow" and eq.children[0] == tree_form(var) and eq.children[1].name[:2]=="d_":
37
- if int(eq.children[1].name[2:])==6:
38
- output.append(str_form( tree_form(var)**tree_form("d_3") ))
46
+ if eq.name == "f_pow" and frac(eq.children[1]) is not None and abs(frac(eq.children[1])) == Fraction(1,2):
47
+ output.append(str_form(eq.children[0].fx("sqrt")))
39
48
  if eq.name in ["f_pow", "f_sin", "f_cos", "f_arcsin"] and eq.children[0].name[:2] != "v_" and var in str_form(eq.children[0]):
40
49
  output.append(str_form(eq.children[0]))
41
50
  if eq.name == "f_pow" and eq.children[0].name == "s_e" and "v_" in str_form(eq):
@@ -54,10 +63,12 @@ def subs_heuristic(eq, var):
54
63
  if output == []:
55
64
  collect3(eq)
56
65
  tmp = sorted(output, key=lambda x: len(x))
57
- tmp = [solve(tree_form(x)) for x in tmp]
66
+ tmp = [simplify(tree_form(x)) for x in tmp]
67
+
58
68
  return tmp
59
69
 
60
70
  def integrate_subs(equation, term, v1, v2, tab, inf):
71
+
61
72
  origv2 = copy.deepcopy(v2)
62
73
  equation = solve(equation)
63
74
  eq = equation
@@ -83,6 +94,7 @@ def integrate_subs(equation, term, v1, v2, tab, inf):
83
94
  continue
84
95
 
85
96
  eq = expand(simplify(eq))
97
+
86
98
  out = integrate(eq, origv2, tab+1, inf)
87
99
 
88
100
  if out is None:
@@ -103,7 +115,7 @@ def integrate_subs_main(equation, wrt, tab, inf):
103
115
  if tmp3 is not None:
104
116
  return tmp3[0], tmp3[1]
105
117
  return None
106
- def sqint(equation, var, depth, inf):
118
+ def sqint(equation, var="v_0", depth=0, inf=0):
107
119
 
108
120
  logs = []
109
121
  def sgn(eq):
@@ -148,6 +160,7 @@ def sqint(equation, var, depth, inf):
148
160
  t1, t2 = sgn(const)
149
161
  la = s2**root
150
162
  lb = b*s2**root/(two*a)
163
+
151
164
  if mode:
152
165
  if s1 == one:
153
166
  if t1 == one:
@@ -162,9 +175,10 @@ def sqint(equation, var, depth, inf):
162
175
  return -k*((la*x+lb)/t2**root).fx("arctan")/(la * t2**root), logs
163
176
  if s1 == one:
164
177
  if t1 == one:
165
- return k*(la*x + lb + ((la*x + lb)**two + t2)**root).fx("abs").fx("log")/la, logs
178
+ return simplify(k*(la*x + lb + ((la*x + lb)**two + t2)**root).fx("abs").fx("log")/la), logs
166
179
  else:
167
- return k*(la*x + lb + ((la*x + lb)**two - t2)**root).fx("abs").fx("log")/la, logs
180
+ return simplify(k*(la*x + lb + ((la*x + lb)**two - t2)**root).fx("abs").fx("log")/la), logs
181
+
168
182
  else:
169
183
  if t1 == one:
170
184
  return k*((la*x + lb)/t2**root).fx("arcsin")/la, logs
@@ -191,7 +205,6 @@ def sqint(equation, var, depth, inf):
191
205
  else:
192
206
  log2 = tmp[1]
193
207
  tmp = tmp[0]
194
-
195
208
  return A*two*t**root + tmp*B, logs+log2
196
209
  else:
197
210
  tmp = sqint(simplify(one/t), var, depth, inf)
@@ -206,28 +219,65 @@ def sqint(equation, var, depth, inf):
206
219
  else:
207
220
  log2 = tmp[1]
208
221
  tmp = tmp[0]
209
-
210
222
  return A*t.fx("abs").fx("log") + tmp*B, logs+log2
211
223
  return None
224
+ typeint = "integrate"
225
+ def typeintegrate():
226
+ global typeint
227
+ typeint= "integrate"
228
+ def typesqint():
229
+ global typeint
230
+ typeint= "sqint"
231
+ def typebyparts():
232
+ global typeint
233
+ typeint= "byparts"
234
+ def byparts(eq, wrt="v_0", tab=0, inf=0):
235
+
236
+ lst = factor_generation(eq)
237
+ if len(lst) == 1:
238
+ lst += [tree_form("d_1")]
239
+ if len(lst) == 2:
240
+ for i in range(2):
241
+
242
+ f, g = copy.deepcopy([lst[i], lst[1-i]])
243
+
244
+ logs = [(tab, f"trying integration by parts, f = {printeq_str(simplify(f))} and g = {printeq_str(simplify(g))}")]
245
+ typeintegrate()
246
+ out1 = integrate(copy.deepcopy(g), wrt, tab+1, inf)
247
+ typebyparts()
248
+
249
+ if out1 is None:
250
+ continue
251
+
252
+ typeintegrate()
253
+ out2 = integrate(simplify(diff(copy.deepcopy(f), wrt)*out1[0]), wrt, tab+1, inf)
254
+
255
+ typebyparts()
256
+ if out2 is None:
257
+ continue
258
+
259
+ return copy.deepcopy([simplify(copy.deepcopy(f) * out1[0] - out2[0]), logs+out1[1]+out2[1]])
260
+ return None
212
261
  def integration_formula_init():
213
262
  var = "x"
214
263
  formula_list = [(f"(A*{var}+B)^C", f"(A*{var}+B)^(C+1)/(A*(C+1))"),\
215
264
  (f"sin(A*{var}+B)", f"-cos(A*{var}+B)/A"),\
216
265
  (f"cos(A*{var}+B)", f"sin(A*{var}+B)/A"),\
217
- (f"1/(A*{var}+B)", f"log(abs(A*{var}+B))/A")]
266
+ (f"1/(A*{var}+B)", f"log(abs(A*{var}+B))/A"),\
267
+ (f"e^(A*{var}+B)", f"e^(A*{var}+B)/A"),\
268
+ (f"abs(A*{var}+B)", f"(A*{var}+B)*abs(A*{var}+B)/(2*A)")]
218
269
  formula_list = [[simplify(parse(y)) for y in x] for x in formula_list]
219
270
  expr = [[parse("A"), parse("1")], [parse("B"), parse("0")]]
220
271
  return [formula_list, var, expr]
221
272
  formula_gen = integration_formula_init()
222
- typeint = "integrate"
223
- def typesqint():
224
- global typeint
225
- typeint= "sqint"
273
+
274
+
226
275
  def integrate(equation, wrt="v_0", tab=0, inf=0):
227
276
  global formula_list, var, expr
228
277
  global typeint
229
278
 
230
279
  equation = simplify(equation)
280
+
231
281
  logs = []
232
282
  if tab == 0:
233
283
  logs += [(tab, f"the given question is to integrate {printeq_str(simplify(equation))} wrt to {str(tree_form(wrt))}")]
@@ -245,9 +295,10 @@ def integrate(equation, wrt="v_0", tab=0, inf=0):
245
295
  if lst_const != []:
246
296
  equation = product([item for item in lst if contain(item, tree_form(wrt))])
247
297
  const = product(lst_const)
248
- if simplify(const) != 1:
298
+ const = simplify(const)
299
+ if const != 1 and not contain(const, tree_form("s_i")):
249
300
 
250
- equation = solve(equation)
301
+ equation = simplify(equation)
251
302
  out = integrate(equation, wrt, tab+1, inf)
252
303
 
253
304
  if out is None:
@@ -261,14 +312,18 @@ def integrate(equation, wrt="v_0", tab=0, inf=0):
261
312
  if out is not None:
262
313
  return out[0], logs+out[1]+[(tab, f"result is {printeq_str(simplify(out[0]))}")]
263
314
  out = None
264
- if typeint == "sqint":
315
+ if typeint in ["integrate", "sqint"]:
265
316
  out = sqint(equation, wrt, tab+1, inf)
266
317
  if out is not None:
267
318
  return out[0], logs+out[1]+[(tab, f"result is {printeq_str(simplify(out[0]))}")]
268
- elif typeint == "integrate":
319
+ if typeint == "integrate":
269
320
  if inf==0:
270
321
  out = integrate_subs_main(equation, wrt, tab, inf+1)
271
322
  if out is not None:
272
323
  return out[0], logs+out[1]+[(tab, f"result is {printeq_str(simplify(out[0]))}")]
273
-
324
+ if typeint == "byparts":
325
+
326
+ out = byparts(copy.deepcopy(equation), wrt, tab, inf)
327
+ if out is not None:
328
+ return out[0], logs+out[1]+[(tab, f"result is {printeq_str(simplify(out[0]))}")]
274
329
  return None
@@ -244,6 +244,12 @@ def simplify(eq):
244
244
  out = perfect_nth_root_value(n, r)
245
245
  if out is not None:
246
246
  return pp( tree_form("d_"+str(out)), f)
247
+ if eq.name == "f_mul" and len(eq.children)== 2:
248
+ for i in range(2):
249
+ if eq.children[i].name[:2] == "d_" and eq.children[1-i].name == "f_log":
250
+ return (eq.children[1-i].children[0]**eq.children[i]).fx("log")
251
+ if eq.name == "f_pow" and eq.children[0] == tree_form("s_e") and eq.children[1].name == "f_log":
252
+ return eq.children[1].children[0]
247
253
  if eq.name == "f_pow" and eq.children[0] == tree_form("d_1"):
248
254
  eq = tree_form("d_1")
249
255
  if eq.name == "f_pow" and eq.children[0] == tree_form("d_0"):
@@ -297,7 +303,12 @@ def simplify(eq):
297
303
  if eq.name == "f_pow" and eq.children[1].name[:2] == "d_" and abs(int(eq.children[1].name[2:]))%2==0 and eq.children[0].name == "f_abs":
298
304
  return eq.children[0].children[0]**eq.children[1]
299
305
  return TreeNode(eq.name, [helper5(child) for child in eq.children])
300
-
306
+ def helper8(eq):
307
+ if eq.name == "f_abs" and eq.children[0].name == "f_abs":
308
+ return eq.children[0]
309
+ if eq.name == "f_cos" and eq.children[0].name == "f_abs":
310
+ return eq.children[0].children[0].fx("cos")
311
+ return TreeNode(eq.name, [helper8(child) for child in eq.children])
301
312
  def fx1(eq):
302
313
  for item in [helper, helper3, helper4, helper6,solve,helper2,helper5]:
303
314
  eq = dowhile(eq, item)
@@ -311,5 +322,5 @@ def simplify(eq):
311
322
  eq = dowhile(eq, item)
312
323
  return eq
313
324
  eq = dowhile(eq, fx3)
314
-
325
+ eq = dowhile(eq, helper8)
315
326
  return solve(eq)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: mathai
3
- Version: 0.1.4
3
+ Version: 0.1.5
4
4
  Summary: Mathematics solving Ai tailored to NCERT
5
5
  Home-page: https://github.com/infinity390/mathai4
6
6
  Author: educated indians are having a low iq and are good for nothing
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="mathai",
5
- version="0.1.4",
5
+ version="0.1.5",
6
6
  description="Mathematics solving Ai tailored to NCERT",
7
7
  long_description=open("README.md").read(),
8
8
  long_description_content_type="text/markdown",
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