mathai 0.4.1__py3-none-any.whl → 0.4.2__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/integrate.py CHANGED
@@ -343,6 +343,7 @@ def integration_formula_init():
343
343
  (f"e^(A*{var}+B)", f"e^(A*{var}+B)/A"),\
344
344
  (f"1/cos({var})", f"log(abs((1+sin({var}))/cos({var})))"),\
345
345
  (f"1/cos({var})^2", f"sin({var})/cos({var})"),\
346
+ (f"1/sin({var})", f"log(abs(tan({var}/2)))"),\
346
347
  (f"abs(A*{var}+B)", f"(A*{var}+B)*abs(A*{var}+B)/(2*A)")]
347
348
  formula_list = [[simplify(parse(y)) for y in x] for x in formula_list]
348
349
  expr = [[parse("A"), parse("1")], [parse("B"), parse("0")]]
mathai/simplify.py CHANGED
@@ -279,6 +279,7 @@ def simplify(eq):
279
279
  return (eq.children[1-i].children[0]**eq.children[i]).fx("log")
280
280
  if eq.name == "f_pow" and eq.children[0] == tree_form("s_e") and eq.children[1].name == "f_log":
281
281
  return eq.children[1].children[0]
282
+
282
283
  if eq.name == "f_pow" and eq.children[0] == tree_form("d_1"):
283
284
  eq = tree_form("d_1")
284
285
  if eq.name == "f_pow" and eq.children[0] == tree_form("d_0"):
@@ -301,7 +302,7 @@ def simplify(eq):
301
302
  dic[head] = tail
302
303
  else:
303
304
  dic[head] += tail
304
- if len(eq.children) != len(dic.keys()):
305
+ if len(eq.children) > len(dic.keys()):
305
306
  eq = product([key if dic[key] == 1 else key**dic[key] for key in dic.keys()])
306
307
  if eq.name == "f_pow" and eq.children[0].name == "f_pow" and eq.children[0].children[1] == tree_form("d_2")**-1 and eq.children[1] == tree_form("d_2"):
307
308
  eq = eq.children[0].children[0]
@@ -315,7 +316,11 @@ def simplify(eq):
315
316
  eq = eq.children[0].children[0]
316
317
  if eq.name == "f_abs" and eq.children[0].name[:2] == "d_":
317
318
  eq = tree_form("d_"+str(abs(int(eq.children[0].name[2:]))))
318
-
319
+ if eq.name == "f_abs" and "v_" not in str_form(eq.children[0]):
320
+ if compute(eq.children[0]) > 0.00001:
321
+ eq = eq.children[0]
322
+ elif compute(eq.children[0]) < 0.00001:
323
+ eq = -eq.children[0]
319
324
  if eq.name == "f_pow" and eq.children[0].name[:2] == "d_" and frac(eq.children[1]) is not None:
320
325
  f = frac(eq.children[1])
321
326
  if f.denominator != 1:
mathai/trig.py CHANGED
@@ -169,7 +169,12 @@ def trig4(eq, numer=True):
169
169
  if eq.name == "f_sin":
170
170
  if eq.children[0].name == "f_add" and len(eq.children[0].children)>=2:
171
171
  r = len(eq.children[0].children)%2
172
- a, b = eq.children[0].children[:(len(eq.children[0].children)-r)/2], eq.children[0].children[(len(eq.children[0].children)-r)/2:]
172
+ a, b = TreeNode("f_add", eq.children[0].children[:round((len(eq.children[0].children)-r)/2)]),\
173
+ TreeNode("f_add", eq.children[0].children[round((len(eq.children[0].children)-r)/2):])
174
+ if len(a.children)==1:
175
+ a=a.children[0]
176
+ if len(b.children)==1:
177
+ b=b.children[0]
173
178
  return a.fx("sin")*b.fx("cos") + a.fx("cos")*b.fx("sin")
174
179
  if eq.children[0].name == "f_arccos":
175
180
  a = eq.children[0].children[0]
@@ -189,7 +194,12 @@ def trig4(eq, numer=True):
189
194
  if eq.name == "f_cos":
190
195
  if eq.children[0].name == "f_add" and len(eq.children[0].children)>=2:
191
196
  r = len(eq.children[0].children)%2
192
- a, b = eq.children[0].children[:(len(eq.children[0].children)-r)/2], eq.children[0].children[(len(eq.children[0].children)-r)/2:]
197
+ a, b = TreeNode("f_add", eq.children[0].children[:round((len(eq.children[0].children)-r)/2)]),\
198
+ TreeNode("f_add", eq.children[0].children[round((len(eq.children[0].children)-r)/2):])
199
+ if len(a.children)==1:
200
+ a=a.children[0]
201
+ if len(b.children)==1:
202
+ b=b.children[0]
193
203
  return a.fx("cos")*b.fx("cos") - a.fx("sin")*b.fx("sin")
