mathai 2.3.4__tar.gz → 2.3.6__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 (40) hide show
  1. {mathai-2.3.4 → mathai-2.3.6}/PKG-INFO +1 -1
  2. {mathai-2.3.4 → mathai-2.3.6}/mathai/__init__.py +5 -7
  3. {mathai-2.3.4 → mathai-2.3.6}/mathai/decision.py +4 -1
  4. mathai-2.3.6/mathai/diff.py +179 -0
  5. {mathai-2.3.4 → mathai-2.3.6}/mathai/formula_applier.py +4 -2
  6. {mathai-2.3.4 → mathai-2.3.6}/mathai/graphics.py +52 -1
  7. {mathai-2.3.4 → mathai-2.3.6}/mathai/integrate.py +19 -274
  8. {mathai-2.3.4 → mathai-2.3.6}/mathai/qm.py +2 -3
  9. {mathai-2.3.4 → mathai-2.3.6}/mathai/simplify.py +8 -0
  10. {mathai-2.3.4 → mathai-2.3.6}/mathai.egg-info/PKG-INFO +1 -1
  11. {mathai-2.3.4 → mathai-2.3.6}/setup.py +1 -1
  12. mathai-2.3.4/mathai/diff.py +0 -24
  13. {mathai-2.3.4 → mathai-2.3.6}/README.md +0 -0
  14. {mathai-2.3.4 → mathai-2.3.6}/mathai/apart.py +0 -0
  15. {mathai-2.3.4 → mathai-2.3.6}/mathai/base.py +0 -0
  16. {mathai-2.3.4 → mathai-2.3.6}/mathai/electronic.py +0 -0
  17. {mathai-2.3.4 → mathai-2.3.6}/mathai/expand.py +0 -0
  18. {mathai-2.3.4 → mathai-2.3.6}/mathai/factor.py +0 -0
  19. {mathai-2.3.4 → mathai-2.3.6}/mathai/fraction.py +0 -0
  20. {mathai-2.3.4 → mathai-2.3.6}/mathai/inverse.py +0 -0
  21. {mathai-2.3.4 → mathai-2.3.6}/mathai/lambda_calculus.py +0 -0
  22. {mathai-2.3.4 → mathai-2.3.6}/mathai/limit.py +0 -0
  23. {mathai-2.3.4 → mathai-2.3.6}/mathai/linear.py +0 -0
  24. {mathai-2.3.4 → mathai-2.3.6}/mathai/logic.py +0 -0
  25. {mathai-2.3.4 → mathai-2.3.6}/mathai/matrix.py +0 -0
  26. {mathai-2.3.4 → mathai-2.3.6}/mathai/ml.py +0 -0
  27. {mathai-2.3.4 → mathai-2.3.6}/mathai/mlscalar.py +0 -0
  28. {mathai-2.3.4 → mathai-2.3.6}/mathai/ode.py +0 -0
  29. {mathai-2.3.4 → mathai-2.3.6}/mathai/parser.py +0 -0
  30. {mathai-2.3.4 → mathai-2.3.6}/mathai/pde.py +0 -0
  31. {mathai-2.3.4 → mathai-2.3.6}/mathai/printeq.py +0 -0
  32. {mathai-2.3.4 → mathai-2.3.6}/mathai/statistics.py +0 -0
  33. {mathai-2.3.4 → mathai-2.3.6}/mathai/test.py +0 -0
  34. {mathai-2.3.4 → mathai-2.3.6}/mathai/tool.py +0 -0
  35. {mathai-2.3.4 → mathai-2.3.6}/mathai/trig.py +0 -0
  36. {mathai-2.3.4 → mathai-2.3.6}/mathai/univariate_inequality.py +0 -0
  37. {mathai-2.3.4 → mathai-2.3.6}/mathai.egg-info/SOURCES.txt +0 -0
  38. {mathai-2.3.4 → mathai-2.3.6}/mathai.egg-info/dependency_links.txt +0 -0
  39. {mathai-2.3.4 → mathai-2.3.6}/mathai.egg-info/top_level.txt +0 -0
  40. {mathai-2.3.4 → mathai-2.3.6}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mathai
3
- Version: 2.3.4
3
+ Version: 2.3.6
4
4
  Summary: Mathematics solving Ai tailored to NCERT
5
5
  Home-page: https://github.com/infinity390/mathai
6
6
  Requires-Python: >=3.7
@@ -5,6 +5,8 @@ from .pde import solve_pde
5
5
 
6
6
  from .qm import hydrogen_gse, helium_gse, power_rule
7
7
 
8
+ from .graphics import draw_graphics_from_solution, solve_graphics, solve_graphics_string
9
+
8
10
  from .lambda_calculus import lambda_expand, lambda_compress, lambda_reduce
9
11
 
10
12
  from .electronic import Edge, CircuitGraph, find_resistance
@@ -15,8 +17,6 @@ from .test import test
15
17
 
