mathai 0.4.6__py3-none-any.whl → 0.4.7__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/__init__.py CHANGED
@@ -1,6 +1,8 @@
1
1
  from .ode import diffsolve as ode_solve
2
2
  from .ode import diffsolve_sep as ode_shift_term
3
3
 
4
+ from .linear import linear_solve
5
+
4
6
  from .expand import expand
5
7
 
6
8
  from .parser import parse
mathai/factor.py CHANGED
@@ -5,6 +5,7 @@ from .base import *
5
5
  from .simplify import simplify,solve
6
6
  from .expand import expand
7
7
  import math
8
+ from .tool import poly
8
9
 
9
10
  from collections import Counter
10
11
  def multiset_intersection(*lists):
@@ -158,12 +159,6 @@ def rationalize_sqrt(eq):
158
159
  return TreeNode(eq.name, [rationalize_sqrt(child) for child in eq.children])
159
160
  def factorconst(eq):
160
161
  return simplify(_factorconst(eq))
161
- def factor_quad_formula_init():
162
- var = ""
163
- formula_list = [(f"(A*D^2+B*D+C)", f"A*(D-(-B+(B^2-4*A*C)^(1/2))/(2*A))*(D-(-B-(B^2-4*A*C)^(1/2))/(2*A))")]
164
- formula_list = [[simplify(parse(y)) for y in x] for x in formula_list]
165
- expr = [[parse("A"), parse("1")], [parse("B"), parse("0"), parse("1")], [parse("C"), parse("0")]]
166
- return [formula_list, var, expr]
167
162
 
168
163
  def factor_quar_formula_init():
169
164
  var = ""
@@ -171,44 +166,103 @@ def factor_quar_formula_init():
171
166
  formula_list = [[simplify(parse(y)) for y in x] for x in formula_list]
172
167
  expr = [[parse("A")], [parse("B"), parse("0"), parse("1")], [parse("C"), parse("0")]]
173
168
  return [formula_list, var, expr]
174
- def factor_cube_formula_init():
175
- var = ""
176
- formula_list = [(f"D^3+E", f"(D+E^(1/3))*(D^2-D*E^(1/3)+E^(2/3))"), (f"D^3-E", f"(D-E^(1/3))*(D^2+D*E^(1/3)+E^(2/3))"),\
177
- (f"-D^3+E", f"(-D+E^(1/3))*(D^2+D*E^(1/3)+E^(2/3))")]
178
- formula_list = [[simplify(parse(y)) for y in x] for x in formula_list]
179
- expr = [[parse("A")], [parse("B")]]
180
- return [formula_list, var, expr]
181
- formula_gen2 = factor_quad_formula_init()
182
- formula_gen3 = factor_cube_formula_init()
169
+
183
170
  formula_gen9 = factor_quar_formula_init()
184
171
  def factor_helper(equation, complexnum, power=2):
185
- global formula_gen2, formula_gen3, formula_gen9
186
- maxnum = 1
172
+ global formula_gen9
173
+
174
+ maxnum=1
175
+ alloclst = []
176
+ for i in range(0,26):
177
+ if "v_"+str(i) not in vlist(equation):
178
+ alloclst.append("v_"+str(i))
179
+ r = alloclst.pop(0)
180
+ fx = None
181
+ curr = None
187
182
  def high(eq):
188
183
  nonlocal maxnum
189
184
  if eq.name == "f_pow" and eq.children[1].name[:2] == "d_":
190
185
  n = int(eq.children[1].name[2:])
191
- if n>power and n % power == 0:
192
- maxnum = max(maxnum, n)
186
+ if abs(n)>power and abs(n) % power == 0:
187
+ if abs(n)>abs(maxnum):
188
+ maxnum = n
193
189
  for child in eq.children:
194
190
  high(child)
195
191
  def helper(eq):
196
- nonlocal maxnum
192
+ nonlocal maxnum, fx, r
197
193
  if eq.name == "f_pow" and eq.children[1].name[:2] == "d_":
198
194
  n = int(eq.children[1].name[2:])