194
204
  if eq.children[0].name == "f_arcsin":
195
205
  a = eq.children[0].children[0]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mathai
3
- Version: 0.4.1
3
+ Version: 0.4.2
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
@@ -6,20 +6,19 @@ mathai/diff.py,sha256=YUBpRsz0qmBkq5vGxeGnvR4nMKjdOQiIXlNMxpij2ns,3051
6
6
  mathai/expand.py,sha256=SnBltkpIENMGkP0AYmbMlSc4H-CF5RslO2PcBEkn1BQ,3359
7
7
  mathai/factor.py,sha256=NPXxET52TacNExuvw6p1jbC6g3wY6_VOCdlGlexXZio,5916
8
8
  mathai/fraction.py,sha256=Q2ztsh5Bpz6YhML2QU0tfufbAs0Q6J319AhlzKephIY,4396
9
- mathai/integrate.py,sha256=mKw_L8zccFifJINKLCFiYBrkgQM2qO_Pk8b2ShgxTa8,15065
9
+ mathai/integrate.py,sha256=a0zAndTUco7FhEDSkuQFtTNzh-5Q0E2_bYkYqWpbgu0,15133
10
10
  mathai/inverse.py,sha256=QCvDrzKquWsZv-BDAzZd9HnU0c3gZvcc44UztHVO5LQ,2919
11
11
  mathai/limit.py,sha256=RA8YAehgYCGVWv9qBc8uQ34BQ9mFthWl2OrVTwcHl2g,4920
12
12
  mathai/linear.py,sha256=BzSnm941Zlod_l6hON4Rs6J4pdAA3MGpRVqr6-66ZBk,5524
13
13
  mathai/logic.py,sha256=UvHzRmKcO9AD51tRzHmpNSEhgW5gmaf4XPaQKFjGfC4,9653
14
14
  mathai/parser.py,sha256=f7bemieFmp0sbup1NlraMLvZDVFvqKGFknEVtlFRMVk,6979
15
15
  mathai/printeq.py,sha256=gIes-pstFOa6FcnpVIVvkjVKuWdsVdo11LlEnmHhakU,1303
16
- mathai/search.py,sha256=6S_V0PrC2ZnbhkWyT2ZTtExRD_mDlo-C3p0TDn6Dk3w,4743
17
- mathai/simplify.py,sha256=qG23MRyVLjJL_8Xk5n4Z596bjihFvZg_zKtIvOqrLIk,15824
16
+ mathai/simplify.py,sha256=nxDjrQzC0wgF4BooBiHI_7mTdEJgygOSM97zx1zBR5c,16075
18
17
  mathai/structure.py,sha256=4Ww2IAx62RcQSO7_17TZES-DjMWBpcFQtL939FBIHwY,4103
19
18
  mathai/tool.py,sha256=UyccamiJy_CkFPakfufyPzdhtlEO6v2D7qwbXQ9V7Rg,2000
20
- mathai/trig.py,sha256=Zadw-uTJaMfoXwxuiio7QYHWgPxezEP2xZ2fr__PFM0,10290
19
+ mathai/trig.py,sha256=VYpn3_uuFrr9xOXBSOSGlwdlGHAAlGEzjA1ez-HsZxQ,10712
21
20
  mathai/univariate_inequality.py,sha256=_r-kkiS4Hr-jRN7f-EL_E4svAMFWJP1Ea50HJKKbjfk,14778
