mathai 0.2.2__tar.gz → 0.2.4__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 (29) hide show
  1. {mathai-0.2.2 → mathai-0.2.4}/PKG-INFO +1 -1
  2. {mathai-0.2.2 → mathai-0.2.4}/mathai/__init__.py +2 -1
  3. {mathai-0.2.2 → mathai-0.2.4}/mathai/base.py +2 -1
  4. {mathai-0.2.2 → mathai-0.2.4}/mathai/expand.py +2 -0
  5. {mathai-0.2.2 → mathai-0.2.4}/mathai/inverse.py +11 -3
  6. {mathai-0.2.2 → mathai-0.2.4}/mathai/limit.py +12 -8
  7. {mathai-0.2.2 → mathai-0.2.4}/mathai/simplify.py +24 -9
  8. mathai-0.2.4/mathai/univariate_inequality.py +411 -0
  9. {mathai-0.2.2 → mathai-0.2.4}/mathai.egg-info/PKG-INFO +1 -1
  10. {mathai-0.2.2 → mathai-0.2.4}/mathai.egg-info/SOURCES.txt +1 -0
  11. {mathai-0.2.2 → mathai-0.2.4}/setup.py +1 -1
  12. {mathai-0.2.2 → mathai-0.2.4}/README.md +0 -0
  13. {mathai-0.2.2 → mathai-0.2.4}/mathai/apart.py +0 -0
  14. {mathai-0.2.2 → mathai-0.2.4}/mathai/console.py +0 -0
  15. {mathai-0.2.2 → mathai-0.2.4}/mathai/diff.py +0 -0
  16. {mathai-0.2.2 → mathai-0.2.4}/mathai/factor.py +0 -0
  17. {mathai-0.2.2 → mathai-0.2.4}/mathai/fraction.py +0 -0
  18. {mathai-0.2.2 → mathai-0.2.4}/mathai/integrate.py +0 -0
  19. {mathai-0.2.2 → mathai-0.2.4}/mathai/linear.py +0 -0
  20. {mathai-0.2.2 → mathai-0.2.4}/mathai/logic.py +0 -0
  21. {mathai-0.2.2 → mathai-0.2.4}/mathai/parser.py +0 -0
  22. {mathai-0.2.2 → mathai-0.2.4}/mathai/printeq.py +0 -0
  23. {mathai-0.2.2 → mathai-0.2.4}/mathai/structure.py +0 -0
  24. {mathai-0.2.2 → mathai-0.2.4}/mathai/tool.py +0 -0
  25. {mathai-0.2.2 → mathai-0.2.4}/mathai/trig.py +0 -0
  26. {mathai-0.2.2 → mathai-0.2.4}/mathai.egg-info/dependency_links.txt +0 -0
  27. {mathai-0.2.2 → mathai-0.2.4}/mathai.egg-info/requires.txt +0 -0
  28. {mathai-0.2.2 → mathai-0.2.4}/mathai.egg-info/top_level.txt +0 -0
  29. {mathai-0.2.2 → mathai-0.2.4}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: mathai
3
- Version: 0.2.2
3
+ Version: 0.2.4
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,7 +1,7 @@
1
1
  from .expand import expand
2
2
  from .parser import parse
3
3
  from .printeq import printeq, printeq_log, printeq_str
4
- from .simplify import solve, simplify
4
+ from .simplify import solve, simplify, solve2
5
5
  from .integrate import integrate, sqint, byparts
6
6
  from .diff import diff
7
7
  from .factor import factor, factor2
@@ -12,4 +12,5 @@ from .logic import logic0, logic1, logic2, logic3
12
12
  from .apart import apart
13
13
  from .console import console
14
14
  from .limit import limit
15
+ from .univariate_inequality import wavycurvy, absolute, domain, handle_sqrt
15
16
  from .base import *
@@ -193,7 +193,8 @@ def compute(eq):
193
193
 
194
194
  # Recursive case: compute child values
195
195
  values = [compute(child) for child in eq.children]
196
-
196
+ if None in values:
197
+ return None
197
198
  # Evaluate based on node type
198
199
  if eq.name == "f_add":
199
200
  return sum(values)
@@ -52,5 +52,7 @@ def expand(eq):
52
52
  add = add + mul
