mathai 0.8.1__py3-none-any.whl → 0.8.2__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
@@ -35,7 +35,8 @@ from .inverse import inverse
35
35
 
36
36
  from .trig import trig0, trig1, trig2, trig3, trig4
37
37
 
38
- from .logic import logic0, logic1, logic2, logic3, logic_n
38
+ from .logic import logic0, logic1, logic2, logic3, logic_n, set_sub
39
+ from .logic import auto_apply as logic_x
39
40
 
40
41
  from .apart import apart, apart2
41
42
 
mathai/base.py CHANGED
@@ -1,3 +1,4 @@
1
+ import time
1
2
  import copy
2
3
  from fractions import Fraction
3
4
  def use(eq):
@@ -352,6 +353,8 @@ def flatten_tree(node):
352
353
  merged_children = []
353
354
  for child in node.children:
354
355
  flattened_child = flatten_tree(child)
356
+ if flattened_child is None:
357
+ return None
355
358
  if flattened_child.name == node.name:
356
359
  merged_children.extend(flattened_child.children)
357
360
  else:
@@ -360,7 +363,7 @@ def flatten_tree(node):
360
363
  else:
361
364
  node.children = [flatten_tree(child) for child in node.children]
362
365
  return node
363
- def dowhile(eq, fx):
366
+ def dowhile(eq, fx, start_time=None, budget=None):
364
367
  if eq is None:
365
368
  return None
366
369
  while True:
@@ -368,6 +371,10 @@ def dowhile(eq, fx):
368
371
  eq2 = fx(eq)
369
372
  if eq2 is None:
370
373
  return None
374
+ if start_time is not None:
375
+ if -start_time + time.monotonic() > budget:
376
+ print("timeout")
377
+ return None
371
378
  eq = copy.deepcopy(eq2)
372
379
  if eq == orig:
373
380
  return orig
mathai/logic.py CHANGED
@@ -1,3 +1,4 @@
1
+ import time
1
2
  import itertools
2
3
  from .base import *
3
4
  def c(eq):
@@ -5,6 +6,35 @@ def c(eq):
5
6
  eq = dowhile(eq, logic0)
6
7
  eq = dowhile(eq, logic2)
7
8
  return eq
9
+ def set_sub(eq):
10
+ if eq.name == "f_sub":
11
+ return eq.children[0] & eq.children[1].fx("not")
12
+ return TreeNode(eq.name, [set_sub(child) for child in eq.children])
13
+
14
+ start_time = None
15
+ budget = 2.0
16
+ def auto_apply(eq):
17
+ global start_time
18
+ fs = [logic1, logic2]
19
+ results = []
20
+ pair = 0
21
+ for g in fs:
22
+ for f in fs:
23
+ start_time = time.monotonic()
24
+ r = dowhile(g(f(eq)), logic0)
25
+ if r is None:
26
+ continue
27
+ if r != eq:
28
+ results.append(r)
29
+ start_time = None
30
+ pair += 1
31
+ #print(f"pair {pair}")
32
+ if not results:
33
+ return eq
34
+
35
+ return min(results, key=lambda x: len(str(x)))
36
+
37
+
8
38
  def logic_n(eq):
9
39
  return dowhile(eq, c)
10
40
  def logic0(eq):
@@ -40,6 +70,13 @@ def logic3(eq):
40
70
  return TreeNode("f_forall", [eq.children[0], eq.children[1].fx("not")]).fx("not")
41
71
  return TreeNode(eq.name, [logic3(child) for child in eq.children])
42
72
  def logic2(eq):
73
+ if eq is None:
74
+ return None
75
+ global start_time, budget
76
+ if start_time is not None:
77
+ if -start_time + time.monotonic() > budget:
78
+ #print("timeout")
79
+ return None
43
80
  if eq.name in ["f_exist", "f_forall"]:
44
81
  return TreeNode(eq.name, [eq.children[0], logic2(eq.children[1])])
45
82
  if eq.name not in ["f_and", "f_or", "f_not", "f_imply", "f_equiv"]:
@@ -111,6 +148,10 @@ def logic2(eq):
111
148
 
112
149
  if eq.name in ["f_and", "f_or"] and any(child.children is not None and len(child.children)!=0 for child in eq.children):
113
150
  for i in range(len(eq.children),1,-1):