199
- sgn = round(abs(n)/n)
200
- n = abs(n)
201
- if n>power and n % power == 0 and maxnum==n:
202
- out= (eq.children[0]**tree_form("d_"+str(sgn*int(n/power))))**power
195
+ if maxnum !=1 and n % maxnum == 0:
196
+ fx = lambda x: replace(x, tree_form(r), curr**tree_form("d_"+str(maxnum)))
197
+ out= tree_form(r)**tree_form("d_"+str(int(n/maxnum)))
203
198
  return out
204
199
  return TreeNode(eq.name, [helper(child) for child in eq.children])
205
- high(equation)
206
200
  out = None
207
- if power == 2:
208
- out = transform_formula(helper(equation), "v_0", formula_gen2[0], formula_gen2[1], formula_gen2[2])
209
- elif power == 3:
210
- out = transform_formula(helper(equation), "v_0", formula_gen3[0], formula_gen3[1], formula_gen3[2])
211
- elif power == 4:
201
+ for i in range(2,4):
202
+ if power == i:
203
+ for curr in vlist(equation):
204
+ curr = tree_form(curr)
205
+ fx = None
206
+ maxnum = 1
207
+ high(equation)
208
+
209
+ if maxnum != 1:
210
+ maxnum= maxnum/power
211
+ maxnum = round(maxnum)
212
+ eq2 = helper(equation)
213
+ if not contain(eq2, tree_form(r)) or (contain(eq2, tree_form(r)) and not contain(eq2,curr)):
214
+ if not contain(eq2, tree_form(r)):
215
+ r = curr.name
216
+ fx = lambda x: x
217
+
218
+ lst = poly(eq2.copy_tree(), r)
219
+ if lst is not None and len(lst)==i+1:
220
+
221
+ success = True
222
+ if i == 2:
223
+ a, b, c = lst
224
+ x1 = (-b+(b**2 - 4*a*c)**(tree_form("d_2")**-1))/(2*a)
225
+ x2 = (-b-(b**2 - 4*a*c)**(tree_form("d_2")**-1))/(2*a)
226
+ x1 = simplify(x1)
227
+ x2 = simplify(x2)
228
+ eq2 = a*(tree_form(r)-x1)*(tree_form(r)-x2)
229
+ if not complexnum and (contain(x1, tree_form("s_i")) or contain(x2, tree_form("s_i"))):
230
+ success = False
231
+ else:
232
+ a, b, c, d = lst
233
+ B, C, D = b/a, c/a, d/a
234
+ p = C-(B**2)/3
235
+ q = 2*B**3/27-B*C/3+D
236
+ t = q**2/4+ p**3/27
237
+ u = (-q/2+t**(tree_form("d_2")**-1))**(tree_form("d_3")**-1)
238
+ v = (-q/2-t**(tree_form("d_2")**-1))**(tree_form("d_3")**-1)
239
+ y1 = u+v
240
+ three = 3**(tree_form("d_2")**-1)
241
+ y2 = -(u+v)/2+tree_form("s_i")*three*(u-v)/2
242
+ y3 = -(u+v)/2-tree_form("s_i")*three*(u-v)/2
243
+ x1,x2,x3 = y1-B/3 , y2-B/3, y3-B/3
244
+ x1,x2, x3 = simplify(x1), simplify(x2), simplify(x3)
245
+ out2 = None
246
+ if not complexnum:
247
+ for item in itertools.combinations([x1,x2,x3],2):
248
+ if all(contain(item2,tree_form("s_i")) for item2 in list(item)):
249
+ out2 = (tree_form(r)-item[0])*(tree_form(r)-item[1])
250
+ break
251
+ if out2 is not None:
252
+ out2 = simplify(expand(simplify(out2)))
253
+ out3 = None
254
+ for item in [x1, x2, x3]:
255
+ if not contain(item,tree_form("s_i")):
256
+ out3 = item
257
+ break
258
+ eq2 = a*(tree_form(r)-out3)*out2
259
+
260
+ else:
261
+ eq2 = a*(tree_form(r)-x1)*(tree_form(r)-x2)*(tree_form(r)-x3)
262
+ if success:
263
+ equation = fx(eq2)
264
+ break
265
+ if power == 4:
212
266
  out = transform_formula(helper(equation), "v_0", formula_gen9[0], formula_gen9[1], formula_gen9[2])
