mathai 0.5.0__tar.gz → 0.5.2__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 (32) hide show
  1. {mathai-0.5.0 → mathai-0.5.2}/PKG-INFO +1 -1
  2. {mathai-0.5.0 → mathai-0.5.2}/mathai/__init__.py +2 -0
  3. {mathai-0.5.0 → mathai-0.5.2}/mathai/bivariate_inequality.py +32 -11
  4. {mathai-0.5.0 → mathai-0.5.2}/mathai/factor.py +2 -1
  5. {mathai-0.5.0 → mathai-0.5.2}/mathai/linear.py +20 -12
  6. mathai-0.5.2/mathai/matrix.py +22 -0
  7. {mathai-0.5.0 → mathai-0.5.2}/mathai/simplify.py +6 -1
  8. {mathai-0.5.0 → mathai-0.5.2}/mathai/univariate_inequality.py +9 -1
  9. {mathai-0.5.0 → mathai-0.5.2}/mathai.egg-info/PKG-INFO +1 -1
  10. {mathai-0.5.0 → mathai-0.5.2}/mathai.egg-info/SOURCES.txt +1 -0
  11. {mathai-0.5.0 → mathai-0.5.2}/setup.py +1 -1
  12. {mathai-0.5.0 → mathai-0.5.2}/README.md +0 -0
  13. {mathai-0.5.0 → mathai-0.5.2}/mathai/apart.py +0 -0
  14. {mathai-0.5.0 → mathai-0.5.2}/mathai/base.py +0 -0
  15. {mathai-0.5.0 → mathai-0.5.2}/mathai/console.py +0 -0
  16. {mathai-0.5.0 → mathai-0.5.2}/mathai/diff.py +0 -0
  17. {mathai-0.5.0 → mathai-0.5.2}/mathai/expand.py +0 -0
  18. {mathai-0.5.0 → mathai-0.5.2}/mathai/fraction.py +0 -0
  19. {mathai-0.5.0 → mathai-0.5.2}/mathai/integrate.py +0 -0
  20. {mathai-0.5.0 → mathai-0.5.2}/mathai/inverse.py +0 -0
  21. {mathai-0.5.0 → mathai-0.5.2}/mathai/limit.py +0 -0
  22. {mathai-0.5.0 → mathai-0.5.2}/mathai/logic.py +0 -0
  23. {mathai-0.5.0 → mathai-0.5.2}/mathai/ode.py +0 -0
  24. {mathai-0.5.0 → mathai-0.5.2}/mathai/parser.py +0 -0
  25. {mathai-0.5.0 → mathai-0.5.2}/mathai/printeq.py +0 -0
  26. {mathai-0.5.0 → mathai-0.5.2}/mathai/structure.py +0 -0
  27. {mathai-0.5.0 → mathai-0.5.2}/mathai/tool.py +0 -0
  28. {mathai-0.5.0 → mathai-0.5.2}/mathai/trig.py +0 -0
  29. {mathai-0.5.0 → mathai-0.5.2}/mathai.egg-info/dependency_links.txt +0 -0
  30. {mathai-0.5.0 → mathai-0.5.2}/mathai.egg-info/requires.txt +0 -0
  31. {mathai-0.5.0 → mathai-0.5.2}/mathai.egg-info/top_level.txt +0 -0
  32. {mathai-0.5.0 → mathai-0.5.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mathai
3
- Version: 0.5.0
3
+ Version: 0.5.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
@@ -44,6 +44,8 @@ from .limit import limit
44
44
  from .univariate_inequality import wavycurvy, absolute, domain, handle_sqrt
45
45
  from .bivariate_inequality import inequality_solve
46
46
 
47
+ from .matrix import uncommute
48
+
47
49
  from .base import *
48
50
 
49
51
  from .tool import enclose_const
@@ -4,6 +4,9 @@ from functools import reduce
4
4
  import operator
5
5
  from .base import *
6
6
  from .simplify import simplify
7
+ from .expand import expand
8
+ from .logic import logic0
9
+
7
10
  def shoelace_area(vertices):
8
11
  n = len(vertices)
9
12
  area = 0.0
@@ -73,8 +76,6 @@ def deterministic_middle_point(vertices, grid_resolution=100):
73
76
  return best_point
74
77
 
75
78
  def build(eq):
76
- if len(eq) <= 1:
77
- return None
78
79
  eq = TreeNode("f_or", eq)
79
80
  eq = flatten_tree(eq)
80
81
  orig = eq.copy_tree()
@@ -85,15 +86,21 @@ def build(eq):
85
86
  eq = fxhelper3(eq)
86
87
 
87
88
  result = linear_or(eq)
89
+
90
+ if result is None:
91
+ return None
92
+
88
93
  maxnum = tree_form("d_2")
89
94
  if len(result[1]) != 0:
90
95
  maxnum = max([max([simplify(item2.fx("abs")) for item2 in item], key=lambda x: compute(x)) for item in result[1]], key=lambda x: compute(x))
91
96
  maxnum += 1
92
97
  maxnum = simplify(maxnum)
93
98
  eq = flatten_tree(eq | simplify(TreeNode("f_or", [TreeNode("f_eq", [tree_form(item)+maxnum, tree_form("d_0")])|\
94
- TreeNode("f_eq", [tree_form(item)-maxnum, tree_form("d_0")]) for item in vlist(eq)])))
99
+ TreeNode("f_eq", [tree_form(item)-maxnum, tree_form("d_0")]) for item in ["v_0","v_1"]])))
95
100
  result2 = linear_or(eq)