151
+ if start_time is not None:
152
+ if time.monotonic() - start_time > budget:
153
+
154
+ return None
114
155
  for item in itertools.combinations(enumerate(eq.children), i):
115
156
  op = "f_and"
116
157
  if eq.name == "f_and":
@@ -148,7 +189,20 @@ def logic2(eq):
148
189
  return output
149
190
  return TreeNode(eq.name, [flatten_tree(logic2(child)) for child in eq.children])
150
191
  def logic1(eq):
192
+ if eq is None:
193
+ return None
194
+ global start_time, budget
195
+ if start_time is not None:
196
+ if time.monotonic() - start_time > budget:
197
+ #print("timeout")
198
+ return None
199
+ else:
200
+ pass
151
201
  def helper(eq):
202
+ if start_time is not None:
203
+ if -start_time + time.monotonic() > budget:
204
+ #print("timeout")
205
+ return None
152
206
  if eq.name in ["f_exist", "f_forall"]:
153
207
  return TreeNode(eq.name, [eq.children[0], logic1(eq.children[1])])
154
208
  if eq.name not in ["f_and", "f_or", "f_not", "f_imply", "f_equiv"]:
@@ -156,13 +210,17 @@ def logic1(eq):
156
210
  if eq.name == "f_equiv":
157
211
  A, B = eq.children
158
212
  A, B = logic1(A), logic1(B)
159
- A, B = dowhile(A, logic2), dowhile(B, logic2)
213
+ A, B = dowhile(A, logic2, start_time, budget), dowhile(B, logic2, start_time, budget)
214
+ if A is None or B is None:
215
+ return None
160
216
  return flatten_tree((A & B) | (A.fx("not") & B.fx("not")))
161
217
  if eq.name == "f_imply":
162
218
 
163
219
  A, B = eq.children
164
220
  A, B = logic1(A), logic1(B)
165
- A, B = dowhile(A, logic2), dowhile(B, logic2)
221
+ A, B = dowhile(A, logic2, start_time, budget), dowhile(B, logic2, start_time, budget)
222
+ if A is None or B is None:
223
+ return None
166
224
  return flatten_tree(A.fx("not") | B)
167
225
  return TreeNode(eq.name, [helper(child) for child in eq.children])
168
226
  if eq.name in ["f_exist", "f_forall"]:
@@ -171,30 +229,27 @@ def logic1(eq):
171
229
  return eq
172
230
  eq = helper(eq)
173
231
  eq = flatten_tree(eq)
174
-
175
232
  if len(eq.children) > 2:
176
233
  lst = []
177
234
  l = len(eq.children)
178
-
179
235
  if l % 2 == 1:
180
236
  last_child = eq.children[-1]
181
237
 
182
238
  if isinstance(last_child, TreeNode):
183
- last_child = dowhile(last_child, logic2)
239
+ last_child = dowhile(last_child, logic2, start_time, budget)
184
240
  lst.append(last_child)
185
241
  l -= 1
186
242
 
187
243
  for i in range(0, l, 2):
188
244
  left, right = eq.children[i], eq.children[i+1]
189
245
  pair = TreeNode(eq.name, [left, right])
190
- simplified = dowhile(logic1(pair), logic2)
246
+ simplified = dowhile(logic1(pair), logic2, start_time, budget)
191
247
  lst.append(simplified)
192
248
 
193
249
  if len(lst) == 1:
194
250
  return flatten_tree(lst[0])
195
251
 
196
252
  return flatten_tree(TreeNode(eq.name, lst))
197
-
198
253
  if eq.name == "f_and":
199
254
  lst= []
200
255
  for child in eq.children:
@@ -224,4 +279,3 @@ def logic1(eq):
224
279
  out = out.children[0]
225
280
  return flatten_tree(out)
226
281
  return TreeNode(eq.name, [logic1(child) for child in eq.children])
227
-
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mathai
3
- Version: 0.8.1
3
+ Version: 0.8.2
4
4
  Summary: Mathematics solving Ai tailored to NCERT
5
5
  Home-page: https://github.com/infinity390/mathai4
6
6
  Requires-Python: >=3.7