213
267
  if out is not None:
214
268
  out = simplify(solve(out))
mathai/simplify.py CHANGED
@@ -287,7 +287,9 @@ def simplify(eq):
287
287
  error = True
288
288
  else:
289
289
  eq = tree_form("d_0")
290
-
290
+ if eq.name =="f_pow" and eq.children[0] == tree_form("s_i") and frac(eq.children[1])is not None and frac(eq.children[1]).denominator == 1:
291
+ n = frac(eq.children[1]).numerator
292
+ eq = {0:tree_form("d_1"), 1:tree_form("s_i"), 2:tree_form("d_-1"), 3:-tree_form("s_i")}[n%4]
291
293
  if eq.name == "f_mul":
292
294
  dic = {}
293
295
  for child in eq.children:
mathai/tool.py CHANGED
@@ -36,7 +36,12 @@ def poly(eq, to_compute):
36
36
  eq = replace(eq, tree_form(var), tree_form("d_"+str(val)))
37
37
  return eq
38
38
  def inv(eq):
39
- if eq.name == "f_pow" and "v_" in str_form(eq.children[0]) and eq.children[1] == tree_form("d_-1"):
39
+ if eq.name =="f_eq":
40
+ return False
41
+ if eq.name[2:] in ["sin", "cos", "log"] and contain(eq.children[0], tree_form(to_compute)):
42
+ return False
43
+ if eq.name == "f_pow" and contain(eq.children[0], tree_form(to_compute)) and\
44
+ (frac(eq.children[1]) is None or frac(eq.children[1]) < 0 or frac(eq.children[1]).denominator != 1):
40
45
  return False
41
46
  if eq.name == "f_abs":
42
47
  return False
@@ -47,7 +52,7 @@ def poly(eq, to_compute):
47
52
  return None
48
53
  out = []
49
54
  eq2 = eq
50
- for i in range(10):
55
+ for i in range(8):
51
56
  out.append(expand(simplify(eq2)))
52
57
  eq2 = diff(eq2, to_compute)
53
58
  for i in range(len(out)-1,-1,-1):
mathai/trig.py CHANGED
@@ -58,6 +58,9 @@ def trig0(eq):
58
58
  if a > b:
59
59
  a = 2*b - a
60
60
  return a, b
61
+ if eq.name == "f_arccosec":
62
+ return (1/eq.children[0]).fx("arcsin")
63
+
61
64
  if eq.name == "f_arctan":
62
65
  if eq.children[0].name == "d_0":
63
66
  return tree_form("d_0")
@@ -164,52 +167,59 @@ def _trig1(equation):
164
167
  return TreeNode(equation.name, [_trig1(child) for child in equation.children])
165
168
  def trig1(eq):
166
169
  return simplify(_trig1(noneg_pow(eq)))