53
53
  add = simplify(add)
54
54
  eq = add
55
+ eq = simplify(eq)
56
+
55
57
  return TreeNode(eq.name, [expand(child) for child in eq.children])
56
58
 
@@ -1,10 +1,11 @@
1
1
  from .base import *
2
2
  from .simplify import solve
3
3
  from .expand import expand
4
- def inverse(rhs,term):
4
+ def inverse(rhs,term, sign=None):
5
5
  term = tree_form(term)
6
6
  lhs = tree_form("d_0")
7
7
  count = 15
8
+
8
9
  while not rhs==term:
9
10
  if rhs.name == "f_add":
10
11
  if all(term in factor_generation(child) for child in rhs.children):
@@ -20,6 +21,12 @@ def inverse(rhs,term):
20
21
  for i in range(len(rhs.children)-1,-1,-1):
21
22
  if not contain(rhs.children[i], term):
22
23
  lhs = lhs * rhs.children[i]**-1
24
+ if sign is not None:
25
+ if "v_" in str_form(rhs.children[i]):
26
+ return None
27
+ if compute(rhs.children[i]**-1) < 0:
28
+ sign = not sign
29
+
23
30
  rhs.children.pop(i)
24
31
  elif rhs.name == "f_pow" and contain(rhs.children[0], term):
25
32
  lhs = lhs ** (tree_form("d_1")/rhs.children[1])
@@ -53,5 +60,6 @@ def inverse(rhs,term):
53
60
  count -= 1
54
61
  if count == 0:
55
62
  return None
56
-
57
- return solve(lhs)
63
+ if sign is None:
64
+ return solve(lhs)
65
+ return solve(lhs), sign
@@ -23,19 +23,22 @@ def subslimit(equation, var):
23
23
  def check(num, den, var):
24
24
  n, d = None, None
25
25
 
26
- n, d = (dowhile(replace(e, var, tree_form("d_0")), lambda x: trig0(simplify(x))) for e in (num, den))
26
+ n, d = (dowhile(replace(e, tree_form(var), tree_form("d_0")), lambda x: trig0(simplify(x))) for e in (num, den))
27
+
27
28
  if n is None or d is None:
28
29
  return False
29
30
  if n == 0 and d == 0: return True
30
- if d != 0: return simplify(num/den)
31
+ if d != 0:
32
+ return simplify(n/d)
31
33
  return False
32
34
  def lhospital(num, den, steps,var):
33
35
  logs = []
36
+
34
37
  out = check(num, den, var)
35
38
  if isinstance(out, TreeNode):
36
39
  return out,[]
37
40
  for _ in range(steps):
38
- num2, den2 = map(lambda e: simplify(diff(e, var.name)), (num, den))
41
+ num2, den2 = map(lambda e: simplify(diff(e, var)), (num, den))
39
42
  out = check(num2, den2, var)
40
43
  if out is True:
41
44
  num, den = num2, den2
@@ -49,7 +52,7 @@ def lhospital2(eq, var):
49
52
  eq= simplify(eq)
50
53
  if eq is None:
51
54
  return None
52
- if not contain(eq, var):
55
+ if not contain(eq, tree_form(var)):
53
56
  return eq,[]
54
57
  num, dem = [simplify(item) for item in num_dem(eq)]
55
58
  if num is None or dem is None:
@@ -110,14 +113,15 @@ def approx(eq, var):
110
113
  def approx_limit(equation, var):
111
114
  return dowhile(equation, lambda x: approx(x, var))
112
115
 
113
- def limit(equation, var=tree_form("v_0")):
116
+ def limit(equation, var="v_0"):
114
117
  logs = [(0,"lim x->0 "+printeq_str(simplify(equation)))]
115
- eq2 = dowhile(replace(equation, var, tree_form("d_0")), lambda x: trig0(simplify(x)))
116
- if eq2 is not None and not contain(equation, var):
118
+ eq2 = dowhile(replace(equation, tree_form(var), tree_form("d_0")), lambda x: trig0(simplify(x)))
119
+ if eq2 is not None and not contain(equation, tree_form(var)):
117
120
  return eq2,logs
121
+
118
122
  equation, tmp = lhospital2(equation, var)
