mathai 2.0.2__tar.gz → 2.0.4__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 (38) hide show
  1. {mathai-2.0.2 → mathai-2.0.4}/PKG-INFO +1 -1
  2. {mathai-2.0.2 → mathai-2.0.4}/mathai/__init__.py +1 -1
  3. {mathai-2.0.2 → mathai-2.0.4}/mathai/formula_compiler.py +10 -7
  4. {mathai-2.0.2 → mathai-2.0.4}/mathai/formula_data.py +18 -5
  5. {mathai-2.0.2 → mathai-2.0.4}/mathai/integrate.py +29 -17
  6. {mathai-2.0.2 → mathai-2.0.4}/mathai.egg-info/PKG-INFO +1 -1
  7. {mathai-2.0.2 → mathai-2.0.4}/setup.py +1 -1
  8. {mathai-2.0.2 → mathai-2.0.4}/README.md +0 -0
  9. {mathai-2.0.2 → mathai-2.0.4}/mathai/apart.py +0 -0
  10. {mathai-2.0.2 → mathai-2.0.4}/mathai/base.py +0 -0
  11. {mathai-2.0.2 → mathai-2.0.4}/mathai/decision.py +0 -0
  12. {mathai-2.0.2 → mathai-2.0.4}/mathai/diff.py +0 -0
  13. {mathai-2.0.2 → mathai-2.0.4}/mathai/expand.py +0 -0
  14. {mathai-2.0.2 → mathai-2.0.4}/mathai/factor.py +0 -0
  15. {mathai-2.0.2 → mathai-2.0.4}/mathai/fraction.py +0 -0
  16. {mathai-2.0.2 → mathai-2.0.4}/mathai/inverse.py +0 -0
  17. {mathai-2.0.2 → mathai-2.0.4}/mathai/lambda_calculus.py +0 -0
  18. {mathai-2.0.2 → mathai-2.0.4}/mathai/limit.py +0 -0
  19. {mathai-2.0.2 → mathai-2.0.4}/mathai/linear.py +0 -0
  20. {mathai-2.0.2 → mathai-2.0.4}/mathai/logic.py +0 -0
  21. {mathai-2.0.2 → mathai-2.0.4}/mathai/matrix.py +0 -0
  22. {mathai-2.0.2 → mathai-2.0.4}/mathai/ml.py +0 -0
  23. {mathai-2.0.2 → mathai-2.0.4}/mathai/mlscalar.py +0 -0
  24. {mathai-2.0.2 → mathai-2.0.4}/mathai/ode.py +0 -0
  25. {mathai-2.0.2 → mathai-2.0.4}/mathai/parser.py +0 -0
  26. {mathai-2.0.2 → mathai-2.0.4}/mathai/pde.py +0 -0
  27. {mathai-2.0.2 → mathai-2.0.4}/mathai/printeq.py +0 -0
  28. {mathai-2.0.2 → mathai-2.0.4}/mathai/qm.py +0 -0
  29. {mathai-2.0.2 → mathai-2.0.4}/mathai/simplify.py +0 -0
  30. {mathai-2.0.2 → mathai-2.0.4}/mathai/statistics.py +0 -0
  31. {mathai-2.0.2 → mathai-2.0.4}/mathai/test.py +0 -0
  32. {mathai-2.0.2 → mathai-2.0.4}/mathai/tool.py +0 -0
  33. {mathai-2.0.2 → mathai-2.0.4}/mathai/trig.py +0 -0
  34. {mathai-2.0.2 → mathai-2.0.4}/mathai/univariate_inequality.py +0 -0
  35. {mathai-2.0.2 → mathai-2.0.4}/mathai.egg-info/SOURCES.txt +0 -0
  36. {mathai-2.0.2 → mathai-2.0.4}/mathai.egg-info/dependency_links.txt +0 -0
  37. {mathai-2.0.2 → mathai-2.0.4}/mathai.egg-info/top_level.txt +0 -0
  38. {mathai-2.0.2 → mathai-2.0.4}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mathai
3
- Version: 2.0.2
3
+ Version: 2.0.4
4
4
  Summary: Mathematics solving Ai tailored to NCERT
5
5
  Home-page: https://github.com/infinity390/mathai
6
6
  Requires-Python: >=3.7
@@ -29,7 +29,7 @@ from .integrate import byparts as integrate_byparts
29
29
  from .integrate import sqint as integrate_fraction
30
30
  from .integrate import conv_int
31
31
  from .integrate import solve_integrate as integrate_clean
32
- from .integrate import integrate_formula, integrate_qm_formula, integrate_full, integrate_definite
32
+ from .integrate import integrate_formula, integrate_trig_formula, integrate_qm_formula, integrate_full, integrate_definite
33
33
  from .integrate import normalize as integration_basic