167
-
168
- def trig4(eq, numer=True):
169
- if eq.name == "f_sin":
170
- if eq.children[0].name == "f_add" and len(eq.children[0].children)>=2:
171
- r = len(eq.children[0].children)%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]
178
- return a.fx("sin")*b.fx("cos") + a.fx("cos")*b.fx("sin")
179
- if eq.children[0].name == "f_arccos":
180
- a = eq.children[0].children[0]
181
- return (1-a**2)**(tree_form("d_2")**-1)
182
- if eq.children[0].name == "f_arctan":
183
- a = eq.children[0].children[0]
184
- return a/(1+a**2)**(tree_form("d_2")**-1)
185
- if eq.name == "f_pow" and numer:
186
- if eq.children[0].name == "f_cos":
187
- a = eq.children[0].children[0]
188
- if frac(eq.children[1]) == 2:
189
- return 1 - a.fx("sin")**2
190
- if eq.children[0].name == "f_sin":
191
- a = eq.children[0].children[0]
192
- if frac(eq.children[1]) == 2:
193
- return 1 - a.fx("cos")**2
194
- if eq.name == "f_cos":
195
- if eq.children[0].name == "f_add" and len(eq.children[0].children)>=2:
196
- r = len(eq.children[0].children)%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]
203
- return a.fx("cos")*b.fx("cos") - a.fx("sin")*b.fx("sin")
204
- if eq.children[0].name == "f_arcsin":
205
- a = eq.children[0].children[0]
206
- return (1-a**2)**(tree_form("d_2")**-1)
207
- if eq.children[0].name == "f_arctan":
208
- a = eq.children[0].children[0]
209
- return tree_form("d_1")/(1+a**2)**(tree_form("d_2")**-1)
210
-
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
-
170
+ def trig4(eq):
171
+ done = False
172
+ def _trig4(eq, numer=True, chance="sin"):
173
+ nonlocal done
174
+ if eq.name == "f_sin":
175
+ if eq.children[0].name == "f_add" and len(eq.children[0].children)>=2:
176
+ r = len(eq.children[0].children)%2
177
+ a, b = TreeNode("f_add", eq.children[0].children[:round((len(eq.children[0].children)-r)/2)]),\
178
+ TreeNode("f_add", eq.children[0].children[round((len(eq.children[0].children)-r)/2):])
179
+ if len(a.children)==1:
180
+ a=a.children[0]
181
+ if len(b.children)==1:
182
+ b=b.children[0]
183
+ return a.fx("sin")*b.fx("cos") + a.fx("cos")*b.fx("sin")
184
+ if eq.children[0].name == "f_arccos":
185
+ a = eq.children[0].children[0]
186
+ return (1-a**2)**(tree_form("d_2")**-1)
187
+ if eq.children[0].name == "f_arctan":
188
+ a = eq.children[0].children[0]
189
+ return a/(1+a**2)**(tree_form("d_2")**-1)
190
+ if eq.name == "f_pow" and numer:
191
+ if eq.children[0].name == "f_cos" and chance == "cos":
192
+ a = eq.children[0].children[0]
193
+ if frac(eq.children[1]) == 2:
194
+ done = True
195
+ return 1 - a.fx("sin")**2
196
+ if eq.children[0].name == "f_sin" and chance == "cos":
197
+ a = eq.children[0].children[0]
198
+ if frac(eq.children[1]) == 2:
199
+ done = True
200
+ return 1 - a.fx("cos")**2
201
+ if eq.name == "f_cos":
202
+ if eq.children[0].name == "f_add" and len(eq.children[0].children)>=2:
203
+ r = len(eq.children[0].children)%2
204
+ a, b = TreeNode("f_add", eq.children[0].children[:round((len(eq.children[0].children)-r)/2)]),\
205
+ TreeNode("f_add", eq.children[0].children[round((len(eq.children[0].children)-r)/2):])
206
+ if len(a.children)==1:
207
+ a=a.children[0]
208
+ if len(b.children)==1:
209
+ b=b.children[0]
210
+ return a.fx("cos")*b.fx("cos") - a.fx("sin")*b.fx("sin")
211
+ if eq.children[0].name == "f_arcsin":
212
+ a = eq.children[0].children[0]
213
+ return (1-a**2)**(tree_form("d_2")**-1)
214
+ if eq.children[0].name == "f_arctan":
215
+ a = eq.children[0].children[0]
216
+ return tree_form("d_1")/(1+a**2)**(tree_form("d_2")**-1)
217
+
218
+ return TreeNode(eq.name, [_trig4(child, False, chance) 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, chance) for child in eq.children])
219
+ eq= _trig4(eq)
220
+ if not done:
221
+ eq = _trig4(eq,"cos")
222
+ return eq
213
223
  def trig2(eq):
214
224
  # Base case: if not an addition, recurse into children
215
225
  if eq.name != "f_add":
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mathai
3
- Version: 0.4.6
3
+ Version: 0.4.7
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
@@ -1,10 +1,10 @@
1
- mathai/__init__.py,sha256=HiH4VCvWd5r4o5iNLSbKJlOnpRWDBW-Na_8TQRUggz8,1348
1
+ mathai/__init__.py,sha256=VXMMBsOe6R2lXW6R_KhWW7FtlNnj6sF3awsbh_IMWD0,1384
2
2
  mathai/apart.py,sha256=8IlJ8X6SKAjPunUPHVLmgNB5GuEi4_XpY0oLkQqrHKc,3770
3
3
  mathai/base.py,sha256=Hy2y-Nc2aXOst2WoRTuWgnlppgKsKguG9slPQbenRGk,12726