96
-
101
+ if result2 is None:
102
+ return None
103
+
97
104
  point_lst = result2[2]
98
105
 
99
106
  def gen(point):
@@ -175,6 +182,7 @@ def build(eq):
175
182
  cycles.pop(i)
176
183
 
177
184
  point_lst = [index for index, item in enumerate(result2[1]) if item in result[1]]
185
+
178
186
  border = []
179
187
  for item in start:
180
188
  for item2 in graph[item]:
@@ -185,7 +193,9 @@ def build(eq):
185
193
  continue
186
194
  if a[1] == b[1] and simplify(a[1].fx("abs") - maxnum) == 0:
187
195
  continue
196
+
188
197
  border.append(tuple(sorted([item, item2])))
198
+
189
199
  line = []
190
200
  for key in graph.keys():
191
201
  for item in list(set(point_lst)&set(graph[key])):
@@ -193,8 +203,6 @@ def build(eq):
193
203
  line = list(set(line+border))
194
204
  point_in = [deterministic_middle_point([[compute(item3) for item3 in result2[1][item2]] for item2 in item]) for item in cycles]
195
205
  def work(eq, point):
196
- if "f_eq" in str_form(eq):
197
- return False
198
206
  nonlocal result2
199
207
  if eq.name[:2] == "d_":
200
208
  return float(eq.name[2:])
@@ -204,12 +212,20 @@ def build(eq):
204
212
  return sum(work(item, point) for item in eq.children)
205
213
  if eq.name == "f_mul":
206
214
  return math.prod(work(item, point) for item in eq.children)
207
- return {"gt":lambda a,b: a>b, "lt":lambda a,b: a<b}[eq.name[2:]](work(eq.children[0], point), work(eq.children[1], point))
215
+ if eq.name == "f_sub":
216
+ return work(eq.children[0], point) - work(eq.children[1], point)
217
+ return {"eq": lambda a,b: abs(a-b)<0.001, "gt":lambda a,b: False if abs(a-b)<0.001 else a>b, "lt":lambda a,b: False if abs(a-b)<0.001 else a<b}[eq.name[2:]](work(eq.children[0], point), work(eq.children[1], point))
208
218
 
209
219
  data = []
210
220
  for index, item in enumerate(result2[2][:-4]):
211
- a = tuple(set(item) & set(point_lst))
212
- b = tuple(set([tuple(sorted([item[i], item[i+1]])) for i in range(len(item)-1)]) & set(line))
221
+ a = tuple([item for item in point_lst if work(orig.children[index], [compute(item2) for item2 in result2[1][item]])])
222
+ #a = tuple(set(item) & set(point_lst))
223
+ #b = tuple(set([tuple(sorted([item[i], item[i+1]])) for i in range(len(item)-1)]) & set(line))
224
+ b = None
225
+ if orig.children[index] == "f_eq":
226
+ b = tuple([tuple(item) for item in line if work(orig.children[index], [compute(item2) for item2 in result2[1][item[1]]]) and work(orig.children[index], [compute(item2) for item2 in result2[1][item[0]]])])
227
+ else:
228
+ b = tuple([tuple(item) for item in line if work(orig.children[index], [compute(item2) for item2 in result2[1][item[1]]]) or work(orig.children[index], [compute(item2) for item2 in result2[1][item[0]]])])
213
229
  c = tuple([tuple(item) for index2, item in enumerate(cycles) if work(orig.children[index], point_in[index2])])
214
230
  data.append((a,b,c))
215
231
 
@@ -220,16 +236,19 @@ def build(eq):
220
236
  return final, total, result2[1]
221
237
 
222
238
  def inequality_solve(eq):
239
+
240
+ eq = logic0(eq)
223
241
  element = []
224
242
  def helper(eq):
225
243
  nonlocal element
244
+
226
245
  if eq.name[2:] in "le ge lt gt eq".split(" ") and "v_" in str_form(eq):
227
246
  element.append(eq)
