mathai 2.3.8__tar.gz → 2.4.0__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 (43) hide show
  1. {mathai-2.3.8 → mathai-2.4.0}/PKG-INFO +1 -1
  2. {mathai-2.3.8 → mathai-2.4.0}/mathai/__init__.py +5 -0
  3. {mathai-2.3.8 → mathai-2.4.0}/mathai/apart.py +4 -1
  4. mathai-2.4.0/mathai/benchmark.py +18 -0
  5. {mathai-2.3.8 → mathai-2.4.0}/mathai/decision.py +30 -19
  6. mathai-2.4.0/mathai/diff.py +24 -0
  7. {mathai-2.3.8 → mathai-2.4.0}/mathai/factor.py +2 -2
  8. {mathai-2.3.8 → mathai-2.4.0}/mathai/formula_applier.py +9 -4
  9. mathai-2.4.0/mathai/formula_compiler.py +719 -0
  10. {mathai-2.3.8 → mathai-2.4.0}/mathai/integrate.py +22 -15
  11. {mathai-2.3.8 → mathai-2.4.0}/mathai/limit.py +2 -2
  12. {mathai-2.3.8 → mathai-2.4.0}/mathai/ml.py +8 -7
  13. mathai-2.4.0/mathai/ncert_data.txt +61 -0
  14. {mathai-2.3.8 → mathai-2.4.0}/mathai/trig.py +6 -7
  15. {mathai-2.3.8 → mathai-2.4.0}/mathai.egg-info/PKG-INFO +1 -1
  16. {mathai-2.3.8 → mathai-2.4.0}/mathai.egg-info/SOURCES.txt +3 -0
  17. {mathai-2.3.8 → mathai-2.4.0}/setup.py +5 -1
  18. mathai-2.3.8/mathai/diff.py +0 -179
  19. {mathai-2.3.8 → mathai-2.4.0}/README.md +0 -0
  20. {mathai-2.3.8 → mathai-2.4.0}/mathai/base.py +0 -0
  21. {mathai-2.3.8 → mathai-2.4.0}/mathai/electronic.py +0 -0
  22. {mathai-2.3.8 → mathai-2.4.0}/mathai/expand.py +0 -0
  23. {mathai-2.3.8 → mathai-2.4.0}/mathai/fraction.py +0 -0
  24. {mathai-2.3.8 → mathai-2.4.0}/mathai/graphics.py +0 -0
  25. {mathai-2.3.8 → mathai-2.4.0}/mathai/inverse.py +0 -0
  26. {mathai-2.3.8 → mathai-2.4.0}/mathai/lambda_calculus.py +0 -0
  27. {mathai-2.3.8 → mathai-2.4.0}/mathai/linear.py +0 -0
  28. {mathai-2.3.8 → mathai-2.4.0}/mathai/logic.py +0 -0
  29. {mathai-2.3.8 → mathai-2.4.0}/mathai/matrix.py +0 -0
  30. {mathai-2.3.8 → mathai-2.4.0}/mathai/mlscalar.py +0 -0
  31. {mathai-2.3.8 → mathai-2.4.0}/mathai/ode.py +0 -0
  32. {mathai-2.3.8 → mathai-2.4.0}/mathai/parser.py +0 -0
  33. {mathai-2.3.8 → mathai-2.4.0}/mathai/pde.py +0 -0
  34. {mathai-2.3.8 → mathai-2.4.0}/mathai/printeq.py +0 -0
  35. {mathai-2.3.8 → mathai-2.4.0}/mathai/qm.py +0 -0
  36. {mathai-2.3.8 → mathai-2.4.0}/mathai/simplify.py +0 -0
  37. {mathai-2.3.8 → mathai-2.4.0}/mathai/statistics.py +0 -0
  38. {mathai-2.3.8 → mathai-2.4.0}/mathai/test.py +0 -0
  39. {mathai-2.3.8 → mathai-2.4.0}/mathai/tool.py +0 -0
  40. {mathai-2.3.8 → mathai-2.4.0}/mathai/univariate_inequality.py +0 -0
  41. {mathai-2.3.8 → mathai-2.4.0}/mathai.egg-info/dependency_links.txt +0 -0
  42. {mathai-2.3.8 → mathai-2.4.0}/mathai.egg-info/top_level.txt +0 -0
  43. {mathai-2.3.8 → mathai-2.4.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mathai
3
- Version: 2.3.8
3
+ Version: 2.4.0
4
4
  Summary: Mathematics solving Ai tailored to NCERT
5
5
  Home-page: https://github.com/infinity390/mathai
6
6
  Requires-Python: >=3.7
@@ -7,6 +7,11 @@ from .qm import hydrogen_gse, helium_gse, power_rule
7
7
 
8
8
  from .graphics import draw_graphics_from_solution, solve_graphics, solve_graphics_string
9
9
 
10
+ from .benchmark import benchmark_ncert
11
+
12
+ from .formula_compiler import formula_compiler
13
+ from .formula_compiler import formula_list_compiler
14
+
10
15
  from .lambda_calculus import lambda_expand, lambda_compress, lambda_reduce
11
16
 
12
17
  from .electronic import Edge, CircuitGraph, find_resistance
@@ -51,7 +51,10 @@ def _apart(eq, v=None):
51
51
  if n > 3:
52
52
  return eq
53
53
  n = tree_form("d_"+str(n))
54
- l = len(poly(item, v))
54
+ l = poly(item, v)
55
+ if l is None:
56
+ return eq
57
+ l = len(l)
55
58
  if l == 3:
56
59
  a = alloclst.pop(0)
57
60
  b = alloclst.pop(0)
@@ -0,0 +1,18 @@
1
+ import random
2
+ from .decision import god
3
+ def benchmark_ncert(max_count=5):
4
+ with open("mathai/ncert_data.txt", "r", encoding="utf-8") as file:
5
+ content = file.read()
6
+ content = content.strip().split("\n")
7
+ random.shuffle(content)
8
+ output = []
9
+ count = 1
10
+ if len(max_count) > len(content):
11
+ max_count = len(content)
12
+ for item in content[:max_count]:
13
+ print(f"{count}/{max_count}")
14
+ count += 1
15
+ output.append((item, god(item, False)))
16
+ print()
17
+ for index, item in enumerate(output):
18
+ print(f"{index+1}. {item[0]} => {item[1]}")
@@ -60,9 +60,10 @@ def solve_subs(q):
60
60
  if len(solution.keys()) == 0:
61
61
  return orig
62
62
  return operation("f_and", [item for item in lst if all(not contain(item, tree_form(key)) for key in solution.keys())] + [TreeNode("f_eq", [tree_form(key), item]) for key, item in solution.items()])
63
- def god(string):
64
- print(f"? {string}")
65
- print("thinking...")
63
+ def god(string, debug=True):
64
+ if debug:
65
+ print(f"? {string}")
66
+ print("thinking...")
66
67
  eq = None
67
68
  eq = parse(string)
68
69
  log = [eq]
@@ -72,18 +73,22 @@ def god(string):
72
73
  eq = limit1(limit5(eq))
73
74
  if any(contain2(eq, "f_"+item) for item in "adj det list transpose".split(" ")):
74
75
  eq = matrix_formula(eq)
75
- print(eq)
76
+ if debug:
77
+ print(eq)
76
78
  eq = matrix_solve(eq)
77
- print(eq)
79
+ if debug:
80
+ print(eq)
78
81
  eq = solve_subs(eq)
79
- print(f"=> {eq}")
80
- print()
82
+ if debug:
83
+ print(f"=> {eq}")
84
+ print()
81
85
  return eq
82
86
  elif all(not contain2(eq, "f_"+item) for item in "dif add mul abs pow dif integrate arcsin sin cos log limit eq lt le ge gt".split(" ")) and\
83
87
  any(contain2(eq, "f_"+item) for item in "and or not imply equiv".split(" ")):
84
88
  eq = solve_logically(truth_gen(simplify(set_sub(eq))))
85
- print(f"=> {eq}")
86
- print()
89
+ if debug:
90
+ print(f"=> {eq}")
91
+ print()
87
92
  return eq
88
93
  elif not (eq.name == "f_and" and len(vlist(eq)) > 1) and any(contain2(eq, "f_"+item) for item in "eq lt le ge gt".split(" ")) and all(not contain2(eq, "f_"+item) for item in "limit dif integrate".split(" ")):
89
94
  lst = [simplify, log0, simplify, lambda x: dowhile(x, absolute), lambda x: dowhile(x, lambda y: simplify(expand(y))), lambda x: dowhile(x, lambda y: simplify(fraction(y))), logic0, simple_wavycurvy, simple_wavycurvy]
@@ -98,10 +103,11 @@ def god(string):
98
103
  eq = item(eq)
99
104
  if eq not in log:
100
105
  log.append(eq)
101
- print(eq)
102
- # eq = trig7(eq)
103
- print(f"=> {eq}")
104
- print()
106
+ if debug:
107
+ print(eq)
108
+ if debug:
109
+ print(f"=> {eq}")
110
+ print()
105
111
  return eq
106
112
  elif "f_dif" in str_form(eq) or "f_integrate" in str_form(eq):
107
113
  if "f_dif" in str_form(eq) and "f_integrate" not in str_form(eq):
@@ -109,12 +115,15 @@ def god(string):
109
115
  log.append(eq)
110
116
  if "f_integrate" in str_form(eq):
111
117
  eq = def_integrate_formula(eq)
112
- eq = integrate_full(eq)
118
+ eq = integrate_full(eq, debug)
113
119
  eq = limit5(eq)
114
120
  eq = limit1(eq)
115
121
  eq = simplify(expand(simplify(eq)))
116
- print(f"=> {eq}")
117
- print()
122
+ if contain2(eq, "f_integrate"):
123
+ return None
124
+ if debug:
125
+ print(f"=> {eq}")
126
+ print()
118
127
  return eq
119
128
  if any("f_"+item in str_form(eq) for item in "eq lt le ge gt".split(" ")):
120
129
  eq = simple_wavycurvy(eq)
@@ -122,13 +131,15 @@ def god(string):
122
131
  out = linear_solve(eq)
123
132
  if out is not None:
124
133
  eq = out
125
- print(eq)
134
+ if debug:
135
+ print(eq)
126
136
  eq = solve_subs(eq)
127
137
  out = linear_solve(eq)
128
138
  if out is not None:
129
139
  eq = out
130
140
  eq = simple_wavycurvy(eq)
131
141
  eq = simplify(expand(simplify(fraction(simplify(eq)))))
132
- print(f"=> {eq}")
133
- print()
142
+ if debug:
143
+ print(f"=> {eq}")
144
+ print()
134
145
  return eq
@@ -0,0 +1,24 @@
1
+ from .simplify import simplify
2
+ from .base import *
3
+ from .parser import parse
4
+ from .formula_compiler import formula_list_compiler
5
+
6
+ diff2_s = """pdif(e^a,x) e^a*pdif(a,x) [] x _ _ _
7
+ pdif(a^b,x) b*(a^(b-1))*pdif(a,x)+(a^b)*log(a)*pdif(b,x) [] x _ _ _
8
+ pdif(sin(a),x) cos(a)*pdif(a,x) [] x _ _ _
9
+ pdif(cos(a),x) -sin(a)*pdif(a,x) [] x _ _ _
10
+ pdif(arcsin(a),x) (1/sqrt(1-a^2))*pdif(a,x) [] x _ _ _
11
+ pdif(arccos(a),x) (-1/sqrt(1-a^2))*pdif(a,x) [] x _ _ _
12
+ pdif(arctan(a),x) (1/(1+a^2))*pdif(a,x) [] x _ _ _
13
+ pdif(k,x) 0 [] x k _ _
14
+ pdif(x,x) 1 [] x _ _ _
15
+ pdif(product(a,b),x) pdif(a,x)*b+a*pdif(b,x) [] x _ _ _
16
+ pdif(sum(a,b),x) pdif(a,x)+pdif(b,x) [] x _ _ _
17
+ pdif(product(k,a),x) k*pdif(a,x) [] x k _ _"""
18
+
19
+ diff2 = formula_list_compiler(diff2_s)
20
+
21
+ def diff(equation, var=None):
22
+ var = var if var else "v_0"
23
+ out = diff2(simplify(TreeNode("f_pdif", [equation, tree_form(var)])))
24
+ return out
@@ -7,9 +7,9 @@ import math
7
7
  from .tool import poly
8
8
  from .fraction import fraction
9
9
  from collections import Counter
10
- from .formula_applier import formula_list_applier
10
+ from .formula_compiler import formula_list_compiler
11
11
 
12
- factor2 = lambda x: formula_list_applier(x, "poly(x,a,b,c) a*(x-(-b+sqrt(b^2-4*a*c))/(2*a))*(x-(-b-sqrt(b^2-4*a*c))/(2*a)) [] _ _ b^2-4*a*c _")
12
+ factor2 = formula_list_compiler("poly(x,a,b,c) a*(x-(-b+sqrt(b^2-4*a*c))/(2*a))*(x-(-b-sqrt(b^2-4*a*c))/(2*a)) [] _ _ b^2-4*a*c _")
13
13
  def multiset_intersection(*lists):
14
14
  counters = list(map(Counter, lists))
15
15
  common = counters[0]
@@ -705,6 +705,9 @@ def formula_list_applier(eq, s):
705
705
  return dowhile(eq, lambda x: formula_list_applier_h(x, s))
706
706
 
707
707
 
708
+ def _is_zero(node):
709
+ return node is not None and (getattr(node, "name", None) == "d_0" or node == 0)
710
+
708
711
  def extract_polynomial_coefficients(eq, var, degree):
709
712
  if eq is None:
710
713
  return None
@@ -717,12 +720,14 @@ def extract_polynomial_coefficients(eq, var, degree):
717
720
  if c_val is None:
718
721
  return None
719
722
  coefficients.append(c_val)
720
- simplified_num = simplify(operation("f_sub", [current_eq, c_val]))
721
- if simplified_num == 0:
723
+ remainder = simplify(operation("f_sub", [current_eq, c_val]))
724
+ if remainder is None:
725
+ return None
726
+ if _is_zero(remainder):
722
727
  coefficients.extend(TreeNode("d_0") for _ in range(degree + 1 - len(coefficients)))
723
728
  return coefficients
724
- current_eq = simplify(expand(simplify(operation("f_div", [simplified_num, var_node]))))
729
+ current_eq = simplify(expand(simplify(operation("f_div", [remainder, var_node]))))
725
730
  if current_eq is None:
726
731
  return None
727
732
  final_check = simplify(replace(copy.deepcopy(current_eq), var_node, zero_node))
728
- return coefficients if final_check == 0 else None
733
+ return coefficients if _is_zero(final_check) else None