4
4
  mathai/console.py,sha256=Sn58iwYE79MLEh67s8X3q6vZjw6g7f9XM1T8_dBBR2o,3048
5
5
  mathai/diff.py,sha256=YUBpRsz0qmBkq5vGxeGnvR4nMKjdOQiIXlNMxpij2ns,3051
6
6
  mathai/expand.py,sha256=SnBltkpIENMGkP0AYmbMlSc4H-CF5RslO2PcBEkn1BQ,3359
7
- mathai/factor.py,sha256=vuTxFZcjAdjXC-202QmDzDLsqEGOUyAG2rr_n2CgOZ8,8735
7
+ mathai/factor.py,sha256=srUta3WaZlSdXA1Pzf6NPtqKheax4BWudky5brjf7xw,11282
8
8
  mathai/fraction.py,sha256=Q2ztsh5Bpz6YhML2QU0tfufbAs0Q6J319AhlzKephIY,4396
9
9
  mathai/integrate.py,sha256=gWkSIA-4XoAfocdfBSL5dmuadPF0QRCEfaTjz6BXHv4,15161
10
10
  mathai/inverse.py,sha256=QCvDrzKquWsZv-BDAzZd9HnU0c3gZvcc44UztHVO5LQ,2919
@@ -14,12 +14,12 @@ mathai/logic.py,sha256=UvHzRmKcO9AD51tRzHmpNSEhgW5gmaf4XPaQKFjGfC4,9653
14
14
  mathai/ode.py,sha256=zxxTXAOpt7oSsfpgI4vHsCWKXevmM96ZOBZWWs-vj8Y,4801
15
15
  mathai/parser.py,sha256=f7bemieFmp0sbup1NlraMLvZDVFvqKGFknEVtlFRMVk,6979
16
16
  mathai/printeq.py,sha256=gIes-pstFOa6FcnpVIVvkjVKuWdsVdo11LlEnmHhakU,1303
17
- mathai/simplify.py,sha256=x9ac0CYZ6LrLwlUJZDDqV-QbTNwLAHkrWfarcTCZKM0,16231
17
+ mathai/simplify.py,sha256=KHZkvQOy-zU4Y_8URWxGVRMrbGSo-kjBLvFeJ11YSdw,16523
18
18
  mathai/structure.py,sha256=4Ww2IAx62RcQSO7_17TZES-DjMWBpcFQtL939FBIHwY,4103
19
- mathai/tool.py,sha256=UyccamiJy_CkFPakfufyPzdhtlEO6v2D7qwbXQ9V7Rg,2000
20
- mathai/trig.py,sha256=1VLEo5QvBbfoQHPdtzJ_65c1BHklesk9H0bAlvNyT7A,10543
19
+ mathai/tool.py,sha256=HlQc5RtsPTGlGUW0poVfHgzQzFDXNtFXJgUsWcwefuw,2273
20
+ mathai/trig.py,sha256=uN1de4SYWo8LhCjy6XCRkvd_VSwzLiUgfZioenjrjbA,11078
21
21
  mathai/univariate_inequality.py,sha256=_r-kkiS4Hr-jRN7f-EL_E4svAMFWJP1Ea50HJKKbjfk,14778
22
- mathai-0.4.6.dist-info/METADATA,sha256=2eERLHKi7slZrL2Tk21RX5tDXjtn6xkxCVJUngG8MN8,7021
23
- mathai-0.4.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
24
- mathai-0.4.6.dist-info/top_level.txt,sha256=ROP4l3OhGYw3ihkQGASr18xM9GsK4z3_6whV5AyXLwE,7
25
- mathai-0.4.6.dist-info/RECORD,,
22
+ mathai-0.4.7.dist-info/METADATA,sha256=oXc7poWa0rZ_vkOdoweennkqHhkSzHPID8Ce8RLQSJU,7021
23
+ mathai-0.4.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
24
+ mathai-0.4.7.dist-info/top_level.txt,sha256=ROP4l3OhGYw3ihkQGASr18xM9GsK4z3_6whV5AyXLwE,7
25
+ mathai-0.4.7.dist-info/RECORD,,
File without changes