16
18
  from .decision import god, trig7
17
19
 
18
- from .graphics import solve_graphics, solve_graphics_string
19
-
20
20
  from .expand import expand
21
21
 
22
22
  from .ml import NeuralNetwork, diff_matrix_matrix
@@ -30,12 +30,10 @@ from .formula_applier import formula_applier, formula_list_applier
30
30
 
31
31
  from .integrate import integrate_subs_main as integrate_subs
32
32
  from .integrate import byparts as integrate_byparts
33
- from .integrate import sqint as integrate_fraction
34
- from .integrate import conv_int
33
+ from .integrate import integrate_fraction
35
34
  from .integrate import solve_integrate as integrate_clean
36
- from .integrate import integrate_formula, integrate_trig_formula, integrate_qm_formula, integrate_full, integrate_definite
35
+ from .integrate import integrate_formula, integrate_trig_formula, integrate_full, def_integrate_formula
37
36
  from .integrate import normalize as integration_basic
38
- from .integrate import normalize_qm as integration_qm_basic
39
37
 
40
38
  from .diff import diff, diff2
41
39
 
@@ -52,7 +50,7 @@ from .inverse import inverse, inverse2
52
50
  from .logic import logic0, set_sub, truth_gen, solve_logically
53
51
  from .apart import apart, apart2
54
52
 
55
- from .limit import limit1, limit2, limit0, limit3, limit4, solve_inf
53
+ from .limit import limit1, limit2, limit0, limit3, limit4, solve_inf, limit5
56
54
 
57
55
  from .univariate_inequality import wavycurvy, absolute, domain, handle_sqrt, prepare, eq2range, range2eq2, simple_wavycurvy
58
56
 
@@ -1,6 +1,6 @@
1
1
  import math
2
2
  from .inverse import inverse, inverse2
3
- from .integrate import integrate_full
3
+ from .integrate import integrate_full, def_integrate_formula
4
4
  from .ode import diffsolve as ode_solve
5
5
  from .parser import parse
6
6
  from .simplify import simplify, log0
@@ -328,7 +328,10 @@ def god(string):
328
328
  eq = simplify(ode_solve(simplify(eq)))
329
329
  log.append(eq)
330
330
  if "f_integrate" in str_form(eq):
331
+ eq = def_integrate_formula(eq)
331
332
  eq = integrate_full(eq)
333
+ eq = limit5(eq)
334
+ eq = limit1(eq)
332
335
  eq = simplify(expand(simplify(eq)))
333
336
  print(f"=> {eq}")
334
337
  print()
