mathai 0.8.1__tar.gz → 0.8.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.
- {mathai-0.8.1 → mathai-0.8.2}/PKG-INFO +1 -1
- {mathai-0.8.1 → mathai-0.8.2}/mathai/__init__.py +2 -1
- {mathai-0.8.1 → mathai-0.8.2}/mathai/base.py +8 -1
- {mathai-0.8.1 → mathai-0.8.2}/mathai/logic.py +62 -8
- {mathai-0.8.1 → mathai-0.8.2}/mathai.egg-info/PKG-INFO +1 -1
- {mathai-0.8.1 → mathai-0.8.2}/setup.py +1 -1
- {mathai-0.8.1 → mathai-0.8.2}/README.md +0 -0
- {mathai-0.8.1 → mathai-0.8.2}/mathai/apart.py +0 -0
- {mathai-0.8.1 → mathai-0.8.2}/mathai/bivariate_inequality.py +0 -0
- {mathai-0.8.1 → mathai-0.8.2}/mathai/diff.py +0 -0
- {mathai-0.8.1 → mathai-0.8.2}/mathai/expand.py +0 -0
- {mathai-0.8.1 → mathai-0.8.2}/mathai/factor.py +0 -0
- {mathai-0.8.1 → mathai-0.8.2}/mathai/fraction.py +0 -0
- {mathai-0.8.1 → mathai-0.8.2}/mathai/integrate.py +0 -0
- {mathai-0.8.1 → mathai-0.8.2}/mathai/inverse.py +0 -0
- {mathai-0.8.1 → mathai-0.8.2}/mathai/limit.py +0 -0
- {mathai-0.8.1 → mathai-0.8.2}/mathai/linear.py +0 -0
- {mathai-0.8.1 → mathai-0.8.2}/mathai/matrix.py +0 -0
- {mathai-0.8.1 → mathai-0.8.2}/mathai/ode.py +0 -0
- {mathai-0.8.1 → mathai-0.8.2}/mathai/parser.py +0 -0
- {mathai-0.8.1 → mathai-0.8.2}/mathai/pde.py +0 -0
- {mathai-0.8.1 → mathai-0.8.2}/mathai/printeq.py +0 -0
- {mathai-0.8.1 → mathai-0.8.2}/mathai/simplify.py +0 -0
- {mathai-0.8.1 → mathai-0.8.2}/mathai/statistics.py +0 -0
- {mathai-0.8.1 → mathai-0.8.2}/mathai/structure.py +0 -0
- {mathai-0.8.1 → mathai-0.8.2}/mathai/tool.py +0 -0
- {mathai-0.8.1 → mathai-0.8.2}/mathai/trig.py +0 -0
- {mathai-0.8.1 → mathai-0.8.2}/mathai/univariate_inequality.py +0 -0
- {mathai-0.8.1 → mathai-0.8.2}/mathai.egg-info/SOURCES.txt +0 -0
- {mathai-0.8.1 → mathai-0.8.2}/mathai.egg-info/dependency_links.txt +0 -0
- {mathai-0.8.1 → mathai-0.8.2}/mathai.egg-info/requires.txt +0 -0
- {mathai-0.8.1 → mathai-0.8.2}/mathai.egg-info/top_level.txt +0 -0
- {mathai-0.8.1 → mathai-0.8.2}/setup.cfg +0 -0
|
@@ -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
|
|
|
@@ -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
|
|
@@ -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
|
-
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|