228
247
  return TreeNode(eq.name, [helper(child) for child in eq.children])
229
248
  helper(eq)
230
249
 
231
250
  out = build(list(set(element)))
232
-
251
+
233
252
  if out is None:
234
253
  return eq
235
254
 
@@ -284,11 +303,13 @@ def inequality_solve(eq):
284
303
  a,b,c= eq2
285
304
  d,e,f= [set(item) for item in out[1]]
286
305
  return [d-a,e-b,f-c]
306
+ return helper2(dowhile(eq, lambda x: logic0(expand(simplify(eq)))))
287
307
  out2 = helper2(eq)
288
308
 
289
309
  out = list(out)
290
310
  out[1] = [set(item) for item in out[1]]
291
-
311
+ if tuple(out[1]) == (set(), set(), set()):
312
+ return eq
292
313
  if tuple(out[1]) == tuple(out2):
293
314
  return tree_form("s_true")
294
315
  if tuple(out2) == (set(), set(), set()):
@@ -171,7 +171,8 @@ def factor_quar_formula_init():
171
171
  formula_gen9 = factor_quar_formula_init()
172
172
  def factor_helper(equation, complexnum, power=2):
173
173
  global formula_gen9
174
-
174
+ if equation.name in ["f_or", "f_and", "f_not", "f_eq", "f_gt", "f_lt", "f_ge", "f_le"]:
175
+ return TreeNode(equation.name, [factor_helper(child, complexnum, power) for child in equation.children])
175
176
  maxnum=1
176
177
  alloclst = []
177
178
  for i in range(0,26):
@@ -6,6 +6,7 @@ from .fraction import fraction
6
6
  from .expand import expand
7
7
  from .base import *
8
8
  from .factor import factorconst
9
+ from .tool import poly
9
10
  def ss(eq):
10
11
  return dowhile(eq, lambda x: fraction(expand(simplify(x))))
11
12
  def rref(matrix):
@@ -33,17 +34,16 @@ def rref(matrix):
33
34
  return matrix
34
35
  def islinear(eq, fxconst):
35
36
  eq =simplify(eq)
36
- if eq.name == "f_pow" and fxconst(eq):#"v_" in str_form(eq):
37
- return False
38
- for child in eq.children:
39
- out = islinear(child, fxconst)
40
- if not out:
41
- return out
42
- return True
37
+ if all(fxconst(tree_form(item)) and poly(eq, item) is not None and len(poly(eq, item)) <= 2 for item in vlist(eq)):
38
+ return True
39
+ return False
43
40
  def linear(eqlist, fxconst):
44
- eqlist = [eq for eq in eqlist if fxconst(eq)]
45
- if not all(islinear(eq, fxconst) for eq in eqlist):
46
- return TreeNode("f_and", copy.deepcopy(eqlist))
41
+ orig = [item.copy_tree() for item in eqlist]
42
+ #eqlist = [eq for eq in eqlist if fxconst(eq)]
43
+
44
+ if eqlist == [] or not all(islinear(eq, fxconst) for eq in eqlist):
45
+ return None
46
+ #return TreeNode("f_and", [TreeNode("f_eq", [x, tree_form("d_0")]) for x in orig])
47
47
  vl = []
48
48
  def varlist(eq, fxconst):
49
49
  nonlocal vl
@@ -111,7 +111,6 @@ def order_collinear_indices(points, idx):
111
111
  sorted_idx = sorted(idx, key=projection_factor)
112
112
  return list(sorted_idx)
113
113
  def linear_or(eq):
114
- eq = simplify(eq)
115
114
  eqlst =[]
116
115
  if eq.name != "f_or":
117
116
  eqlst = [eq]
@@ -125,8 +124,13 @@ def linear_or(eq):
125
124
  for item in itertools.combinations(enumerate(eqlst), 2):
126
125
  x, y = item[0][0], item[1][0]
127
126
  item = [item[0][1], item[1][1]]
127
+
128
128
  out = linear_solve(TreeNode("f_and", list(item)))
129
- if out.name == "f_and" and all(len(vlist(child)) == 1 for child in out.children) and set(vlist(out)) == set(v):
129
+
130
+ if out is None:
131
+ return None
132
+
133
+ if out.name == "f_and" and all(len(vlist(child)) == 1 for child in out.children) and set(vlist(out)) == set(v) and all(len(vlist(simplify(child))) >0 for child in out.children):
130
134
  t = {}
131
135
  for child in out.children:
132
136
  t[v.index(vlist(child)[0])] = simplify(inverse(child.children[0], vlist(child)[0]))
@@ -141,11 +145,13 @@ def linear_or(eq):
141
145
  line2 = []
142
146
  for key in sorted(line.keys()):
143
147
  line2.append(order_collinear_indices(p, list(set(line[key]))))