@@ -0,0 +1,179 @@
1
+ from .simplify import simplify
2
+ from .base import *
3
+ from .parser import parse
4
+ from .formula_applier import formula_list_applier
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 = lambda x: formula_list_applier(x, 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
25
+ '''
26
+ def diff(equation, var="v_0"):
27
+ def diffeq_iterative(root_eq):
28
+ stack = [(root_eq, False)]
29
+ results = {}
30
+ while stack:
31
+ eq, processed = stack.pop()
32
+ if eq in results:
33
+ continue
34
+ if not processed:
35
+ eq_simplified = simplify(eq)
36
+ if "v_" not in str_form(eq_simplified):
37
+ results[eq] = tree_form("d_0")
38
+ continue
39
+ stack.append((eq, True))
40
+ if eq.name in ("f_add", "f_mul"):
41
+ for child in eq.children:
42
+ if child not in results:
43
+ stack.append((child, False))
44
+ elif eq.name in ("f_abs", "f_tan", "f_log", "f_arcsin", "f_arccos", "f_arctan", "f_sin", "f_cos"):
45
+ child = eq.children[0]
46
+ if child not in results:
47
+ stack.append((child, False))
48
+ elif eq.name == "f_pow":
49
+ for child in eq.children:
50
+ if child not in results:
51
+ stack.append((child, False))
52
+ else:
53
+ if "v_" not in str_form(eq):
54
+ results[eq] = tree_form("d_0")
55
+ continue
56
+ if eq.name == "f_add":
57
+ add_res = tree_form("d_0")
58
+ for child in eq.children:
59
+ add_res = add_res + results.get(child, tree_form("d_0"))
60
+ results[eq] = add_res
61
+ elif eq.name == "f_abs":
62
+ u = eq.children[0]
63
+ du = results.get(u, tree_form("d_0"))
64
+ results[eq] = du * u / eq
65
+ elif eq.name == "f_pow" and eq.children[0].name == "s_e":
66
+ u = eq.children[1]
67
+ du = results.get(u, tree_form("d_0"))
68
+ results[eq] = du * eq
69
+ elif eq.name == "f_tan":
70
+ u = eq.children[0]
71
+ du = results.get(u, tree_form("d_0"))
72
+ cos_u = u.fx("cos")
73
+ results[eq] = du / (cos_u * cos_u)
74
+ elif eq.name == "f_log":
75
+ u = eq.children[0]
76
+ du = results.get(u, tree_form("d_0"))
77
+ results[eq] = du * (tree_form("d_1") / u)
78
+ elif eq.name == "f_arcsin":
79
+ u = eq.children[0]
80
+ du = results.get(u, tree_form("d_0"))
81
+ one = tree_form("d_1")
82
+ half = tree_form("d_2") ** tree_form("d_-1")
83
+ results[eq] = du / ((one - u * u) ** half)
84
+ elif eq.name == "f_arccos":
85
+ u = eq.children[0]
86
+ du = results.get(u, tree_form("d_0"))
87
+ one = tree_form("d_1")
88
+ half = tree_form("d_2") ** tree_form("d_-1")
89
+ results[eq] = tree_form("d_-1") * du / ((one - u * u) ** half)
90
+ elif eq.name == "f_arctan":
91
+ u = eq.children[0]
92
+ du = results.get(u, tree_form("d_0"))
93
+ results[eq] = du / (tree_form("d_1") + u * u)
94
+ elif eq.name == "f_pow" and "v_" in str_form(eq.children[1]):
95
+ u, v = eq.children
96
+ du = results.get(u, tree_form("d_0"))
97
+ dv = results.get(v, tree_form("d_0"))
98
+ term1 = (v / u) * du
99
+ term2 = u.fx("log") * dv
100
+ results[eq] = (u ** v) * (term1 + term2)
101
+ elif eq.name == "f_mul":
102
+ add_res = tree_form("d_0")
103
+ n_children = len(eq.children)
104
+ for i in range(n_children):
105
+ target_child = eq.children[i]
106
+ d_target = results.get(target_child, tree_form("d_0"))
107
+ other_terms = [eq.children[j] for j in range(n_children) if j != i]
108
+ if len(other_terms) == 1:
109
+ other_prod = other_terms[0]
110
+ else:
111
+ other_prod = TreeNode("f_mul", other_terms)
112
+ add_res = add_res + (d_target * other_prod)
113
+ results[eq] = add_res
114
+ elif eq.name == "f_sin":
115
+ u = eq.children[0]
116
+ du = results.get(u, tree_form("d_0"))
117
+ results[eq] = du * u.fx("cos")
118
+ elif eq.name == "f_cos":
119
+ u = eq.children[0]
120
+ du = results.get(u, tree_form("d_0"))
121
+ results[eq] = tree_form("d_-1") * du * u.fx("sin")
122
+ elif eq.name[:2] == "v_":
123
+ results[eq] = TreeNode("f_dif", [eq])
124
+ elif eq.name == "f_pow" and "v_" not in str_form(eq.children[1]):
125
+ base, power = eq.children
126
+ dbase = results.get(base, tree_form("d_0"))
127
+ power_minus_1 = power - tree_form("d_1")
128
+ results[eq] = power * (base ** power_minus_1) * dbase
129
+ else:
130
+ results[eq] = TreeNode("f_dif", [eq, tree_form(var)])
131
+ return results.get(root_eq, tree_form("d_0"))
132
+ def helper2_iterative(root_eq, target_var):
133
+ stack = [(root_eq, False)]
134
+ results = {}
135
+ while stack:
136
+ eq, processed = stack.pop()
137
+ if eq in results:
138
+ continue
139
+ if not processed:
140
+ stack.append((eq, True))
141
+ for child in eq.children:
142
+ if child not in results:
143
+ stack.append((child, False))
144
+ else:
145
+ if eq.name == "f_dif":
146
+ if eq.children[0].name == target_var:
147
+ results[eq] = tree_form("d_1")
148
+ elif not contain(eq.children[0], target_var):
149
+ results[eq] = tree_form("d_0")
150
+ else:
151
+ results[eq] = eq
152
+ else:
153
+ new_children = [results.get(child, child) for child in eq.children]
154
+ results[eq] = TreeNode(eq.name, new_children)
155
+ return results.get(root_eq, root_eq)
156
+ def calc_iterative(root_eq):
157
+ stack = [(root_eq, False)]
158
+ results = {}
159
+ while stack:
160
+ eq, processed = stack.pop()
161
+ if eq in results:
162
+ continue
163
+ if not processed:
164
+ stack.append((eq, True))
165
+ for child in eq.children:
166
+ if child not in results:
167
+ stack.append((child, False))
168
+ else:
169
+ if eq.name == "f_dif":
170
+ results[eq] = diffeq_iterative(eq.children[0])
171
+ else:
172
+ new_children = [results.get(child, child) for child in eq.children]
173
+ results[eq] = TreeNode(eq.name, new_children)
174
+ return results.get(root_eq, root_eq)
175
+ if var is None:
176
+ return simplify(calc_iterative(equation))
177
+ equation = diffeq_iterative(equation)
178
+ equation = helper2_iterative(equation, var)
179
+ return simplify(equation)
@@ -253,8 +253,10 @@ def _match_struct_bind_core(eq, f, binding, const_1_vars, ignore_set, resolved_i
253
253
  for item in vlist(eq):
254
254
  out = extract_polynomial_coefficients(eq_plain, item, degree)
255
255
  if out is not None:
256
- out = out[::-1][1:]
257
- if out[0] != 0:
256
+ out = out[::-1]
257
+ while out[0] == 0:
258
+ out.pop(0)
259
+ if len(out) == degree:
258
260
  local_binding = binding.copy()
259
261
  for i in range(1, len(f.children)):
260
262
  local_binding[f.children[i].name] = out[i - 1]
@@ -46,5 +46,56 @@ def solve_graphics(Ax, Ay, Az, Bx, By, Bz, BAx, BAy, BAz, phi, theta, fvl, tvl,
46
46
  return final_solution
47
47
  def solve_graphics_string(s):
48
48
  s_parsed = [None if item == "None" else parse(item) for item in s.split()]
49
- for key, item in solve_graphics(*s_parsed).items():
49
+ solution = solve_graphics(*s_parsed)
50
+ for key, item in solution.items():
50
51
  print(f"{key} : {item}")
52
+ return solution
53
+ def draw_graphics_from_solution(solution):
54
+ import matplotlib.pyplot as plt
55
+ import numpy as np
56
+ def get_val(key):
57
+ if key in solution:
58
+ val = solution[key]
59
+ try:
60
+ return float(compute(val))
61
+ except Exception:
62
+ try:
63
+ return float(str(val))
64
+ except Exception:
65
+ return 0.0
66
+ return 0.0
67
+ Ax = get_val('Ax')
68
+ Ay = get_val('Ay')
69
+ Az = get_val('Az')
70
+ Bx = get_val('Bx')
71
+ By = get_val('By')
72
+ Bz = get_val('Bz')
73
+ fa_x, fa_y = Az, Ay
74
+ fb_x, fb_y = Bz, By
75
+ ta_x, ta_y = Az, -Ax
76
+ tb_x, tb_y = Bz, -Bx
77
+ fig, ax = plt.subplots(figsize=(9, 7))
78
+ x_min = min(fa_x, fb_x, ta_x, tb_x) - 25
79
+ x_max = max(fa_x, fb_x, ta_x, tb_x) + 25
80
+ ax.axhline(0, color='black', linewidth=1.5, label='Reference Axis')
81
+ ax.plot([fa_x, fb_x], [fa_y, fb_y], 'r-', linewidth=2, label="Front View (a' b')")
82
+ ax.plot(fa_x, fa_y, 'ro', markersize=5)
83
+ ax.plot(fb_x, fb_y, 'ro', markersize=5)
84
+ ax.text(fa_x - 3, fa_y + 3, "a'", fontsize=11, color='red', fontweight='bold')
85
+ ax.text(fb_x + 3, fb_y + 3, "b'", fontsize=11, color='red', fontweight='bold')
86
+ ax.plot([ta_x, tb_x], [ta_y, tb_y], 'b-', linewidth=2, label="Top View (a b)")
87
+ ax.plot(ta_x, ta_y, 'bo', markersize=5)
88
+ ax.plot(tb_x, tb_y, 'bo', markersize=5)
89
+ ax.text(ta_x - 3, ta_y - 8, "a", fontsize=11, color='blue', fontweight='bold')
90
+ ax.text(tb_x + 3, tb_y - 8, "b", fontsize=11, color='blue', fontweight='bold')
91
+ ax.plot([fa_x, ta_x], [fa_y, ta_y], 'k--', alpha=0.5)
92
+ ax.plot([fb_x, tb_x], [fb_y, tb_y], 'k--', alpha=0.5)
93
+ ax.set_aspect('equal', adjustable='datalim')
94
+ ax.grid(True, linestyle=':', alpha=0.6)
95
+ ax.set_xlabel('Coordinate Axis (Az / Bz)', fontsize=10)
96
+ ax.set_ylabel('Height / Depth', fontsize=10)
97
+ ax.set_title('Engineering Drawing: Projections of a Line', fontsize=13, fontweight='bold', pad=15)
98
+ ax.legend(loc='upper right', framealpha=0.9)
99
+ plt.tight_layout()
100
+ plt.savefig('line_projections.png', dpi=300)
101
+ plt.show()
@@ -217,106 +217,7 @@ def integrate_subs_main_helper(equation):
217
217
  return equation
218
218
  def integrate_subs_main(equation):
219
219
  return transform_dfs(equation, integrate_subs_main_helper)
220
- def _sqint(equation):
221
- def sgn(eq):
222
- if compute(eq) <0:
223
- return tree_form("d_-1"), tree_form("d_-1")*eq
224
- return tree_form("d_1"), eq
225
- eq2 = equation
226
- if eq2.name == "f_integrate":
227
- equation = eq2.children[0]
228
- var = eq2.children[1]
229
- one = tree_form("d_1")
230
- two = tree_form("d_2")
231
- four = tree_form("d_4")
232
- three = tree_form("d_3")
233
- root = tree_form("d_2")**-1
234
- zero = tree_form("d_0")
235
- n, d = num_dem(equation)
236
- n, d = simplify(n), simplify(d)
237
- term = [simplify(x) for x in factor_generation(d)]
238
- const = product([item for item in term if "v_" not in str_form(item)])
239
- term = [item for item in term if "v_" in str_form(item)]
240
- mode = False
241
- if all(item.name == "f_pow" and simplify(item.children[1]-root) == zero for item in term):
242
- d = simplify(expand(const**two*product([item.children[0] for item in term])))
243
- else:
244
- mode = True
245
- if any(item.name == "f_pow" and simplify(item.children[1]-root) == zero for item in term):
246
- return None
247
- if vlist(equation) == []:
248
- return None
249
- v = vlist(equation)[0]
250
- x = tree_form(v)
251
- np = poly(n, v)
252
- dp = poly(d, v)
253
- if np is None or dp is None:
254
- return None
255
- if len(np) == 1 and len(dp) == 3:
256
- k, a, b, c = np+dp
257
- if a == zero:
258
- return None
259
- s1, s2 = sgn(a)
260
- const = (four*a*c - b**two)/(four*a)
261
- t1, t2 = sgn(const)
262
- la = s2**root
263
- lb = b*s2**root/(two*a)
264
- if mode:
265
- if s1 == one:
266
- if t1 == one:
267
- if simplify(t2**root) == tree_form("d_0"):
268
- return None
269
- return k*((la*x+lb)/t2**root).fx("arctan")/(la * t2**root)
270
- else:
271
- return None
272
- else:
273
- if t1 == one:
274
- return None
275
- else:
276
- _, t2 = sgn(-const)
277
- return -k*((la*x+lb)/t2**root).fx("arctan")/(la * t2**root)
278
- if s1 == one:
279
- if t1 == one:
280
- return simplify(k*(la*x + lb + ((la*x + lb)**two + t2)**root).fx("abs").fx("log")/la)
281
- else:
282
- return simplify(k*(la*x + lb + ((la*x + lb)**two - t2)**root).fx("abs").fx("log")/la)
283
- else:
284
- if t1 == one:
285
- return k*((la*x + lb)/t2**root).fx("arcsin")/la
286
- else:
287
- return None
288
- if len(np) == 2 and len(dp) == 3:
289
- p, q, a, b, c = np+dp
290
- if a == zero:
291
- return None
292
- A = p/(two*a)
293
- B = q - A*b
294
- t = a*x**two + b*x + c
295
- if not mode:
296
- tmp = _sqint(TreeNode("f_integrate", [simplify(one/t**root), var]))
297
- if tmp is None:
298
- tmp = TreeNode("f_integrate", [simplify(one/t**root), var])
299
- return A*two*t**root + tmp*B
300
- else:
301
- tmp = _sqint(TreeNode("f_integrate", [simplify(one/t), var]))
302
- if tmp is None:
303
- tmp = TreeNode("f_integrate", [simplify(one/t), var])
304
- return A*t.fx("abs").fx("log") + tmp*B
305
- equation = eq2
306
- coll = TreeNode(equation.name, [])
307
- for child in equation.children:
308
- out = _sqint(child)
309
- if out is None:
310
- coll.children.append(child)
311
- else:
312
- coll.children.append(out)
313
- return coll
314
- def sqint(eq):
315
- eq = _sqint(eq)
316
- out = simplify(eq)
317
- if out is None:
318
- return eq
319
- return out
220
+
320
221
  def byparts(eq):
321
222
  if eq.name == "f_ref":
322
223
  return eq
@@ -353,6 +254,21 @@ def byparts(eq):
353
254
  eq = eq2
354
255
  return TreeNode(eq.name, [byparts(child) for child in eq.children])
355
256
 
257
+ integrate_fraction_s = """integrate(1/sqrt(poly(x,a,b,c)),x) 1/sqrt(a)*log(abs(sqrt(a)*x+b/(2*sqrt(a))+sqrt((sqrt(a)*x+b/(2*sqrt(a)))^2+(4*a*c-b^2)/(4*a)))) [] x [a,b,c] [a,4*a*c-b^2] _ [[a,0],[b^2-4*a*c,0]]
258
+ integrate(1/sqrt(poly(x,a,b,c)),x) 1/sqrt(a)*log(abs(sqrt(a)*x+b/(2*sqrt(a))+sqrt((sqrt(a)*x+b/(2*sqrt(a)))^2-(b^2-4*a*c)/(4*a)))) [] x [a,b,c] [a,b^2-4*a*c] _ [[a,0],[4*a*c-b^2,0]]
259
+ integrate(1/sqrt(poly(x,a,b,c)),x) 1/sqrt(-a)*arcsin((sqrt(-a)*x-b/(2*sqrt(-a)))/sqrt((4*a*c-b^2)/(4*a))) [] x [a,b,c] [4*a*c-b^2] a [[a,0],[b^2-4*a*c,0]]
260
+ integrate(1/poly(x,a,b,c),x) 1/(sqrt(a)*sqrt((4*a*c-b^2)/(4*a)))*arctan((sqrt(a)*x+b/(2*sqrt(a)))/sqrt((4*a*c-b^2)/(4*a))) [] x [a,b,c] [a,4*a*c-b^2] _ [[a,0],[b^2-4*a*c,0]]
261
+ integrate(1/poly(x,a,b,c),x) -1/(sqrt(-a)*sqrt((b^2-4*a*c)/(-4*a)))*arctan((sqrt(-a)*x-b/(2*sqrt(-a)))/sqrt((b^2-4*a*c)/(-4*a))) [] x [a,b,c] _ [a,b^2-4*a*c] [[a,0],[4*a*c-b^2,0]]
262
+ integrate(poly(x,p,q)/sqrt(poly(x,a,b,c)),x) (p/a)*sqrt(a*x^2+b*x+c)+(q-p*b/(2*a))*integrate(1/sqrt(a*x^2+b*x+c),x) [] x [p,q,a,b,c] _ _ _ [[a,0]]
263
+ integrate(poly(x,p,q)/poly(x,a,b,c),x) (p/(2*a))*log(abs(a*x^2+b*x+c))+(q-p*b/(2*a))*integrate(1/(a*x^2+b*x+c),x) [] x [p,q,a,b,c] _ _ _ [[a,0]]"""
264
+ integrate_fraction = lambda x: formula_list_applier(x, integrate_fraction_s)
265
+
266
+ def_integrate_formula_s = """integrate(abs(poly(x,a,b)),x,m,n) ((a*n+b)*abs(a*n+b)-(a*m+b)*abs(a*m+b))/(2*a) [] x [a,b] _ _
267
+ integrate(abs(sin(x)),x) 2*floor(x/pi)+1-cos(x-pi*floor(x/pi)) [] x _ _ _
268
+ integrate(u,x,a,inf) limitpinf(integrate(u,x),x)-limit(integrate(u,x),x,a) [] x a _ _ _
269
+ integrate(u,x,a,b) limit(integrate(u,x),x,b)-limit(integrate(u,x),x,a) [] x [a,b] _ _ _"""
270
+ def_integrate_formula = lambda x: formula_list_applier(x, def_integrate_formula_s)
271
+
356
272
  integrate_formula_s = """
357
273
  integrate(x^2*e^(poly(x,a,b)),x) ((x^2/a)-(2*x/(a^2))+(2/(a^3)))*e^(a*x+b) [] x [a,b] _ _
358
274
  integrate(x*e^(poly(x,a,b)),x) ((x/a)-(1/(a^2)))*e^(a*x+b) [] x [a,b] _ _
@@ -386,166 +302,6 @@ integrate(sin(x)^a,x) sin(x)^(a+1)*cos(x)/(a+1)+(a+2)/(a+1)*integrate(sin(x)^(a+
386
302
  integrate(cos(x)^a,x) -(sin(x)*cos(x)^(a+1)/(a+1))+(a+2)/(a+1)*integrate(cos(x)^(a+2),x) [] x a _ a [[a,-1]]"""
387
303
  integrate_trig_formula = lambda x: formula_list_applier(x, integrate_trig_s)
388
304
 
389
- def shorten(eq):
390
- if eq.name.startswith("d_"):
391
- return tree_form("d_0")
392
- return TreeNode(eq.name, [shorten(child) for child in eq.children])
393
-
394
- def integrate_qm_formula(equation):
395
- out = transform_dfs(equation, integrate_formula_h, [True])
396
- return out
397
- def has_nested_trig(node, seen_trig=False):
398
- if not isinstance(node, TreeNode):
399
- return False
400
- trig = {
401
- "f_sin", "f_cos", "f_tan",
402
- "f_sec", "f_cosec", "f_cot"
403
- }
404
- is_trig = node.name in trig
405
- if is_trig and seen_trig:
406
- return True
407
- seen_trig = seen_trig or is_trig
408
- children = getattr(node, "args", None) or getattr(node, "children", None) or []
409
- for c in children:
410
- if has_nested_trig(c, seen_trig):
411
- return True
412
- return False
413
- def has_nested_trig(node, seen_trig=False):
414
- if not isinstance(node, TreeNode):
415
- return False
416
- trig = {
417
- "f_sin", "f_cos", "f_tan",
418
- "f_sec", "f_cosec", "f_cot"
419
- }
420
- is_trig = node.name in trig
421
- if is_trig and seen_trig:
422
- return True
423
- seen_trig = seen_trig or is_trig
424
- children = getattr(node, "args", None) or getattr(node, "children", None) or []
425
- for c in children:
426
- if has_nested_trig(c, seen_trig):
427
- return True
428
- return False
429
- def sin_range(eq, n, wrt):
430
- a = tree_form(f"d_{n}")*parse("pi/2")
431
- b = tree_form(f"d_{n+1}")*parse("pi/2")
432
- return eq2range(wavycurvy(simplify(TreeNode("f_lt", [a,eq]) & TreeNode("f_lt", [eq,b])), wrt)), tree_form("d_1") if (n // 2)%2 ==0 else tree_form("d_-1")
433
- def def_int_h(eq, start, end, wrt, root):
434
- if eq.name == "f_abs" and eq.children[0].name == "f_sin":
435
- lst = []
436
- f = Range()
437
- f.r = [False, start, True, end, False]
438
- a = math.floor(compute(start)/compute(parse("pi/2")))
439
- b = math.floor(compute(end)/compute(parse("pi/2")))+1
440
- for i in range(a,b+1):
441
- inq, sgn = sin_range(eq.children[0].children[0], i, wrt)
442
- inq = eq2range(wavycurvy(range2eq2(f&inq))).fix()
443
- if len(inq.r) != 5:
444
- continue
445
- eqn = TreeNode("f_integrate", [eq.children[0]*sgn, wrt])
446
- eqn2 = TreeNode("f_subs", [eqn, wrt, inq.r[3]]) - TreeNode("f_subs", [eqn, wrt, inq.r[1]])
447
- lst.append(eqn2)
448
- return simplify(summation(lst))
449
- elif eq.name == "f_max" and len(eq.children) == 2:
450
- if len(vlist(eq)) == 2:
451
- if eq.children[0].name.startswith("v_") and eq.children[1].name.startswith("v_"):
452
- if start != tree_form("d_0") or end != tree_form("s_inf"):
453
- return None
454
- var = tree_form(list(set(vlist(eq))-set([wrt.name]))[0])
455
- a = replace(copy.deepcopy(root), eq, var)
456
- b = replace(copy.deepcopy(root), eq, wrt)
457
- return TreeNode("f_integrate", [a.children[0],wrt,start,var])+TreeNode("f_integrate", [b.children[0],wrt,var, end])
458
- elif eq.name == "f_abs":
459
- if len(vlist(eq)) == 1:
460
- lst = []
461
- f = TreeNode("f_gt", [eq.children[0], tree_form("d_0")])
462
- f = simplify(f)
463
- g = TreeNode("f_lt", [eq.children[0], tree_form("d_0")])
464
- g = simplify(g)
465
- h = Range()
466
- h.r = [False, start, True, end, False]
467
- f = eq2range(wavycurvy(f, wrt))
468
- f = (f & h).fix()
469
- g = eq2range(wavycurvy(g, wrt))
470
- g = (g & h).fix()
471
- if f.r[0] or f.r[-1] or g.r[0] or g.r[-1]:
472
- return None
473
- for i in range(2):
474
- for j in range(len([f,g][i].r)):
475
- if [f,g][i].r[j] == True:
476
- eqn = TreeNode("f_integrate", [eq.children[0]*[tree_form("d_1"), tree_form("d_-1")][i], wrt])
477
- eqn2 = TreeNode("f_subs", [eqn, wrt, [f,g][i].r[j+1]]) - TreeNode("f_subs", [eqn, wrt, [f,g][i].r[j-1]])
478
- lst.append(eqn2)
479
- return simplify(summation(lst))
480
- elif len(vlist(eq)) > 1:
481
- out = inverse(copy.deepcopy(eq.children[0]), wrt.name, True)
482
- if out is None:
483
- return None
484
- eqn, sign = out
485
- test = copy.deepcopy(eqn)
486
- pos = True
487
- neg = True
488
- for item in vlist(eq.children[0]):
489
- out = diff(eq.children[0],item)
490
- if frac(out) is None:
491
- pos = False
492
- neg = False
493
- elif frac(out) > 0:
494
- neg = False
495
- elif frac(out) < 0:
496
- pos = False
497
- test = replace(test, tree_form(item), tree_form("d_0"))
498
- a = None
499
- if simplify(test-start) != 0:
500
- return None
501
- if pos or neg:
502
- if sign:
503
- return TreeNode("f_integrate", [replace(copy.deepcopy(root), eq, eq.children[0]).children[0],wrt,start,end])
504
- else:
505
- return TreeNode("f_integrate", [replace(copy.deepcopy(root), eq, -eq.children[0]).children[0],wrt,start,end])
506
- a = replace(copy.deepcopy(root), eq, -eq.children[0])
507
- b = replace(copy.deepcopy(root), eq, eq.children[0])
508
- if not sign:
509
- a, b = b, a
510
- out = TreeNode("f_integrate", [a.children[0],wrt,start, eqn])+TreeNode("f_integrate", [b.children[0],wrt,eqn, end])
511
- return out
512
- return None
513
- def conv_int2(eq, wrt, start, end):
514
- lst = []
515
- for item in [start, end]:
516
- if item == tree_form("s_inf"):
517
- lst.append(TreeNode("f_limitpinf", [eq, wrt]))
518
- else:
519
- lst.append(TreeNode("f_limit", [replace(copy.deepcopy(eq), wrt, wrt+item), wrt]))
520
- return lst[1]-lst[0]
521
- def conv_int_h(eq):
522
- if (eq.name == "f_integrate" and len(eq.children) == 4):
523
- lst = []
524
- for item in [eq.children[2], eq.children[3]]:
525
- if item == tree_form("s_inf"):
526
- lst.append(TreeNode("f_limitpinf", [TreeNode("f_integrate", copy.deepcopy(eq.children[:2])), eq.children[1]]))
527
- else:
528
- lst.append(TreeNode("f_limit", [TreeNode("f_integrate", [replace(copy.deepcopy(eq.children[0]),eq.children[1],eq.children[1]+item),\
529
- eq.children[1]]), eq.children[1]]))
530
- return lst[1]-lst[0]
531
- return eq
532
- def conv_int(eq):
533
- return transform_dfs(eq, conv_int_h, [])
534
- def def_int(eq, start, end, wrt, root):
535
- out = def_int_h(eq, start, end, wrt, root)
536
- if out is not None:
537
- return out
538
- for child in eq.children:
539
- out = def_int(child, start, end, wrt, root)
540
- if out is not None:
541
- return out
542
- return None
543
- def integrate_definite(eq):
544
- if eq.name == "f_integrate" and len(eq.children) == 4:
545
- out = def_int(eq.children[0], eq.children[2], eq.children[3], eq.children[1], eq)
546
- if out is not None:
547
- return out
548
- return TreeNode(eq.name, [integrate_definite(child) for child in eq.children])
549
305
  def normalize(x, f=True):
550
306
  x = simplify(x)
551
307
  x = factor2(x)
@@ -553,24 +309,13 @@ def normalize(x, f=True):
553
309
  x = dowhile(x, lambda y: fraction(simplify(integrate_formula(y))))
554
310
  else:
555
311
  x = dowhile(x, lambda y: simplify(integrate_formula(y)))
556
- out = sqint(x)
557
- if out is not None:
558
- x = out
559
- return x
560
- def normalize_qm(x, f=True):
561
- x = simplify(x)
562
- x = integrate_summation(x)
563
- x = factor2(x)
564
- if f:
565
- x = dowhile(x, lambda y: fraction(simplify(integrate_qm_formula(rm_const(integrate_summation(y))))))
566
- else:
567
- x = dowhile(x, lambda y: simplify(integrate_qm_formula(rm_const(integrate_summation(y)))))
568
- out = sqint(x)
312
+ out = integrate_fraction(x)
569
313
  if out is not None:
570
314
  x = out
571
315
  return x
316
+
572
317
  def integrate_full(root):
573
- root = integrate_definite(trig0(root))
318
+ root = trig0(root)
574
319
  def is_solved(x):
575
320
  x = solve_integrate(x)
576
321
  return "f_integrate" not in str_form(x)
@@ -12,10 +12,9 @@ from .inverse import inverse
12
12
 
13
13
  from .integrate import integrate_subs_main as integrate_subs
14
14
  from .integrate import byparts as integrate_byparts
15
- from .integrate import sqint as integrate_fraction
16
- from .integrate import conv_int
15
+ from .integrate import integrate_fraction
17
16
  from .integrate import solve_integrate as integrate_clean
18
- from .integrate import integrate_formula, integrate_full, integrate_definite
17
+ from .integrate import integrate_formula, integrate_full
19
18
  from .integrate import normalize as integration_basic
20
19
 
21
20
  from .diff import diff
@@ -356,6 +356,14 @@ def other_node(root):
356
356
  if child != tree_form("d_1")
357
357
  ])
358
358
  continue
359
+ if eq.name == "f_abs":
360
+ out = frac(eq.children[0])
361
+ if out is not None:
362
+ if out >= 0:
363
+ result_map[eq] = eq.children[0]
364
+ else:
365
+ result_map[eq] = -eq.children[0]
366
+ continue
359
367
  if eq.name == "f_sgn":
360
368
  out = frac(eq.children[0])
361
369
  if out is not None:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mathai
3
- Version: 2.3.4
3
+ Version: 2.3.6
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 setuptools import setup, find_packages
3
3
 
4
4
  setup(
5
5
  name="mathai",
6
- version="2.3.4",
6
+ version="2.3.6",
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",
@@ -1,24 +0,0 @@
1
- from .simplify import simplify
2
- from .base import *
3
- from .parser import parse
4
- from .formula_applier import formula_list_applier
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 = lambda x: formula_list_applier(x, 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
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