@@ -1,6 +1,6 @@
1
- mathai/__init__.py,sha256=JdRPSes54qhzvi6f8Rni2sXljzzirrWZsaCmu9W9rws,1525
1
+ mathai/__init__.py,sha256=MX8bkJQ_MOk0fkoCo3r3g5Kwt4zMx9g5M6i64p5kH18,1576
2
2
  mathai/apart.py,sha256=CbCX4pAWIaJgu21wZcW9XdEf82oXgxmtTyD3tUI31Ls,4235
3
- mathai/base.py,sha256=Qp3V5kpEZpg1fM_pB8y5upjkuoIc3I_UUlkhpTj0-3Y,14849
3
+ mathai/base.py,sha256=W_Lk9hQp4wTzF4H5DQLsb8O_HAE6bfqgjqHvWJOMJb8,15114
4
4
  mathai/bivariate_inequality.py,sha256=Da-A1kqVynR0tNOlEI7GSTf5T2vNkcF4etL9-EoyPJg,11415
5
5
  mathai/diff.py,sha256=GEiAGMCTT0dO-ULTUGvTlBKy-Io-r2xcgvFJfmqGurY,6879
6
6
  mathai/expand.py,sha256=yioVkQrtCz1fC8npcnokN1WwvJlGxrO1D4aKn8F8ky0,1757
@@ -10,7 +10,7 @@ mathai/integrate.py,sha256=6Ik_uAzkLyOWCE9M7mqwH_SVTvEdiG0-UYS2KsDgjLI,17454
10
10
  mathai/inverse.py,sha256=ya7P8WjzfaAL3UXL7xqOh5GaIsXLDZ-F6lZFy3IEgaQ,2931
11
11
  mathai/limit.py,sha256=9F8i9UZh2xb-V8A5Sd1gdhDf9c2RFgpE1GdNn9MvbWI,5703
12
12
  mathai/linear.py,sha256=pTo4gXyosUnwG6h5G1zZOMCJPwQaBZyuaeH8XlrBy9o,5219
13
- mathai/logic.py,sha256=wUenUEcIazQH2jnka43QQ9XpLQgY7x3Rq2QUxzFzf-U,9569
13
+ mathai/logic.py,sha256=-riPN3SI0gv53u2jlHY81onlN0NfPXDOpyJszATLZOQ,11353
14
14
  mathai/matrix.py,sha256=k8gIasxtEF1t_B0mJSbDvUJ3FDddvYI8hhy0FMMQ54k,5416
15
15
  mathai/ode.py,sha256=F0Z_Zv2YsnVf4HwIJmqvIenjONaItzy5H739THkLvcU,11616
16
16
  mathai/parser.py,sha256=vXpDobXd6de3-1zdeXVDcZ817oiGM_o2RoVwgUc4U9s,6785
@@ -22,7 +22,7 @@ mathai/structure.py,sha256=u4usB0yPnem2VscgEBqKWxRN9Y4tTjymEaQh1de5Bsk,4121
22
22
  mathai/tool.py,sha256=Wjp8pcBu7MkJr-oAa_bFzKr9mNAB9WrpPISSJd4p-x0,5407
23
23
  mathai/trig.py,sha256=tkn6NgfXj5XzjVB261SuX_mx2g3stqNksoco4O6so90,10713
24
24
  mathai/univariate_inequality.py,sha256=QoE6lZW_cUXa5sbbvwz88DjAVSY--RZt03w02edCVtA,16375
25
- mathai-0.8.1.dist-info/METADATA,sha256=v2DpxYv_i3Tpxv1XmcNGSnX5EgLVShvGyRXFVNR5V6o,7735
26
- mathai-0.8.1.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
27
- mathai-0.8.1.dist-info/top_level.txt,sha256=ROP4l3OhGYw3ihkQGASr18xM9GsK4z3_6whV5AyXLwE,7
28
- mathai-0.8.1.dist-info/RECORD,,
25
+ mathai-0.8.2.dist-info/METADATA,sha256=7pNC30dw3ZaFDHm2q_CNxEZ5E5CUtUPF7T9YYJahyqY,7735
26
+ mathai-0.8.2.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
27
+ mathai-0.8.2.dist-info/top_level.txt,sha256=ROP4l3OhGYw3ihkQGASr18xM9GsK4z3_6whV5AyXLwE,7
28
+ mathai-0.8.2.dist-info/RECORD,,
File without changes