34
34
  from .integrate import normalize_qm as integration_qm_basic
35
35
 
@@ -3,6 +3,7 @@ import itertools
3
3
  from .base import *
4
4
  from .parser import parse
5
5
  from fractions import Fraction
6
+ from .simplify import simplify
6
7
  def simplify0_h(eq):
7
8
  if eq.name == "f_add":
8
9
  lst = [item for item in eq.children if item.name != "d_0"]
@@ -293,14 +294,14 @@ def structure(
293
294
  for key, item3 in varlist.items():
294
295
  local_pos = replace(local_pos, tree_form(key), item3)
295
296
  s = print_code2(local_pos)
296
- s = f"simplify0({s})==0 or (compute({s}) is not None and compute({s})>0)"
297
+ s = f"simplify({s})==0 or (compute({s}) is not None and compute({s})>0)"
297
298
  d.append(TreeNode(s))
298
299
  for item2 in negative:
299
300
  local_neg = copy.deepcopy(item2)
300
301
  for key, item3 in varlist.items():
301
302
  local_neg = replace(local_neg, tree_form(key), item3)
302
303
  s = print_code2(local_neg)
303
- s = f"simplify0({s})==0 or (compute({s}) is not None and compute({s})<0)"
304
+ s = f"simplify({s})==0 or (compute({s}) is not None and compute({s})<0)"
304
305
  d.append(TreeNode(s))
305
306
  if len(d) == 0:
306
307
  pass
@@ -319,10 +320,12 @@ def structure(
319
320
  local_formula_out = replace(
320
321
  local_formula_out, tree_form(key), item2
321
322
  )
322
- s = "\tif " + print_code(out2) + ":\n"
323
- u = "\t\tif " + print_code(out) + ":\n"
324
- t = "\t\t\treturn " + print_code2(local_formula_out) + "\n"
325
- final_output += s + u + t
323
+ out = TreeNode("f_wand", [out2, out])
324
+ s = "\tif " + print_code(out) + ":\n"
325
+ t = "\t\tout = simplify(" + print_code2(local_formula_out) + ")\n"
326
+ t2 = "\t\tif out is not None:\n"
327
+ t3 = "\t\t\treturn out\n"
328
+ final_output += s + t + t2 + t3
326
329
  return final_output
327
330
  def convert2(eq):
328
331
 
@@ -443,7 +446,7 @@ def formula_compiler(lst_formula):
443
446
  "contain": contain,
444
447
  "str_form": str_form,
445
448
  "copy":copy,
446
- "simplify0":simplify0,
449
+ "simplify":simplify,
447
450
  "compute":compute,
448
451
  "remove_all":remove_all,
449
452
  }
@@ -14,9 +14,10 @@ formula_data = {}
14
14
  # negative constraint
15
15
  # associative arity
16
16
  formula = """
17
- integrate(1/(a*x+b),x) log(abs(a*x+b))/a x _ [a,b] _ [a,0] _ _ 6
18
- integrate((a*x+b)^c,x) (a*x+b)^(c+1)/(a*(c+1)) x _ [a,b,c] _ [[a,0],[c,-1]] _ _ 1
19
- // dummy
17
+ a*x^2+b*x+c true x _ [a,b,c] _ [a,0] _ _ 2
18
+ a*x+b true x _ [a,b] _ [a,0] _ _ 4
19
+ a false _ _ _ _ _ _ _ 1
20
+ // is_integrate_subs
20
21
 
21
22
  integrate(x^2*e^(a*x+b),x) ((x^2/a)-(2*x/(a^2))+(2/(a^3)))*e^(a*x+b) x _ [a,b] _ [a,0] _ _ 6
22
23
  integrate(x*e^(a*x+b),x) ((x/a)-(1/(a^2)))*e^(a*x+b) x _ [a,b] _ [a,0] _ _ 6
@@ -37,6 +38,18 @@ integrate(a*b,x) a*integrate(b,x) x _ [a] _ [a,1] _ _ 6
37
38
  integrate(a+b,x) integrate(a,x)+integrate(b,x) x _ _ _ [[a,0],[b,0]] _ _ 6
38
39
  // integration
39
40
 
41
+ integrate(cos(a*x+b)/sin(a*x+b),x) log(abs(sin(a*x+b)))/a x _ [a,b] _ [a,0] _ _ 2
42
+ integrate(sin(a*x+b)/cos(a*x+b),x) -log(abs(cos(a*x+b)))/a x _ [a,b] _ [a,0] _ _ 2
43
+ integrate(sin(x)^a*cos(x)^b,x) -sin(x)^(a+1)*cos(x)^(b+1)/(b+1)+(a+b+2)/(b+1)*integrate(sin(x)^a*cos(x)^(b+2),x) x _ [a,b] _ [b,-1] a b 4
44
+ integrate((sin(x)/cos(x))^a,x) tan(x)^(a-1)/(a-1)-integrate((sin(x)/cos(x))^(a-2),x) x _ a _ [[a,1],[a,0]] a _ 4
45
+ integrate((cos(x)/sin(x))^a,x) -cot(x)^(a-1)/(a-1)-integrate((cos(x)/sin(x))^(a-2),x) x _ a _ [[a,1],[a,0]] a _ 4
46
+ integrate(sin(x)^a/cos(x),x) -sin(x)^(a-1)/(a-1)+integrate(sin(x)^(a-2)/cos(x),x) x _ a _ [[a,1],[a,0]] a _ 4
47
+ integrate(cos(x)^a/sin(x),x) cos(x)^(a-1)/(a-1)+integrate(cos(x)^(a-2)/sin(x),x) x _ a _ [[a,1],[a,0]] a _ 4
48
+ integrate(sin(x)^a*cos(x)^b,x) sin(x)^(a+1)*cos(x)^(b+1)/(a+1)-(a+b+2)/(a+1)*integrate(sin(x)^(a+2)*cos(x)^b,x) x _ [a,b] _ [a,-1] b a 4
49
+ integrate(sin(x)^a,x) cos(x)/((a+1)*sin(x)^(a+1))+(a+2)/(a+1)*integrate(sin(x)^(a+2),x) x _ a _ [[a,-1],[a,0]] _ a 4
50
+ integrate(cos(x)^a,x) -sin(x)/((a+1)*cos(x)^(a+1))+(a+2)/(a+1)*integrate(cos(x)^(a+2),x) x _ a _ [[a,-1],[a,0]] _ a 4
51
+ // integration_trig
52
+
40
53
  pdif(a^b,x) b*(a^(b-1))*pdif(a,x)+(a^b)*log(a)*pdif(b,x) x _ k _ _ _ _ 6
41
54
  pdif(sin(a),x) cos(a)*pdif(a,x) x _ k _ [[c,1],[d,1],[f,0],[g,0]] _ _ 2
42
55
  pdif(cos(a),x) -sin(a)*pdif(a,x) x _ k _ [[c,1],[d,1],[f,0],[g,0]] _ _ 2
@@ -114,7 +127,7 @@ a*x^2+b*x+c a*(x-(-b+sqrt(b^2-4*a*c))/(2*a))*(x-(-b-sqrt(b^2-4*a*c))/(2*a)) _ x
114
127
  """
115
128
 
116
129
  def load_formula(label):
117
- global formula_data
130
+ global formula_data
118
131
  return formula_data[label]
119
132
  def convert_lst(eq):
120
133
  if eq.name == "f_list":
@@ -144,7 +157,7 @@ def init_formula(label_list="all"):
144
157
  for item in formula.strip().split("\n\n"):
145
158
  item = item.split("\n")
146
159
  item[-1] = item[-1][3:]
147
- if label_list == "all" or item[-1] in label_list:
160
+ if label_list == "all" or item[-1] in label_list or (label_list == "god" and item[-1] in "is_integrate_subs integration_trig differentiation integration quadratic trigonometry_misc".split(" ")):
148
161
  formula_data[item[-1]] = compile_formula("\n".join(item[:-1]))
149
162
  print(f"{item[-1]} formula set compiled")
150
163
  print()
@@ -16,7 +16,13 @@ from .trig import trig0, trig2, trig3, trig4, trig1, trig5, trig6
16
16
  from .apart import apart, apart2
17
17
  from .univariate_inequality import wavycurvy, eq2range, range2eq2, Range
18
18
  from .printeq import *
19
-
19
+ def all_branch(eq):
20
+ if eq.children == []:
21
+ return []
22
+ out = [eq.name]
23
+ for child in eq.children:
24
+ out += all_branch(child)
25
+ return list(set(out))
20
26
  def subs_heuristic(eq, var):
21
27
  output = []
22
28
  last = []
@@ -27,6 +33,8 @@ def subs_heuristic(eq, var):
27
33
  if eq.name in ["f_pow"] and var.name in str_form(eq):
28
34
  if eq.children[1].name[:2] != "v_":
29
35
  output.append(str_form(eq))
36
+ if eq.name in ["f_arctan"] and var.name in str_form(eq.children[0]):
37
+ output.append(str_form(eq))
30
38
  if eq.name in ["f_pow", "f_sin", "f_cos", "f_arcsin"] and var.name in str_form(eq.children[0]):
31
39
  if eq.children[0].name[:2] != "v_":
32
40
  output.append(str_form(eq.children[0]))
@@ -52,21 +60,19 @@ def subs_heuristic(eq, var):
52
60
  tmp = list(set([simplify(tree_form(x)) for x in output]))
53
61
  tmp = sorted(tmp, key=lambda x: len(str_form(x)))
54
62
  poly_term = None
55
- term_degree = 20
63
+ fx = load_formula("is_integrate_subs")
56
64
  output = []
57
- for item in tmp:
58
- n = poly(simplify(item), var.name)
59
- if n is None:
60
- output.append(item)
61
- else:
62
- if term_degree > len(n):
65
+ if set(all_branch(eq)) <= set("f_add f_mul f_pow".split(" ")):
66
+ for item in tmp:
67
+ if fx(item).name == "s_true":
63
68
  poly_term = item
64
- term_degree = len(n)
69
+ else:
70
+ output.append(item)
65
71
  p = None
66
72
  if poly_term is None:
67
73
  p = tmp
68
74
  else:
69
- p = [poly_term]+output
75
+ p = output+[poly_term]
70
76
  last = list(set(last))
71
77
  if len(p)>3:
72
78
  p = p[:3]
@@ -164,17 +170,22 @@ def integrate_subs(equation, term, v1, v2, extra):
164
170
  eq = equation
165
171
  termeq = term
166
172
  t = inverse(copy.deepcopy(termeq), v1)
167
- g = inverse(termeq, v2)
173
+ g = inverse(copy.deepcopy(termeq), v2)
168
174
  if g is None:
169
175
  return none
170
176
  if t is None:
171
177
  return none
172
178
  else:
173
179
  t = expand(t)
174
- eq = replace(eq, tree_form(v1), t)
175
- eq2 = replace(diff(g, v1), tree_form(v1), t)
176
- equation = eq/eq2
177
- equation = simplify(equation)
180
+ eq3 = diff(g, v1)
181
+ eq2 = replace(eq, g, tree_form(v2))
182
+ eq4 = simplify(eq2/eq3)
183
+ if not contain(eq4, tree_form(v1)):
184
+ equation = eq4
185
+ else:
186
+ eq = replace(eq, tree_form(v1), t)
187
+ equation = eq/eq3
188
+ equation = simplify(equation)
178
189
  if v1 in str_form(equation):
179
190
  return none
180
191
  return dowhile(TreeNode("f_subs", [TreeNode("f_integrate", [simplify(equation), tree_form(origv2)]),tree_form(origv2) ,g]+extra), lambda x: simplify(trig4(trig0(x))))
@@ -336,6 +347,7 @@ def byparts(eq):
336
347
  return TreeNode(eq.name, [byparts(child) for child in eq.children])
337
348
 
338
349
  integrate_formula = lambda x: load_formula("integration")(x)
350
+ integrate_trig_formula = lambda x: load_formula("integration_trig")(x)
339
351
 
340
352
  def shorten(eq):
341
353
  if eq.name.startswith("d_"):
@@ -532,8 +544,8 @@ def integrate_full(root):
532
544
  orig = copy.deepcopy(root)
533
545
  eq = root
534
546
  for item in [[lambda x: x, simplify, expand, normalize], [factor2, apart, normalize2, normalize], [trig1, normalize2],\
535
- [factor1, normalize, trig6, normalize, expand, normalize, integrate_subs_main, normalize, factor2, simplify, apart, normalize2],\
536
- [normalize, integrate_subs_main, normalize2, expand, normalize, byparts, normalize]]:
547
+ [factor1, normalize, trig6, normalize, expand, normalize, integrate_subs_main, normalize, factor2, simplify, integrate_trig_formula, trig1, apart, normalize2],\
548
+ [normalize, integrate_subs_main, normalize2, expand, normalize, byparts, normalize], [integrate_trig_formula, trig1, integrate_formula]]:
537
549
  for item2 in item:
538
550
  eq = item2(eq)
539
551
  if eq not in log:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mathai
3
- Version: 2.0.2
3
+ Version: 2.0.4
4
4
  Summary: Mathematics solving Ai tailored to NCERT
5
5
  Home-page: https://github.com/infinity390/mathai
6
6
  Requires-Python: >=3.7
@@ -3,7 +3,7 @@ from pathlib import Path
3
3
 
4
4
  setup(
5
5
  name="mathai",
6
- version="2.0.2",
6
+ version="2.0.4",
7
7
  description="Mathematics solving Ai tailored to NCERT",
8
8
  long_description=Path("README.md").read_text(encoding="utf-8"),
9
9
  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
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