mathai 0.7.8__py3-none-any.whl → 0.7.9__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/fraction.py +90 -87
- mathai/integrate.py +10 -4
- mathai/ode.py +164 -104
- mathai/pde.py +5 -10
- mathai/structure.py +3 -3
- {mathai-0.7.8.dist-info → mathai-0.7.9.dist-info}/METADATA +1 -1
- {mathai-0.7.8.dist-info → mathai-0.7.9.dist-info}/RECORD +9 -9
- {mathai-0.7.8.dist-info → mathai-0.7.9.dist-info}/WHEEL +0 -0
- {mathai-0.7.8.dist-info → mathai-0.7.9.dist-info}/top_level.txt +0 -0
mathai/fraction.py
CHANGED
|
@@ -2,102 +2,105 @@ from .base import *
|
|
|
2
2
|
from .simplify import simplify
|
|
3
3
|
from .expand import expand
|
|
4
4
|
|
|
5
|
-
def fraction(eq):
|
|
6
|
-
stack = [(eq, None)] # (current_node, parent_processed_children)
|
|
7
|
-
result_map = {} # Map original nodes to their processed TreeNode
|
|
8
5
|
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
def fraction(expr):
|
|
7
|
+
if expr is None:
|
|
8
|
+
return None
|
|
9
|
+
|
|
10
|
+
expr = simplify(expr)
|
|
11
|
+
|
|
12
|
+
# -----------------------------
|
|
13
|
+
# leaf
|
|
14
|
+
# -----------------------------
|
|
15
|
+
if expr.children == []:
|
|
16
|
+
return expr
|
|
11
17
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
continue
|
|
18
|
+
# recurse first (inner-most first)
|
|
19
|
+
children = [fraction(c) for c in expr.children]
|
|
15
20
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
# -----------------------------
|
|
22
|
+
# ADDITION: collect denominators
|
|
23
|
+
# -----------------------------
|
|
24
|
+
if expr.name == "f_add":
|
|
25
|
+
terms = []
|
|
20
26
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
for c in children:
|
|
28
|
+
# term is a multiplication
|
|
29
|
+
if c.name == "f_mul":
|
|
30
|
+
num = []
|
|
31
|
+
den = []
|
|
32
|
+
for f in c.children:
|
|
33
|
+
if (
|
|
34
|
+
f.name == "f_pow"
|
|
35
|
+
and f.children[1].name.startswith("d_")
|
|
36
|
+
and int(f.children[1].name[2:]) < 0
|
|
37
|
+
):
|
|
38
|
+
n = int(f.children[1].name[2:])
|
|
39
|
+
den.append(
|
|
40
|
+
f.children[0]
|
|
41
|
+
if n == -1
|
|
42
|
+
else TreeNode("f_pow", [f.children[0], tree_form(f"d_{-n}")])
|
|
43
|
+
)
|
|
44
|
+
else:
|
|
45
|
+
num.append(f)
|
|
46
|
+
terms.append((num, den))
|
|
30
47
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
48
|
+
# pure reciprocal
|
|
49
|
+
elif (
|
|
50
|
+
c.name == "f_pow"
|
|
51
|
+
and c.children[1].name.startswith("d_")
|
|
52
|
+
and int(c.children[1].name[2:]) < 0
|
|
53
|
+
):
|
|
54
|
+
n = int(c.children[1].name[2:])
|
|
55
|
+
terms.append(([], [
|
|
56
|
+
c.children[0]
|
|
57
|
+
if n == -1
|
|
58
|
+
else TreeNode("f_pow", [c.children[0], tree_form(f"d_{-n}")])
|
|
59
|
+
]))
|
|
37
60
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
child_processed = result_map[child]
|
|
42
|
-
if child_processed.name == "f_pow" and child_processed.children[1].name[:2] == "d_" and int(child_processed.children[1].name[2:]) < 0:
|
|
43
|
-
den = []
|
|
44
|
-
n = int(child_processed.children[1].name[2:])
|
|
45
|
-
if n == -1:
|
|
46
|
-
den.append(child_processed.children[0])
|
|
47
|
-
else:
|
|
48
|
-
den.append(TreeNode("f_pow", [child_processed.children[0], tree_form("d_" + str(-n))]))
|
|
49
|
-
con.append([[], den])
|
|
50
|
-
elif child_processed.name == "f_mul":
|
|
51
|
-
num = []
|
|
52
|
-
den = []
|
|
53
|
-
for child2 in child_processed.children:
|
|
54
|
-
if child2.name == "f_pow" and child2.children[1].name[:2] == "d_" and int(child2.children[1].name[2:]) < 0:
|
|
55
|
-
n = int(child2.children[1].name[2:])
|
|
56
|
-
if n == -1:
|
|
57
|
-
den.append(child2.children[0])
|
|
58
|
-
else:
|
|
59
|
-
den.append(TreeNode("f_pow", [child2.children[0], tree_form("d_" + str(-n))]))
|
|
60
|
-
else:
|
|
61
|
-
num.append(child2)
|
|
62
|
-
con.append([num, den])
|
|
63
|
-
else:
|
|
64
|
-
con.append([[child_processed], []])
|
|
61
|
+
# normal term
|
|
62
|
+
else:
|
|
63
|
+
terms.append(([c], []))
|
|
65
64
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
for i in range(len(con)):
|
|
70
|
-
b_children = con[i][0].copy()
|
|
71
|
-
for j in range(len(con)):
|
|
72
|
-
if i == j:
|
|
73
|
-
continue
|
|
74
|
-
b_children += con[j][1]
|
|
75
|
-
if len(b_children) == 0:
|
|
76
|
-
b_children = [tree_form("d_1")]
|
|
77
|
-
elif len(b_children) == 1:
|
|
78
|
-
b_children = b_children
|
|
79
|
-
else:
|
|
80
|
-
b_children = [TreeNode("f_mul", b_children)]
|
|
81
|
-
a_children += b_children if isinstance(b_children, list) else [b_children]
|
|
65
|
+
# if no denominators → rebuild normally
|
|
66
|
+
if not any(den for _, den in terms):
|
|
67
|
+
return TreeNode("f_add", children)
|
|
82
68
|
|
|
83
|
-
|
|
69
|
+
# -----------------------------
|
|
70
|
+
# build numerator
|
|
71
|
+
# -----------------------------
|
|
72
|
+
num_terms = []
|
|
73
|
+
for i, (num_i, _) in enumerate(terms):
|
|
74
|
+
acc = list(num_i)
|
|
75
|
+
for j, (_, den_j) in enumerate(terms):
|
|
76
|
+
if i != j:
|
|
77
|
+
acc += den_j
|
|
78
|
+
if not acc:
|
|
79
|
+
acc = [tree_form("d_1")]
|
|
80
|
+
num_terms.append(
|
|
81
|
+
acc[0] if len(acc) == 1 else TreeNode("f_mul", acc)
|
|
82
|
+
)
|
|
84
83
|
|
|
85
|
-
|
|
86
|
-
c_children = []
|
|
87
|
-
for i in range(len(con)):
|
|
88
|
-
c_children += con[i][1]
|
|
89
|
-
if len(c_children) == 1:
|
|
90
|
-
c = c_children[0]
|
|
91
|
-
else:
|
|
92
|
-
c = TreeNode("f_mul", c_children)
|
|
93
|
-
c = TreeNode("f_pow", [c, tree_form("d_-1")])
|
|
84
|
+
numerator = TreeNode("f_add", num_terms)
|
|
94
85
|
|
|
95
|
-
|
|
96
|
-
|
|
86
|
+
# -----------------------------
|
|
87
|
+
# build denominator
|
|
88
|
+
# -----------------------------
|
|
89
|
+
den_all = []
|
|
90
|
+
for _, den in terms:
|
|
91
|
+
den_all += den
|
|
97
92
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
93
|
+
denom = den_all[0] if len(den_all) == 1 else TreeNode("f_mul", den_all)
|
|
94
|
+
denom = TreeNode("f_pow", [denom, tree_form("d_-1")])
|
|
95
|
+
|
|
96
|
+
return simplify(
|
|
97
|
+
TreeNode(
|
|
98
|
+
"f_mul",
|
|
99
|
+
[simplify(expand(numerator)), denom],
|
|
100
|
+
)
|
|
101
|
+
)
|
|
101
102
|
|
|
102
|
-
#
|
|
103
|
-
|
|
103
|
+
# -----------------------------
|
|
104
|
+
# default reconstruction
|
|
105
|
+
# -----------------------------
|
|
106
|
+
return TreeNode(expr.name, children)
|
mathai/integrate.py
CHANGED
|
@@ -97,6 +97,8 @@ def place_try2(eq):
|
|
|
97
97
|
return eq.children[try_lst.pop(0)]
|
|
98
98
|
return TreeNode(eq.name, [place_try2(child) for child in eq.children])
|
|
99
99
|
def _solve_integrate(eq):
|
|
100
|
+
if eq is None:
|
|
101
|
+
return None
|
|
100
102
|
if eq.name == "f_ref":
|
|
101
103
|
return eq
|
|
102
104
|
if eq.name == "f_subs":
|
|
@@ -153,6 +155,8 @@ def inteq(eq):
|
|
|
153
155
|
else:
|
|
154
156
|
return TreeNode(eq.name, [inteq(child) for child in eq.children])
|
|
155
157
|
def rm(eq):
|
|
158
|
+
if eq is None:
|
|
159
|
+
return None
|
|
156
160
|
if eq.name == "f_try":
|
|
157
161
|
eq = TreeNode(eq.name, list(set(eq.children)))
|
|
158
162
|
return TreeNode(eq.name, [rm(child) for child in eq.children if child is not None])
|
|
@@ -161,6 +165,8 @@ def solve_integrate(eq):
|
|
|
161
165
|
eq2 = dowhile(eq, _solve_integrate)
|
|
162
166
|
#eq2 = dowhile(eq2, handle_try)
|
|
163
167
|
eq2 = rm(eq2)
|
|
168
|
+
if eq2 is None:
|
|
169
|
+
return None
|
|
164
170
|
if eq2.name == "f_try":
|
|
165
171
|
eq2.children = list(set(eq2.children))
|
|
166
172
|
return eq2
|
|
@@ -409,8 +415,8 @@ def integration_formula_ex():
|
|
|
409
415
|
|
|
410
416
|
formula_gen11 = integration_formula_ex()
|
|
411
417
|
def rm_const(equation):
|
|
412
|
-
if equation
|
|
413
|
-
return
|
|
418
|
+
if equation is None:
|
|
419
|
+
return None
|
|
414
420
|
eq2 = equation
|
|
415
421
|
if eq2.name == "f_integrate" and contain(eq2.children[0], eq2.children[1]):
|
|
416
422
|
equation = eq2.children[0]
|
|
@@ -436,8 +442,8 @@ def shorten(eq):
|
|
|
436
442
|
return tree_form("d_0")
|
|
437
443
|
return TreeNode(eq.name, [shorten(child) for child in eq.children])
|
|
438
444
|
def integrate_formula(equation):
|
|
439
|
-
if equation
|
|
440
|
-
return
|
|
445
|
+
if equation is None:
|
|
446
|
+
return None
|
|
441
447
|
eq2 = equation.copy_tree()
|
|
442
448
|
if eq2.name == "f_integrate":
|
|
443
449
|
integrand = eq2.children[0]
|
mathai/ode.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import itertools
|
|
1
2
|
from collections import Counter
|
|
2
|
-
from .diff import diff
|
|
3
|
-
from .factor import factor, factor2
|
|
3
|
+
from .diff import diff, diff2
|
|
4
|
+
from .factor import factor, factor2, term_common2
|
|
4
5
|
from .expand import expand
|
|
5
6
|
from .base import *
|
|
6
7
|
from .fraction import fraction
|
|
@@ -9,71 +10,110 @@ import copy
|
|
|
9
10
|
from .inverse import inverse
|
|
10
11
|
from .parser import parse
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
out = TreeNode(lst[i].name, out)
|
|
26
|
-
|
|
27
|
-
if len(out.children) == 1:
|
|
28
|
-
out = out.children[0]
|
|
29
|
-
out = out.copy_tree()
|
|
30
|
-
if lst[i].name == "f_add":
|
|
31
|
-
lst[i] = lst[i] - out
|
|
32
|
-
lst[1-i] = lst[1-i] - out
|
|
33
|
-
else:
|
|
34
|
-
lst[i] = lst[i] / out
|
|
35
|
-
lst[1-i] = lst[1-i] / out
|
|
36
|
-
|
|
37
|
-
lst = [simplify(expand(simplify(item))) for item in lst]
|
|
38
|
-
return lst
|
|
39
|
-
|
|
40
|
-
def kkk(lhs, rhs, depth=3):
|
|
41
|
-
|
|
42
|
-
lst = jjj(lhs, rhs)
|
|
43
|
-
|
|
44
|
-
if depth < 0:
|
|
45
|
-
return lst, False
|
|
13
|
+
def rev(eq):
|
|
14
|
+
tmp = factor_generation(eq)
|
|
15
|
+
if tree_form("v_0").fx("dif")**-1 in tmp or tree_form("v_1").fx("dif")**-1 in tmp:
|
|
16
|
+
return False
|
|
17
|
+
for child in eq.children:
|
|
18
|
+
if not rev(child):
|
|
19
|
+
return False
|
|
20
|
+
return True
|
|
21
|
+
node_count = 100
|
|
22
|
+
def kkk(lhs, rhs, depth=5):
|
|
23
|
+
global node_count
|
|
24
|
+
lst = [simplify(lhs), simplify(rhs)]
|
|
25
|
+
orig = copy.deepcopy(lst)
|
|
46
26
|
if not contain(lst[0], tree_form("v_1")) and not contain(lst[1], tree_form("v_0")):
|
|
27
|
+
if not contain(lst[0], tree_form("v_0")) and not contain(lst[1], tree_form("v_1")):
|
|
28
|
+
return lst, False
|
|
47
29
|
return lst, True
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
30
|
+
node_count -= 1
|
|
31
|
+
|
|
32
|
+
if depth < 0 or node_count < 0:
|
|
33
|
+
return lst, False
|
|
34
|
+
for j in range(2):
|
|
35
|
+
for i in range(2):
|
|
36
|
+
if lst[i].name in ["f_mul", "f_add"]:
|
|
37
|
+
for child in lst[i].children:
|
|
38
|
+
out = child
|
|
39
|
+
if j == 0:
|
|
40
|
+
if contain(out, tree_form(f"v_{i}")) or not contain(out, tree_form(f"v_{1-i}")):
|
|
41
|
+
continue
|
|
42
|
+
if contain(out, tree_form(f"v_{i}")) and not contain(out, tree_form(f"v_{1-i}")):
|
|
43
|
+
continue
|
|
44
|
+
|
|
45
|
+
if lst[i].name == "f_add":
|
|
46
|
+
lst[i] = lst[i] - out
|
|
47
|
+
lst[1-i] = lst[1-i] - out
|
|
48
|
+
elif lst[i].name == "f_mul":
|
|
49
|
+
lst[i] = lst[i] / out
|
|
50
|
+
lst[1-i] = lst[1-i] / out
|
|
51
|
+
else:
|
|
52
|
+
continue
|
|
53
|
+
|
|
54
|
+
output = kkk(lst[0], lst[1], depth-1)
|
|
55
|
+
lst = orig
|
|
56
|
+
|
|
57
|
+
if output[1]:
|
|
58
|
+
return output
|
|
61
59
|
|
|
62
|
-
output = kkk(lst[0], lst[1], depth-1)
|
|
63
|
-
lst = orig
|
|
64
|
-
if output[1]:
|
|
65
|
-
return output
|
|
66
60
|
return lst, False
|
|
67
|
-
|
|
61
|
+
def clr(eq):
|
|
62
|
+
return simplify(product([item for item in factor_generation(eq) if "f_add" in str_form(item)]))
|
|
68
63
|
def inversediff(lhs, rhs):
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
64
|
+
global node_count
|
|
65
|
+
eq = simplify(fraction(TreeNode("f_eq", [lhs-rhs, tree_form("d_0")]))).children[0]
|
|
66
|
+
eq = simplify(term_common2(eq))
|
|
67
|
+
eq = clr(eq)
|
|
68
|
+
|
|
69
|
+
out= None
|
|
70
|
+
if eq.name == "f_add":
|
|
71
|
+
h = {}
|
|
72
|
+
n = [eq]
|
|
73
|
+
for i in range(len(eq.children)-2,1,-1):
|
|
74
|
+
for item in itertools.combinations(list(range(len(eq.children))), i):
|
|
75
|
+
item = tuple(sorted(list(item)))
|
|
76
|
+
tmp = simplify(term_common2(simplify(summation([eq.children[x] for x in item]))))
|
|
77
|
+
if tmp.name == "f_mul":
|
|
78
|
+
h[item] = tmp
|
|
79
|
+
|
|
80
|
+
for item in itertools.combinations(list(h.keys()),2):
|
|
81
|
+
|
|
82
|
+
g = []
|
|
83
|
+
for x in item:
|
|
84
|
+
g += x
|
|
85
|
+
if sum([len(x) for x in item]) == len(set(g)):
|
|
86
|
+
pass
|
|
87
|
+
else:
|
|
88
|
+
continue
|
|
89
|
+
|
|
90
|
+
item2 = summation([eq.children[x] for x in list(set(range(len(eq.children)))-set(g))])
|
|
91
|
+
n.append(simplify(term_common2(simplify(h[item[0]] + h[item[1]]))+item2))
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
for item in list(set(n)):
|
|
95
|
+
|
|
96
|
+
item = clr(item)
|
|
97
|
+
node_count = 100
|
|
98
|
+
|
|
99
|
+
tmp = kkk(item, tree_form("d_0"))
|
|
100
|
+
|
|
101
|
+
if tmp[1]:
|
|
102
|
+
out = tmp[0]
|
|
103
|
+
break
|
|
104
|
+
else:
|
|
105
|
+
node_count = 100
|
|
106
|
+
tmp = kkk(eq, tree_form("d_0"))
|
|
107
|
+
if tmp[1]:
|
|
108
|
+
out = tmp[0]
|
|
109
|
+
if out is None:
|
|
110
|
+
return None
|
|
111
|
+
out = [simplify(fraction(item)) for item in out]
|
|
112
|
+
|
|
113
|
+
if not rev(out[0]) and not rev(out[1]):
|
|
75
114
|
|
|
76
|
-
|
|
115
|
+
out[0] = fraction(1/out[0])
|
|
116
|
+
out[1] = fraction(1/out[1])
|
|
77
117
|
return simplify(e0(out[0]-out[1]))
|
|
78
118
|
|
|
79
119
|
def allocvar():
|
|
@@ -88,38 +128,28 @@ def esolve(s):
|
|
|
88
128
|
return product([tree_form("s_e")**child for child in s.children]) - tree_form("d_1")
|
|
89
129
|
return TreeNode(s.name, [esolve(child) for child in s.children])
|
|
90
130
|
def diffsolve_sep2(eq):
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
s = []
|
|
94
|
-
eq = simplify(expand(eq))
|
|
95
|
-
eq = e1(eq)
|
|
96
|
-
|
|
97
|
-
def vlor1(eq):
|
|
98
|
-
if contain(eq, tree_form("v_0")) and not contain(eq, tree_form("v_1")):
|
|
99
|
-
return True
|
|
100
|
-
if contain(eq, tree_form("v_1")) and not contain(eq, tree_form("v_0")):
|
|
101
|
-
return True
|
|
102
|
-
return False
|
|
103
|
-
if eq.name == "f_add" and all(vlor1(child) and [str_form(x) for x in factor_generation(copy.deepcopy(child))].count(str_form(tree_form(vlist(child)[0]).fx("dif")))==1 for child in eq.children):
|
|
104
|
-
for child in eq.children:
|
|
105
|
-
v = vlist(child)[0]
|
|
106
|
-
v2 = tree_form(v).fx("dif")
|
|
107
|
-
child = replace(child, v2, tree_form("d_1"))
|
|
108
|
-
child = simplify(child)
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
tmp6 = TreeNode("f_integrate", [child, tree_form(v)])
|
|
112
|
-
s.append(tmp6)
|
|
113
|
-
|
|
114
|
-
if s[-1] is None:
|
|
115
|
-
return None
|
|
116
|
-
s.append(allocvar())
|
|
117
|
-
else:
|
|
131
|
+
lst = None
|
|
132
|
+
if eq is None:
|
|
118
133
|
return None
|
|
119
|
-
|
|
120
|
-
|
|
134
|
+
eq = eq.children[0]
|
|
135
|
+
if eq.name == "f_add":
|
|
136
|
+
lst = list(eq.children)
|
|
137
|
+
else:
|
|
138
|
+
lst = [eq]
|
|
139
|
+
s = [allocvar()]
|
|
140
|
+
|
|
141
|
+
for item in lst:
|
|
142
|
+
item = simplify(item)
|
|
143
|
+
tmp = factor_generation(item)
|
|
144
|
+
|
|
145
|
+
tmp2 = product([k for k in tmp if k.name != "f_dif"])
|
|
146
|
+
|
|
147
|
+
if tree_form("v_0").fx("dif") in tmp:
|
|
148
|
+
s.append(TreeNode("f_integrate", [tmp2, tree_form("v_0")]))
|
|
149
|
+
elif tree_form("v_1").fx("dif") in tmp:
|
|
150
|
+
s.append(TreeNode("f_integrate", [tmp2, tree_form("v_1")]))
|
|
121
151
|
|
|
122
|
-
return
|
|
152
|
+
return TreeNode("f_eq", [summation(s), tree_form("d_0")])
|
|
123
153
|
def e0(eq):
|
|
124
154
|
return TreeNode("f_eq", [eq, tree_form("d_0")])
|
|
125
155
|
def e1(eq):
|
|
@@ -136,11 +166,17 @@ def groupe(eq):
|
|
|
136
166
|
|
|
137
167
|
def diffsolve_sep(eq):
|
|
138
168
|
eq = epowersplit(eq)
|
|
169
|
+
|
|
139
170
|
eq = inversediff(tree_form("d_0"), eq.children[0].copy_tree())
|
|
171
|
+
|
|
140
172
|
return eq
|
|
141
173
|
|
|
142
174
|
def diffsolve(eq):
|
|
143
175
|
orig = eq.copy_tree()
|
|
176
|
+
eq = diff2(eq)
|
|
177
|
+
eq = subs2(eq, order(eq))
|
|
178
|
+
eq = fraction(simplify(fraction(eq)))
|
|
179
|
+
|
|
144
180
|
if order(eq) == 2:
|
|
145
181
|
for i in range(2):
|
|
146
182
|
out = second_order_dif(eq, tree_form(f"v_{i}"), tree_form(f"v_{1-i}"))
|
|
@@ -149,28 +185,38 @@ def diffsolve(eq):
|
|
|
149
185
|
return orig
|
|
150
186
|
|
|
151
187
|
eq = diffsolve_sep2(diffsolve_sep(eq))
|
|
188
|
+
|
|
152
189
|
if eq is None:
|
|
153
190
|
for i in range(2):
|
|
154
191
|
a = tree_form(f"v_{i}")
|
|
155
192
|
b = tree_form(f"v_{1-i}")
|
|
156
193
|
c = tree_form("v_2")
|
|
157
|
-
eq2 =
|
|
158
|
-
|
|
159
|
-
eq2 =
|
|
194
|
+
eq2 = orig
|
|
195
|
+
|
|
196
|
+
eq2 = subs2(eq2, 1)
|
|
197
|
+
eq2 = replace(eq2, b, b*a)
|
|
198
|
+
eq2 = subs3(eq2)
|
|
199
|
+
|
|
200
|
+
eq2 = simplify(fraction(simplify(eq2)))
|
|
201
|
+
|
|
160
202
|
eq2 = diffsolve_sep(eq2)
|
|
203
|
+
|
|
161
204
|
eq2 = diffsolve_sep2(eq2)
|
|
162
205
|
if eq2 is not None:
|
|
163
206
|
return e0(TreeNode("f_subs", [replace(eq2.children[0],b,c), c,b/a]).fx("try"))
|
|
164
207
|
eq = orig
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
208
|
+
eq = simplify(eq)
|
|
209
|
+
eq = subs2(eq, 1)
|
|
210
|
+
eq = fraction(eq)
|
|
211
|
+
for i in range(2):
|
|
212
|
+
|
|
213
|
+
out = linear_dif(eq, tree_form(f"v_{i}"), tree_form(f"v_{1-i}"))
|
|
214
|
+
if out is not None:
|
|
215
|
+
return out
|
|
216
|
+
return orig
|
|
217
|
+
else:
|
|
218
|
+
return eq
|
|
219
|
+
|
|
174
220
|
def clist(x):
|
|
175
221
|
return list(x.elements())
|
|
176
222
|
def collect_term(eq, term_lst):
|
|
@@ -219,6 +265,19 @@ def order(eq,m=0):
|
|
|
219
265
|
out = order(child, m)
|
|
220
266
|
best = max(out, best)
|
|
221
267
|
return best
|
|
268
|
+
def subs2(eq, orde):
|
|
269
|
+
if eq.name in ["f_dif", "f_pdif"] and len(eq.children) == 2:
|
|
270
|
+
if orde == 1:
|
|
271
|
+
return eq.children[0].fx("dif")/eq.children[1].fx("dif")
|
|
272
|
+
else:
|
|
273
|
+
return subs2(TreeNode("f_dif", eq.children), orde)
|
|
274
|
+
return TreeNode(eq.name, [subs2(child, orde) for child in eq.children])
|
|
275
|
+
def subs3(eq):
|
|
276
|
+
if eq.name == "f_dif" and eq.children[0].name == "f_add":
|
|
277
|
+
return summation([subs3(child.fx("dif")) for child in eq.children[0].children])
|
|
278
|
+
if eq.name == "f_dif" and eq.children[0].name == "f_mul":
|
|
279
|
+
return summation([product([subs3(child.fx("dif")) if index==index2 else child for index2, child in enumerate(eq.children[0].children)]) for index in range(len(eq.children[0].children))])
|
|
280
|
+
return TreeNode(eq.name, [subs3(child) for child in eq.children])
|
|
222
281
|
def second_order_dif(eq, a, b):
|
|
223
282
|
eq = simplify(eq)
|
|
224
283
|
nn = [TreeNode("f_dif", [TreeNode("f_dif", [b,a]),a]), TreeNode("f_dif", [b,a]), b]
|
|
@@ -260,7 +319,8 @@ def linear_dif(eq, a, b):
|
|
|
260
319
|
for key in out[0].keys():
|
|
261
320
|
out[0][key] = simplify(out[0][key]/tmp)
|
|
262
321
|
p, q = out[0][b*a.fx("dif")], -out[0][a.fx("dif")]
|
|
263
|
-
|
|
322
|
+
if contain(p, b) or contain(q, b):
|
|
323
|
+
return None
|
|
264
324
|
f = tree_form("s_e") ** TreeNode("f_integrate", [p, a])
|
|
265
325
|
return simplify(TreeNode("f_eq", [b*f, TreeNode("f_integrate", [q*f, a])+allocvar()]))
|
|
266
326
|
return None
|
mathai/pde.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from .expand import expand
|
|
2
|
-
from .ode import diffsolve, inversediff, order, groupe, epowersplit
|
|
2
|
+
from .ode import diffsolve, inversediff, order, groupe, epowersplit, subs2
|
|
3
3
|
from .base import *
|
|
4
4
|
from .simplify import simplify
|
|
5
5
|
from .diff import diff2
|
|
@@ -16,13 +16,7 @@ def capital2(eq):
|
|
|
16
16
|
if out is not None:
|
|
17
17
|
return out
|
|
18
18
|
return None
|
|
19
|
-
|
|
20
|
-
if eq.name == "f_pdif":
|
|
21
|
-
if orde == 1:
|
|
22
|
-
return eq.children[0].fx("dif")/eq.children[1].fx("dif")
|
|
23
|
-
else:
|
|
24
|
-
return subs2(TreeNode("f_dif", eq.children), orde)
|
|
25
|
-
return TreeNode(eq.name, [subs2(child, orde) for child in eq.children])
|
|
19
|
+
|
|
26
20
|
def capital(eq):
|
|
27
21
|
if eq.name[:2] == "f_" and eq.name != eq.name.lower():
|
|
28
22
|
return eq
|
|
@@ -36,6 +30,8 @@ def abs_const(eq):
|
|
|
36
30
|
return tree_form("v_101")*eq.children[0]
|
|
37
31
|
return TreeNode(eq.name, [abs_const(child) for child in eq.children])
|
|
38
32
|
def want(eq):
|
|
33
|
+
if eq is None:
|
|
34
|
+
return None
|
|
39
35
|
if eq.name == "f_want":
|
|
40
36
|
|
|
41
37
|
eq2 = eq.children[0]
|
|
@@ -95,8 +91,7 @@ def pde_sep(eq):
|
|
|
95
91
|
r = capital(out[i])
|
|
96
92
|
lst.append(r)
|
|
97
93
|
out[i] = replace(out[i], r, tree_form(f"v_{1-i}"))
|
|
98
|
-
out[i] =
|
|
99
|
-
|
|
94
|
+
out[i] = tree_form(str_form(out[i]).replace("f_pdif", "f_dif"))
|
|
100
95
|
out[i] = diffsolve(out[i])
|
|
101
96
|
|
|
102
97
|
out[i] = replace(out[i], tree_form(f"v_{1-i}"), r)
|
mathai/structure.py
CHANGED
|
@@ -2,7 +2,7 @@ import itertools
|
|
|
2
2
|
from .simplify import simplify
|
|
3
3
|
from .base import *
|
|
4
4
|
|
|
5
|
-
def structure(equation, formula, formula_out=None, only_const=False):
|
|
5
|
+
def structure(equation, formula, formula_out=None, only_const=False, wrt=None):
|
|
6
6
|
varlist = {}
|
|
7
7
|
def helper(equation, formula):
|
|
8
8
|
nonlocal varlist
|
|
@@ -60,7 +60,7 @@ def structure(equation, formula, formula_out=None, only_const=False):
|
|
|
60
60
|
for item in lst(formula):
|
|
61
61
|
varlist = {}
|
|
62
62
|
if helper(equation, item):
|
|
63
|
-
if only_const and any(
|
|
63
|
+
if only_const and any(contain(varlist[key], tree_form(wrt)) for key in varlist.keys()):
|
|
64
64
|
continue
|
|
65
65
|
if formula_out is None:
|
|
66
66
|
return varlist
|
|
@@ -90,7 +90,7 @@ def transform_formula(equation, wrt, formula_list, var, expr):
|
|
|
90
90
|
if var != "":
|
|
91
91
|
p = True
|
|
92
92
|
try:
|
|
93
|
-
out = structure(equation.copy_tree(), copy.deepcopy(item[0]), copy.deepcopy(item[1]), p)
|
|
93
|
+
out = structure(equation.copy_tree(), copy.deepcopy(item[0]), copy.deepcopy(item[1]), p, wrt)
|
|
94
94
|
if out is not None:
|
|
95
95
|
out = simplify(out)
|
|
96
96
|
|
|
@@ -6,25 +6,25 @@ mathai/console.py,sha256=Sn58iwYE79MLEh67s8X3q6vZjw6g7f9XM1T8_dBBR2o,3048
|
|
|
6
6
|
mathai/diff.py,sha256=GEiAGMCTT0dO-ULTUGvTlBKy-Io-r2xcgvFJfmqGurY,6879
|
|
7
7
|
mathai/expand.py,sha256=IuzMX6emCT480VE27aCtR0eWU-rJ2VElvRLVa2xcRw0,2582
|
|
8
8
|
mathai/factor.py,sha256=mz_UlPuAqwvsextLB0FM5KWIuuDiMMKG51bXrofqzw8,12830
|
|
9
|
-
mathai/fraction.py,sha256=
|
|
10
|
-
mathai/integrate.py,sha256=
|
|
9
|
+
mathai/fraction.py,sha256=jCIDurenm6grPWNDSY_67zci6fmsIhKG24qm2gbmYtQ,3322
|
|
10
|
+
mathai/integrate.py,sha256=6Ik_uAzkLyOWCE9M7mqwH_SVTvEdiG0-UYS2KsDgjLI,17454
|
|
11
11
|
mathai/inverse.py,sha256=ya7P8WjzfaAL3UXL7xqOh5GaIsXLDZ-F6lZFy3IEgaQ,2931
|
|
12
12
|
mathai/limit.py,sha256=9F8i9UZh2xb-V8A5Sd1gdhDf9c2RFgpE1GdNn9MvbWI,5703
|
|
13
13
|
mathai/linear.py,sha256=viGlPU8BPrjLWHlyNUvnfPHNH5d4ZBImiQMdyXaKGg0,5702
|
|
14
14
|
mathai/logic.py,sha256=Ndz4Fd6aNCmzFlqoPyyIpSmV_BXmYHsurePjLyZJoNc,9809
|
|
15
15
|
mathai/matrix.py,sha256=MFe6tUL4a3jYuP13fXWGwER_34AbqfoOK5kHwVHfsKk,7169
|
|
16
|
-
mathai/ode.py,sha256=
|
|
16
|
+
mathai/ode.py,sha256=F0Z_Zv2YsnVf4HwIJmqvIenjONaItzy5H739THkLvcU,11616
|
|
17
17
|
mathai/parser.py,sha256=7NWPPzci7MZazkGG_q5uUyKCOZ_-rqvOhp9UZjzBNc4,7100
|
|
18
18
|
mathai/parsetab.py,sha256=TL-4jvRM_Tx6ipwet8CFJc2DkjR4tGsbrGF_r4IC8xI,9651
|
|
19
|
-
mathai/pde.py,sha256=
|
|
19
|
+
mathai/pde.py,sha256=KL1UFPrfyp8lI1p-mXUaEPo4Yia2GkCw9oZT2R1zhKI,3576
|
|
20
20
|
mathai/printeq.py,sha256=4UgLJo-vV_YlVw_3QUQY_jQMHrFnG-ZKAyVZsd7yD6o,1450
|
|
21
21
|
mathai/simplify.py,sha256=bCtYyLyc3pY04hta-MU62ii5-O4zUwGHjs1Q4WBYEvY,19680
|
|
22
22
|
mathai/statistics.py,sha256=ifmaXFzRc6vIgPFWP-9EDfZZYmmMGw-WEKhoQZUaHXo,884
|
|
23
|
-
mathai/structure.py,sha256=
|
|
23
|
+
mathai/structure.py,sha256=u4usB0yPnem2VscgEBqKWxRN9Y4tTjymEaQh1de5Bsk,4121
|
|
24
24
|
mathai/tool.py,sha256=ozcXTXLbKUnyPM9r9kz9M43YA2CBcWezcqLZfEs8rpc,6051
|
|
25
25
|
mathai/trig.py,sha256=fnBbfiopcQzFg4ya1BoO5M0X_aCBnse2bjnKh1juw4I,11223
|
|
26
26
|
mathai/univariate_inequality.py,sha256=LPFdWgC1y5zBwnsy1wwZxj-yP_SbqFDhCmTTzhuwoiY,16469
|
|
27
|
-
mathai-0.7.
|
|
28
|
-
mathai-0.7.
|
|
29
|
-
mathai-0.7.
|
|
30
|
-
mathai-0.7.
|
|
27
|
+
mathai-0.7.9.dist-info/METADATA,sha256=KuLNc-p43qoo0WX2rG-VBhOVbknBxYm9ZZy8pI8SKr8,7735
|
|
28
|
+
mathai-0.7.9.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
29
|
+
mathai-0.7.9.dist-info/top_level.txt,sha256=ROP4l3OhGYw3ihkQGASr18xM9GsK4z3_6whV5AyXLwE,7
|
|
30
|
+
mathai-0.7.9.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|