mathai 0.4.4__py3-none-any.whl → 0.4.5__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/trig.py CHANGED
@@ -82,7 +82,7 @@ def trig0(eq):
82
82
  if any(isneg(item) for item in lst):
83
83
  return -(eq.children[0]*-1).fx("sin")
84
84
  out=single_pi(lst)
85
- if out is not None:
85
+ if out is not None and tuple(out) in trig_sin_table.keys():
86
86
  return trig_sin_table[tuple(out)]
87
87
 
88
88
  if eq.name == "f_cos":
@@ -211,35 +211,38 @@ def trig4(eq, numer=True):
211
211
  return TreeNode(eq.name, [trig4(child, False) if not numer or (eq.name == "f_pow" and frac(eq.children[1]) is not None and frac(eq.children[1]) < 0) else trig4(child, True) for child in eq.children])
212
212
 
213
213
  def trig2(eq):
214
- if eq.name == "f_add":
215
- for item in itertools.combinations(range(len(eq.children)), 2):
216
- child1, child2 = eq.children[item[0]], eq.children[item[1]]
214
+ # Base case: if not an addition, recurse into children
215
+ if eq.name != "f_add":
216
+ return TreeNode(eq.name, [trig2(child) for child in eq.children])
217
+
218
+ # Try all pairs in the addition
219
+ for i, j in itertools.combinations(range(len(eq.children)), 2):
220
+ c1, c2 = eq.children[i], eq.children[j]
221
+
222
+ # Combine only sin/sin or cos/cos
223
+ if c1.name in ["f_sin", "f_cos"] and c2.name in ["f_sin", "f_cos"]:
224
+ A, B = c1.children[0], c2.children[0]
225
+ rest = [eq.children[k] for k in range(len(eq.children)) if k not in (i, j)]
226
+ rest_tree = summation(rest) if rest else tree_form("d_0")
217
227
 
218
- # Check if both are sin or cos
219
- if child1.name in ["f_sin", "f_cos"] and child2.name in ["f_sin", "f_cos"]:
220
- a, b = child1.children[0], child2.children[0]
221
-
222
- # Compute the rest of the sum
223
- rest = [eq.children[i] for i in range(len(eq.children)) if i not in item]
224
- if len(rest) == 0:
225
- rest_tree = tree_form("d_0")
226
- else:
227
- rest_tree = summation(rest)
228
+ two = tree_form("d_2")
228
229
 
229
- # Now handle the sin/cos combination formula
230
- if child1.name == "f_sin" and child2.name == "f_sin":
231
- # sin A + sin B = 2 sin((A+B)/2) cos((A-B)/2)
232
- two = tree_form("d_2")
233
- combined = two * ((a + b) / two).fx("sin") * ((a - b) / two).fx("cos")
234
- elif child1.name == "f_cos" and child2.name == "f_cos":
235
- # cos A + cos B = 2 cos((A+B)/2) cos((A-B)/2)
236
- two = tree_form("d_2")
237
- combined = two * ((a + b) / two).fx("cos") * ((a - b) / two).fx("cos")
238
- else:
239
- # sin A + cos B = sin A + cos B (leave unchanged, or implement formula if desired)
240
- continue # skip for now, keep original
230
+ # sinA + sinB
231
+ if c1.name == "f_sin" and c2.name == "f_sin":
232
+ combined = two * ((A + B) / two).fx("sin") * ((A - B) / two).fx("cos")
241
233
 
242
- return rest_tree + combined
234
+ # cosA + cosB
235
+ elif c1.name == "f_cos" and c2.name == "f_cos":
236
+ combined = two * ((A + B) / two).fx("cos") * ((A - B) / two).fx("cos")
243
237
 
244
- # Recurse for other nodes
238
+ # sinA + cosB (leave unchanged)
239
+ else:
240
+ continue
241
+
242
+ new_expr = rest_tree + combined
243
+ # Re-run trig2 in case there are more sin/cos sums to simplify
244
+ return trig2(new_expr)
245
+
246
+ # If no sin/cos pairs found, just recurse on children
245
247
  return TreeNode(eq.name, [trig2(child) for child in eq.children])
248
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mathai
3
- Version: 0.4.4
3
+ Version: 0.4.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
@@ -16,9 +16,9 @@ mathai/printeq.py,sha256=gIes-pstFOa6FcnpVIVvkjVKuWdsVdo11LlEnmHhakU,1303
16
16
  mathai/simplify.py,sha256=aEvpkhaDowgyQWPSxHKshcVIMngZ4NBVc2yuiCYqOYI,16229
17
17
  mathai/structure.py,sha256=4Ww2IAx62RcQSO7_17TZES-DjMWBpcFQtL939FBIHwY,4103
18
18
  mathai/tool.py,sha256=UyccamiJy_CkFPakfufyPzdhtlEO6v2D7qwbXQ9V7Rg,2000
19
- mathai/trig.py,sha256=VYpn3_uuFrr9xOXBSOSGlwdlGHAAlGEzjA1ez-HsZxQ,10712
19
+ mathai/trig.py,sha256=1VLEo5QvBbfoQHPdtzJ_65c1BHklesk9H0bAlvNyT7A,10543
20
20
  mathai/univariate_inequality.py,sha256=_r-kkiS4Hr-jRN7f-EL_E4svAMFWJP1Ea50HJKKbjfk,14778
21
- mathai-0.4.4.dist-info/METADATA,sha256=LeMmNLbtXxWcr6eME07Yd9HS-bDS4jLPeQe1wa-dZds,7021
22
- mathai-0.4.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
23
- mathai-0.4.4.dist-info/top_level.txt,sha256=ROP4l3OhGYw3ihkQGASr18xM9GsK4z3_6whV5AyXLwE,7
24
- mathai-0.4.4.dist-info/RECORD,,
21
+ mathai-0.4.5.dist-info/METADATA,sha256=oryIRWZw-NGvmk5Uu-F_5zAxp0RonwuxZ-HxExh1_hc,7021
22
+ mathai-0.4.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
23
+ mathai-0.4.5.dist-info/top_level.txt,sha256=ROP4l3OhGYw3ihkQGASr18xM9GsK4z3_6whV5AyXLwE,7
24
+ mathai-0.4.5.dist-info/RECORD,,
File without changes