148
+
144
149
  return v, p, line2, eqlst
145
150
  def linear_solve(eq, lst=None):
146
151
  eq = simplify(eq)
147
152
  eqlist = []
148
153
  if eq.name =="f_and" and all(child.name == "f_eq" and child.children[1] == 0 for child in eq.children):
154
+
149
155
  eqlist = [child.children[0] for child in eq.children]
150
156
  else:
151
157
  return eq
@@ -154,4 +160,6 @@ def linear_solve(eq, lst=None):
154
160
  out = linear(copy.deepcopy(eqlist), lambda x: "v_" in str_form(x))
155
161
  else:
156
162
  out = linear(copy.deepcopy(eqlist), lambda x: any(contain(x, item) for item in lst))
163
+ if out is None:
164
+ return None
157
165
  return simplify(out)
@@ -0,0 +1,22 @@
1
+ def uncommute(eq, inside=False):
2
+ if not inside and eq.name in ["f_add", "f_mul"]:
3
+ return TreeNode(eq.name[:2]+"w"+eq.name[2:], [uncommute(child) for child in eq.children])
4
+ return TreeNode(eq.name, [uncommute(child, True) if eq.name == "f_list" else uncommute(child, inside) for child in eq.children])
5
+
6
+ def matrix_solve(eq):
7
+ if eq.name == "f_wadd":
8
+ output = None
9
+ output2 = []
10
+ for child in eq.children:
11
+ if child.name == "f_list":
12
+ if output is None:
13
+ output = []
14
+ for i in range(len(child.children)):
15
+ output.append([child.children[i]])
16
+ else:
17
+ for i in range(len(child.children)):
18
+ output[i] += [child.children[i]]
19
+ output.append(child)
20
+ else:
21
+ output2.append(child)
22
+ output = [summation(item) for item in output]
@@ -159,7 +159,12 @@ def clear_div(eq, denom=False):
159
159
  if len(lst3) % 2 == 1:
160
160
  sign = False
161
161
  if denom:
162
- return eq if sign else -eq, sign
162
+ eq2 = [item for item in lst if "v_" not in str_form(item)]
163
+ eq3 = [item for item in lst if "v_" in str_form(item)]
164
+ if eq3 == []:
165
+ return solve(product(eq2)),True
166
+ return solve(product(eq3)),sign
167
+ #return eq if sign else -eq, sign
163
168
  lst = [item for item in lst if not(item.name == "f_pow" and frac(item.children[1]) is not None and frac(item.children[1]) == -1)]
164
169
 
165
170
  lst2 = [item for item in lst if "v_" in str_form(item)]
@@ -361,7 +361,9 @@ def absolute(equation):
361
361
  equation = TreeNode("f_or", out2)
362
362
  return equation
363
363
  def handle_sqrt(eq):
364
+ d= []
364
365
  def helper2(eq):
366
+ nonlocal d
365
367
  if eq.name in ["f_lt", "f_gt", "f_le", "f_ge","f_eq"]:
366
368
  out = []
367
369
  def helper(eq):
@@ -378,11 +380,17 @@ def handle_sqrt(eq):
378
380
  eq2, sgn = inverse(simplify(eq.children[0]), str_form(item), True)
379
381
  if sgn == False:
380
382
  n = tree_form("d_-1")
383
+ d.append(TreeNode("f_ge", [eq2,tree_form("d_0")]))
384
+ #d.append(TreeNode("f_ge", [item.children[0],tree_form("d_0")]))
381
385
  eq3 = simplify(expand(simplify(eq2**2)))
382
386
 
383
387
  return simplify(TreeNode(eq.name, [simplify(n*item.children[0]-eq3*n), tree_form("d_0")]))
388
+
384
389
  return TreeNode(eq.name, [helper2(child) for child in eq.children])
385
- return helper2(eq)
390
+ out = helper2(eq)
391
+ if len(d) == 0:
392
+ return out
393
+ return TreeNode("f_and", [helper2(eq)]+d)
386
394
  def domain(eq):
387
395
  eq = solve(eq, True)
388
396
  out = []
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mathai
3
- Version: 0.5.0
3
+ Version: 0.5.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
@@ -14,6 +14,7 @@ mathai/inverse.py
14
14
  mathai/limit.py
15
15
  mathai/linear.py
16
16
  mathai/logic.py
17
+ mathai/matrix.py
17
18
  mathai/ode.py
18
19
  mathai/parser.py
19
20
  mathai/printeq.py
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="mathai",
5
- version="0.5.0",
5
+ version="0.5.2",
6
6
  description="Mathematics solving Ai tailored to NCERT",
7
7
  long_description=open("README.md").read(),
8
8
  long_description_content_type="text/markdown",
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