mathai 0.5.0__tar.gz → 0.5.1__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 (31) hide show
  1. {mathai-0.5.0 → mathai-0.5.1}/PKG-INFO +1 -1
  2. {mathai-0.5.0 → mathai-0.5.1}/mathai/bivariate_inequality.py +32 -11
  3. {mathai-0.5.0 → mathai-0.5.1}/mathai/linear.py +20 -12
  4. {mathai-0.5.0 → mathai-0.5.1}/mathai.egg-info/PKG-INFO +1 -1
  5. {mathai-0.5.0 → mathai-0.5.1}/setup.py +1 -1
  6. {mathai-0.5.0 → mathai-0.5.1}/README.md +0 -0
  7. {mathai-0.5.0 → mathai-0.5.1}/mathai/__init__.py +0 -0
  8. {mathai-0.5.0 → mathai-0.5.1}/mathai/apart.py +0 -0
  9. {mathai-0.5.0 → mathai-0.5.1}/mathai/base.py +0 -0
  10. {mathai-0.5.0 → mathai-0.5.1}/mathai/console.py +0 -0
  11. {mathai-0.5.0 → mathai-0.5.1}/mathai/diff.py +0 -0
  12. {mathai-0.5.0 → mathai-0.5.1}/mathai/expand.py +0 -0
  13. {mathai-0.5.0 → mathai-0.5.1}/mathai/factor.py +0 -0
  14. {mathai-0.5.0 → mathai-0.5.1}/mathai/fraction.py +0 -0
  15. {mathai-0.5.0 → mathai-0.5.1}/mathai/integrate.py +0 -0
  16. {mathai-0.5.0 → mathai-0.5.1}/mathai/inverse.py +0 -0
  17. {mathai-0.5.0 → mathai-0.5.1}/mathai/limit.py +0 -0
  18. {mathai-0.5.0 → mathai-0.5.1}/mathai/logic.py +0 -0
  19. {mathai-0.5.0 → mathai-0.5.1}/mathai/ode.py +0 -0
  20. {mathai-0.5.0 → mathai-0.5.1}/mathai/parser.py +0 -0
  21. {mathai-0.5.0 → mathai-0.5.1}/mathai/printeq.py +0 -0
  22. {mathai-0.5.0 → mathai-0.5.1}/mathai/simplify.py +0 -0
  23. {mathai-0.5.0 → mathai-0.5.1}/mathai/structure.py +0 -0
  24. {mathai-0.5.0 → mathai-0.5.1}/mathai/tool.py +0 -0
  25. {mathai-0.5.0 → mathai-0.5.1}/mathai/trig.py +0 -0
  26. {mathai-0.5.0 → mathai-0.5.1}/mathai/univariate_inequality.py +0 -0
  27. {mathai-0.5.0 → mathai-0.5.1}/mathai.egg-info/SOURCES.txt +0 -0
  28. {mathai-0.5.0 → mathai-0.5.1}/mathai.egg-info/dependency_links.txt +0 -0
  29. {mathai-0.5.0 → mathai-0.5.1}/mathai.egg-info/requires.txt +0 -0
  30. {mathai-0.5.0 → mathai-0.5.1}/mathai.egg-info/top_level.txt +0 -0
  31. {mathai-0.5.0 → mathai-0.5.1}/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.1
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
@@ -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()):
@@ -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)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mathai
3
- Version: 0.5.0
3
+ Version: 0.5.1
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
@@ -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.1",
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
File without changes
File without changes
File without changes