22
- mathai-0.4.1.dist-info/METADATA,sha256=m5N3sDp8R2_3ffySHyzvmo4YDpxYq6dT3FXUfkerCco,7021
23
- mathai-0.4.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
24
- mathai-0.4.1.dist-info/top_level.txt,sha256=ROP4l3OhGYw3ihkQGASr18xM9GsK4z3_6whV5AyXLwE,7
25
- mathai-0.4.1.dist-info/RECORD,,
21
+ mathai-0.4.2.dist-info/METADATA,sha256=fXzD9pbztl7ku4RJ2BRJosBOXoe1R6uj-SDiTnyRbgM,7021
22
+ mathai-0.4.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
23
+ mathai-0.4.2.dist-info/top_level.txt,sha256=ROP4l3OhGYw3ihkQGASr18xM9GsK4z3_6whV5AyXLwE,7
24
+ mathai-0.4.2.dist-info/RECORD,,
mathai/search.py DELETED
@@ -1,117 +0,0 @@
1
- from mathai import *
2
- import copy
3
- from concurrent.futures import ThreadPoolExecutor, TimeoutError
4
-
5
- def dfs_simplify(equation, functions, true_expr, false_expr,
6
- max_timeout=25, max_small=4,
7
- base_timeout=1, time_per_char=0.1, timeout_increase=0.5):
8
- """
9
- Perform DFS simplification on a given equation using provided functions.
10
-
11
- Args:
12
- equation: The starting expression (TreeNode or parsed equation)
13
- functions: List of simplification functions
14
- true_expr: Expression representing True (immediate termination)
15
- false_expr: Expression representing False (immediate termination)
16
- max_timeout: Maximum timeout allowed for any function
17
- max_small: Number of smallest expressions to track
18
- base_timeout: Base timeout in seconds
19
- time_per_char: Additional timeout per character of expression
20
- timeout_increase: Factor to increase timeout for consecutive timeouts
21
-
22
- Returns:
23
- tuple(found_boolean, boolean_path, smallest_expressions)
24
- """
25
- original_eq = simplify(equation)
26
- smallest_four = []
27
-
28
- stack = [(copy.deepcopy(original_eq), [copy.deepcopy(original_eq)])]
29
- visited = set()
30
-
31
- found_boolean = False
32
- boolean_path = None
33
- boolean_expr = None
34
-
35
- executor = ThreadPoolExecutor(max_workers=3)
36
- consecutive_timeouts = 0
37
-
38
- while stack and not found_boolean:
39
- current_eq, path = stack.pop()
40
- expr_str = str(current_eq)
41
-
42
- if expr_str in visited:
43
- continue
44
- visited.add(expr_str)
45
-
46
- # Thinking message
47
- printeq(current_eq)
48
-
49
- # Immediate termination using predicate functions
50
- if true_expr(current_eq):
51
- found_boolean = True
52
- boolean_path = path
53
- boolean_expr = current_eq
54
- break
55
- if false_expr(current_eq):
56
- found_boolean = True
57
- boolean_path = path
58
- boolean_expr = current_eq
59
- break
60
-
61
-
62
- # Insert into smallest_four if qualifies
63
- inserted = False
64
- for j in range(len(smallest_four)):
65
- if len(expr_str) < len(str(smallest_four[j][0])):
66
- smallest_four.insert(j, (copy.deepcopy(current_eq), copy.deepcopy(path)))
67
- inserted = True
68
- break
69
- if not inserted and len(smallest_four) < max_small:
70
- smallest_four.append((copy.deepcopy(current_eq), copy.deepcopy(path)))
71
- if len(smallest_four) > max_small:
72
- smallest_four = smallest_four[:max_small]
73
-
74
- # Calculate adaptive timeout with cap
75
- timeout = (base_timeout + time_per_char * len(expr_str)) * (1 + timeout_increase * consecutive_timeouts)
76
- if timeout > max_timeout:
77
- timeout = max_timeout
78
-
79
- # Try functions that reduce length first
80
- reduced_any = False
81
- for fx in functions:
82
- print(f"[Thinking] Executing {fx.__name__} on current expression (timeout={timeout:.2f}s):")
83
- printeq(current_eq)
84
- future = executor.submit(fx, current_eq)
85
- try:
86
- new_expr = future.result(timeout=timeout)
87
- new_expr_str = str(new_expr)
88
- if len(new_expr_str) <= len(expr_str) and new_expr_str != expr_str:
89
- reduced_any = True
90
- stack.append((new_expr, path + [copy.deepcopy(new_expr)]))
91
- consecutive_timeouts = 0 # reset after success
92
- except TimeoutError:
93
- print(f"[Thinking] {fx.__name__} timed out, skipping.")
94
- consecutive_timeouts += 1
95
- continue
96
-
97
- # If no reducing function worked, try growing functions
98
- if not reduced_any:
99
- for fx in functions:
100
- print(f"[Thinking] Trying growing {fx.__name__} on current expression (timeout={timeout:.2f}s):")
101
- printeq(current_eq)
102
- future = executor.submit(fx, current_eq)
103
- try:
104
- new_expr = future.result(timeout=timeout)
105
- new_expr_str = str(new_expr)
106
- if new_expr_str != expr_str:
107
- stack.append((new_expr, path + [copy.deepcopy(new_expr)]))
108
- consecutive_timeouts = 0
109
- break # only take one growing function
110
- except TimeoutError:
111
- print(f"[Thinking] {fx.__name__} (growing) timed out, skipping.")
112
- consecutive_timeouts += 1
113
- continue
114
-
115
- executor.shutdown(wait=True)
116
-
117
- return found_boolean, boolean_path, smallest_four
File without changes