119
123
  equation = simplify(expand(simplify(equation)))
120
- if not contain(equation, var):
124
+ if not contain(equation, tree_form(var)):
121
125
  return equation,logs+tmp
122
126
  '''
123
127
  if equation.name == "f_add":
@@ -144,25 +144,36 @@ def solve(eq, specialfx=False):
144
144
  eq = flatten_tree(eq)
145
145
 
146
146
  return dowhile(eq, _solve)
147
-
147
+ def solve2(eq):
148
+ return solve(eq, True)
148
149
  def clear_div(eq):
149
150
  lst = factor_generation(eq)
150
151
  if tree_form("d_0") in lst:
151
152
  return tree_form("d_0")
152
- 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]) < 0)]
153
+ lst3 = [item for item in lst if "v_" not in str_form(item) and compute(item) < 0]
154
+ sign = True
155
+ if len(lst3) % 2 == 1:
156
+ sign = False
157
+ 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)]
153
158
 
154
159
  lst2 = [item for item in lst if "v_" in str_form(item)]
155
160
  if lst2 == []:
156
- return solve(product(lst))
157
- return solve(product(lst2))
161
+ return solve(product(lst)),sign
162
+ return solve(product(lst2)),sign
158
163
 
159
164
  def simplify(eq):
160
165
  error = False
161
- if eq.name == "f_eq":
162
- if eq.children[1] != 0:
163
- return TreeNode(eq.name, [clear_div(simplify(eq.children[0]-eq.children[1])), tree_form("d_0")])
164
- else:
165
- return TreeNode(eq.name, [clear_div(simplify(eq.children[0])), tree_form("d_0")])
166
+ eq = flatten_tree(eq)
167
+ if eq.name in ["f_and", "f_or", "f_not"]:
168
+ return TreeNode(eq.name, [simplify(child) for child in eq.children])
169
+
170
+ if eq.name in ["f_lt", "f_gt", "f_le", "f_ge", "f_eq"]:
171
+ tmp, sign = clear_div(simplify(eq.children[0]-eq.children[1]))
172
+ name2 = eq.name
173
+ if not sign:
174
+ name2 = {"f_lt":"f_gt", "f_gt":"f_lt", "f_eq":"f_eq", "f_le":"f_ge", "f_ge":"f_le"}[name2]
175
+
176
+ return TreeNode(name2, [tmp, tree_form("d_0")])
166
177
 
167
178
  eq = solve(eq, True)
168
179
  def helper(eq):
@@ -219,6 +230,8 @@ def simplify(eq):
219
230
  return TreeNode(eq.name, [helper3(child) for child in eq.children])
220
231
  def helper4(eq):
221
232
  nonlocal error
233
+ if eq == tree_form("d_-1")**tree_form("d_-1"):
234
+ return tree_form("d_-1")
222
235
  def perfect_nth_root_value(x, n):
223
236
  """Return integer y if x is a perfect n-th power (y**n == x), else None."""
224
237
  if x < 0 and n % 2 == 0:
@@ -316,6 +329,8 @@ def simplify(eq):
316
329
  return eq.children[0].children[0]**eq.children[1]
317
330
  return TreeNode(eq.name, [helper5(child) for child in eq.children])
318
331
  def helper8(eq):
332
+ if eq.name == "f_pow" and eq.children[0].name == "f_abs" and frac(eq.children[1]) is not None and frac(eq.children[1]).numerator % 2==0:
333
+ return eq.children[0].children[0] ** eq.children[1]
319
334
  if eq.name == "f_abs" and eq.children[0].name == "f_abs":
320
335
  return eq.children[0]
321
336
  if eq.name == "f_cos" and eq.children[0].name == "f_abs":
@@ -0,0 +1,411 @@
1
+ import itertools
2
+
3
+ from .base import *
4
+ from .inverse import inverse
5
+ from collections import Counter
6
+ from .factor import factor2
7
+ from .simplify import simplify, solve
8
+ from .expand import expand
9
+ from .fraction import fraction
10
+ import copy
11
+ from .diff import diff
12
+ from .logic import logic0
13
+ def intersection2(domain, lst):
14
+ domain = copy.deepcopy(domain)
15
+ if domain == [True]:
16
+ return lst
17
+ elif domain == [True]:
18
+ return []
19
+ lst = [item for item in lst if item not in domain]
20
+ out = []
21
+ for item2 in lst:
22
+ for index in range(len(domain)):
23
+
24
+ if isinstance(domain[index], bool) and domain[index]:
25
+
26
+ if index == 0 and compute(item2) < compute(domain[index+1]):
27
+
28
+ out.append(item2)
29
+ break
30
+ elif index == len(domain)-1 and compute(domain[index-1]) < compute(item2):
31
+ out.append(item2)
32
+ break
33
+ elif index != 0 and index != len(domain)-1 and compute(domain[index-1]) < compute(item2) and compute(item2) < compute(domain[index+1]):
34
+
35
+ out.append(item2)
36
+ break
37
+
38
+ return list(set(out))
39
+ def flip_less_than(inter):
40
+ inter = copy.deepcopy(inter)
41
+ return [not item if isinstance(item, bool) else item for item in inter]
42
+ def intersection(domain_1, domain_2):
43
+ domain_1, domain_2 = copy.deepcopy(domain_1), copy.deepcopy(domain_2)
44
+ if domain_1 == [True]:
45
+ return domain_2
46
+ if domain_2 == [True]:
47
+ return domain_1
48
+ if domain_1 == [False] or domain_2 == [False]:
49
+ return [False]
50
+ def simplify_ranges(ranges):
51
+ simplified_ranges = []
52
+ i = 0
53
+ while i < len(ranges):
54
+ if i + 2 < len(ranges) and ranges[i] is True and ranges[i + 2] is True:
55
+ simplified_ranges.append(True)
56
+ i += 3
57
+ elif i + 2 < len(ranges) and ranges[i] is False and ranges[i + 2] is False:
58
+ simplified_ranges.append(False)
59
+ i += 3
60
+ else:
61
+ simplified_ranges.append(ranges[i])
62
+ i += 1
63
+ return simplified_ranges
64
+ result = domain_1 + domain_2
65
+ result = [item for item in result if not isinstance(item, bool)]
66
+ result = list(set(result))
67
+ result = sorted(result, key=lambda x: compute(x))
68
+ i = len(result)
69
+ while i>=0:
70
+ result.insert(i, True)
71
+ i = i - 1
72
+ result[0] = domain_1[0] and domain_2[0]
73
+ result[-1] = domain_1[-1] and domain_2[-1]
74
+ def find_fraction_in_list(fraction_list, target_fraction):
75
+ for i in range(1, len(fraction_list)-1, 2):
76
+ if fraction_list[i] == target_fraction:
77
+ return i
78
+ return -1
79
+ for i in range(2, len(result)-1, 2):
80
+ if result[i+1] in domain_1:
81
+ result[i] = result[i] and domain_1[find_fraction_in_list(domain_1, result[i+1])-1]
82
+ if result[i+1] in domain_2:
83
+ result[i] = result[i] and domain_2[find_fraction_in_list(domain_2, result[i+1])-1]
84
+ if result[i-1] in domain_1:
85
+ result[i] = result[i] and domain_1[find_fraction_in_list(domain_1, result[i-1])+1]
86
+ if result[i-1] in domain_2:
87
+ result[i] = result[i] and domain_2[find_fraction_in_list(domain_2, result[i-1])+1]
88
+
89
+ result = simplify_ranges(result)
90
+ return result
91
+ class Range:
92
+ def __init__(self, r=[True], p=[], z=[]):
93
+ self.r = r
94
+ self.p = p
95
+ self.z = z
96
+ self.do = True
97
+
98
+ def unfix(self):
99
+ self.do = False
100
+ return self
101
+ def fix(self):
102
+ if not self.do:
103
+ return
104
+ def simplify_ranges(ranges):
105
+ simplified_ranges = []
106
+ i = 0
107
+ while i < len(ranges):
108
+ if i + 2 < len(ranges) and ranges[i] is True and ranges[i + 2] is True:
109
+ simplified_ranges.append(True)
110
+ i += 3
111
+ elif i + 2 < len(ranges) and ranges[i] is False and ranges[i + 2] is False:
112
+ simplified_ranges.append(False)
113
+ i += 3
114
+ else:
115
+ simplified_ranges.append(ranges[i])
116
+ i += 1
117
+ return simplified_ranges
118
+
119
+ self.r = simplify_ranges(self.r)
120
+
121
+ common = set(self.p) & set(self.z)
122
+ self.z = list(set(self.z) - common)
123
+ self.p = list(set(self.p) - common)
124
+
125
+ self.p = list(set(self.p) - set(intersection2(self.r, self.p)))
126
+ self.z = list(set(intersection2(self.r, self.z)))
127
+ return self
128
+
129
+ def __or__(self, other):
130
+ return (self.unfix().__invert__().unfix() & other.unfix().__invert__().unfix()).unfix().__invert__().fix()
131
+ def __invert__(self):
132
+ tmp = Range(flip_less_than(self.r), self.z, list(set(self.p)-set(self.z)))
133
+
134
+ return tmp
135
+ def __and__(self, other):
136
+ a = intersection(self.r, other.r)
137
+ b = intersection2(self.r, other.p)
138
+ c = intersection2(other.r, self.p)
139
+ tmp = Range(a, list(set(b)|set(c)|(set(self.p)&set(other.p))), list(set(self.z)|set(other.z)))
140
+ return tmp
141
+ def __str__(self):
142
+
143
+ if self.r == [False] and self.p == [] and self.z == []:
144
+ return "{}"
145
+ out = []
146
+ out2 = ""
147
+ if self.r != [False]:
148
+ for i in range(0, len(self.r), 2):
149
+ string = ""
150
+ if self.r[i]:
151
+ if i == 0:
152
+ string += "(-inf,"
153
+ if len(self.r)==1:
154
+ string += "+inf)"
155
+ else:
156
+ string += str(self.r[i+1])+")"
157
+ elif i == len(self.r)-1 and len(self.r)!=1:
158
+ string += "("+str(self.r[i-1])+",+inf)"
159
+ else:
160
+ string += "("+str(self.r[i-1])+","+str(self.r[i+1])+")"
161
+ out.append(string)
162
+ if self.p != []:
163
+ out.append("{"+",".join([str(item) for item in self.p])+"}")
164
+ if self.z != []:
165
+ out2 = "{"+",".join([str(item) for item in self.z])+"}"
166
+ if out2 == "":
167
+ return "U".join(out)
168
+ else:
169
+ return "U".join(out)+"-"+out2
170
+
171
+ dic_table = {}
172
+ def helper(eq, var="v_0"):
173
+ global dic_table
174
+
175
+ eq2 = copy.deepcopy(eq)
176
+
177
+ if eq2 in dic_table.keys():
178
+ return dic_table[eq2]
179
+
180
+ if eq.children[0].name == "f_add":
181
+
182
+ eq.children[0] = simplify(expand(eq.children[0]))
183
+ eq = simplify(factor2(eq))
184
+
185
+
186
+ equ = False
187
+ sign= True
188
+ if eq.name in ["f_gt", "f_ge"]:
189
+ sign = True
190
+ elif eq.name in ["f_lt", "f_le"]:
191
+ sign = False
192
+ if eq.name in ["f_ge", "f_le"]:
193
+ equ = True
194
+ if eq.name == "f_eq":
195
+ equ= True
196
+ critical = []
197
+ equal = []
198
+ more = []
199
+
200
+ _, d = num_dem(eq.children[0])
201
+ d = factor2(d)
202
+
203
+ for item in factor_generation(d):
204
+
205
+ item = simplify(expand(item))
206
+ if len(vlist(item)) != 0:
207
+ v = vlist(item)[0]
208
+ if diff(diff(item, v), v) != tree_form("d_0"):
209
+ continue
210
+ out = inverse(item, vlist(item)[0])
211
+ more.append(simplify(out))
212
+
213
+ eq.children[0] = factor2(eq.children[0])
214
+
215
+
216
+ for item in factor_generation(eq.children[0]):
217
+ item = simplify(expand(item))
218
+
219
+ if len(vlist(item)) == 0:
220
+ if compute(item) <0:
221
+ sign = not sign
222
+ continue
223
+ v = vlist(item)[0]
224
+
225
+ if item.name == "f_pow" and item.children[1].name== "d_-1":
226
+
227
+ item = item.children[0]
228
+
229
+ tmp2 = diff(copy.deepcopy(item))
230
+ if "v_" in str_form(tmp2):
231
+ return None
232
+
233
+
234
+ if diff(diff(item, v), v) != tree_form("d_0"):
235
+
236
+ a = replace(diff(diff(item, v), v), tree_form(v), tree_form("d_0"))/tree_form("d_2")
237
+ if compute(a) < 0:
238
+ sign = not sign
239
+ continue
240
+
241
+
242
+ if compute(tmp2)<0:
243
+ sign = not sign
244
+ item = simplify(item * tree_form("d_-1"))
245
+ out = inverse(item, vlist(item)[0])
246
+ critical.append(out)
247
+ else:
248
+ tmp2 = diff(copy.deepcopy(item))
249
+ if "v_" in str_form(tmp2):
250
+ return None
251
+
252
+ if diff(diff(item, v), v) != tree_form("d_0"):
253
+ a = replace(diff(diff(item, v), v), tree_form(v), tree_form("d_0"))/tree_form("d_2")
254
+ if compute(a) < 0:
255
+ sign = not sign
256
+ continue
257
+
258
+
259
+ if compute(tmp2)<0:
260
+ sign = not sign
261
+ item = simplify(item * tree_form("d_-1"))
262
+ out = inverse(item, vlist(item)[0])
263
+ critical.append(out)
264
+ if equ:
265
+ equal.append(str_form(out))
266
+ equal = list(set([simplify(tree_form(item)) for item in equal]))
267
+ more = list(set([simplify(tree_form(item)) for item in more]))
268
+ critical = [simplify(item) for item in critical]
269
+ critical = Counter(critical)
270
+
271
+ critical = sorted(critical.items(), key=lambda x: compute(x[0]))
272
+
273
+ i = len(critical)
274
+ element = sign
275
+ while i>=0:
276
+ critical.insert(i, element)
277
+ if i>0 and critical[i-1][1] % 2 != 0:
278
+ element = not element
279
+ i = i - 1
280
+ for i in range(1, len(critical), 2):
281
+ critical[i] = critical[i][0]
282
+
283
+
284
+
285
+ if eq.name == "f_eq":
286
+ final = Range([False], equal, more)
287
+ dic_table[eq2] = final
288
+ return final
289
+
290
+ final = Range(critical, equal, more)
291
+ dic_table[eq2] = final
292
+ return final
293
+ def wavycurvy(eq):
294
+ if eq.name == "s_true":
295
+ return Range([True])
296
+ if eq.name == "s_false":
297
+ return Range([False])
298
+ if eq.name not in ["f_and", "f_or", "f_not"]:
299
+
300
+ out = helper(eq)
301
+ if out is None:
302
+ return None
303
+ return out
304
+ lst= [wavycurvy(child) for child in eq.children]
305
+ if None in lst:
306
+ return None
307
+ ra = lst[0]
308
+ if eq.name == "f_and":
309
+ for child in lst[1:]:
310
+ ra = ra & child
311
+ elif eq.name == "f_or":
312
+ for child in lst[1:]:
313
+ ra = ra | child
314
+ elif eq.name == "f_not":
315
+ ra = ~ra
316
+ return ra
317
+
318
+ def absolute(equation):
319
+ if equation.name in ["f_and", "f_or", "f_not"]:
320
+ tmp = TreeNode(equation.name, [absolute(child) for child in equation.children])
321
+ if len(tmp.children)==1:
322
+ tmp =tmp.children[0]
323
+ return tmp
324
+ def mul_abs(eq):
325
+ if eq.name == "f_abs" and eq.children[0].name == "f_mul":
326
+ return simplify(product([item.fx("abs") for item in factor_generation(eq.children[0])]))
327
+ return TreeNode(eq.name, [mul_abs(child) for child in eq.children])
328
+ equation = mul_abs(equation)
329
+
330
+ def collectabs(eq):
331
+ out = []
332
+ if eq.name == "f_abs":
333
+ out.append(eq.children[0])
334
+ return out
335
+ for child in eq.children:
336
+ out += collectabs(child)
337
+ return out
338
+ def abc(eq, arr):
339
+ def trans(eq):
340
+ nonlocal arr
341
+ out = {}
342
+ if eq.name == "f_abs":
343
+ x = arr.pop(0)
344
+ if x == 0 or x==2:
345
+ return eq.children[0]
346
+ else:
347
+ return -eq.children[0]
348
+ else:
349
+ return TreeNode(eq.name, [trans(child) for child in eq.children])
350
+ return trans(eq)
351
+ out = list(set(collectabs(equation)))
352
+
353
+ out2 = []
354
+ for item in itertools.product([0,1,2], repeat=len(out)):
355
+ out3 = []
356
+ for i in range(len(item)):
357
+ out3.append(copy.deepcopy(TreeNode({0:"f_gt", 1:"f_lt", 2:"f_eq"}[item[i]], [out[i], tree_form("d_0")])))
358
+ out3 = TreeNode("f_and", out3+[abc(copy.deepcopy(equation), list(item))])
359
+ if len(out3.children) == 1:
360
+ out3 = out3.children[0]
361
+ out2.append(out3)
362
+ if len(out2) == 1:
363
+ return out2[0]
364
+ else:
365
+ equation = TreeNode("f_or", out2)
366
+ return equation
367
+ def handle_sqrt(eq):
368
+ eq = domain(eq)
369
+ def helper2(eq):
370
+ if eq.name in ["f_lt", "f_gt", "f_le", "f_ge"]:
371
+ out = []
372
+ def helper(eq):
373
+ nonlocal out
374
+ if eq.name == "f_pow" and frac(eq.children[1]) == Fraction(1,2):
375
+ out.append(simplify(eq))
376
+ x = [helper(child) for child in eq.children]
377
+ helper(eq)
378
+ for item in out:
379
+
380
+ eq2, sgn = inverse(simplify(eq.children[0]), str_form(item), True)
381
+ n = tree_form("d_1")
382
+ if sgn == False:
383
+ n = tree_form("d_-1")
384
+ eq3 = simplify(expand(simplify(eq2**2)))
385
+ eq2 = simplify(eq2)
386
+ if "v_" in str_form(eq3) and not (eq2.name == "f_pow" and frac(eq2.children[1]) == Fraction(1,2)):
387
+ return simplify(TreeNode(eq.name, [simplify(n*item.children[0]-eq3*n), tree_form("d_0")])) & TreeNode("f_ge", [eq2, tree_form("d_0")])
388
+ return simplify(TreeNode(eq.name, [simplify(n*item.children[0]-eq3*n), tree_form("d_0")]))
389
+ return TreeNode(eq.name, [helper2(child) for child in eq.children])
390
+ return helper2(eq)
391
+ def domain(eq):
392
+ eq = solve(eq, True)
393
+ out = []
394
+ def helper2(eq):
395
+ nonlocal out
396
+ if eq.name == "f_pow" and frac(eq.children[1]) is not None and frac(eq.children[1]).denominator == 2:
397
+ out.append(TreeNode("f_ge", [eq.children[0], tree_form("d_0")]))
398
+ if eq.name == "f_pow" and frac(eq.children[1]) is not None and frac(eq.children[1]) <0:
399
+ out.append(TreeNode("f_eq", [eq.children[0], tree_form("d_0")]).fx("not"))
400
+ x = [helper2(child) for child in eq.children]
401
+ helper2(eq)
402
+ out = list(set([simplify(item) for item in out]))
403
+ if out == []:
404
+ return eq
405
+ if len(out)==1:
406
+ out = out[0]
407
+ else:
408
+ out = TreeNode("f_and", list(out))
409
+ if eq.name in ["f_lt", "f_gt", "f_le", "f_ge", "f_eq"]:
410
+ return eq & out
411
+ return out
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: mathai
3
- Version: 0.2.2
3
+ Version: 0.2.4
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
@@ -19,6 +19,7 @@ mathai/simplify.py
19
19
  mathai/structure.py
20
20
  mathai/tool.py
21
21
  mathai/trig.py
22
+ mathai/univariate_inequality.py
22
23
  mathai.egg-info/PKG-INFO
23
24
  mathai.egg-info/SOURCES.txt
24
25
  mathai.egg-info/dependency_links.txt
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="mathai",
5
- version="0.2.2",
5
+ version="0.2.4",
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