mathai 0.7.5__py3-none-any.whl → 0.7.7__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 +2 -2
- mathai/base.py +1 -1
- mathai/integrate.py +8 -2
- mathai/ode.py +59 -5
- mathai/pde.py +139 -0
- {mathai-0.7.5.dist-info → mathai-0.7.7.dist-info}/METADATA +1 -1
- {mathai-0.7.5.dist-info → mathai-0.7.7.dist-info}/RECORD +9 -8
- {mathai-0.7.5.dist-info → mathai-0.7.7.dist-info}/WHEEL +0 -0
- {mathai-0.7.5.dist-info → mathai-0.7.7.dist-info}/top_level.txt +0 -0
mathai/__init__.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
from .ode import diffsolve as ode_solve
|
|
2
2
|
from .ode import diffsolve_sep as ode_shift_term
|
|
3
3
|
|
|
4
|
+
from .pde import pde_sep, want
|
|
5
|
+
|
|
4
6
|
from .linear import linear_solve, linear_or
|
|
5
7
|
|
|
6
8
|
from .expand import expand
|
|
@@ -11,14 +13,12 @@ from .printeq import printeq, printeq_str
|
|
|
11
13
|
|
|
12
14
|
from .simplify import simplify
|
|
13
15
|
|
|
14
|
-
from .integrate import ref as integrate_save
|
|
15
16
|
from .integrate import integrate_subs_main as integrate_subs
|
|
16
17
|
from .integrate import byparts as integrate_byparts
|
|
17
18
|
from .integrate import sqint as integrate_fraction
|
|
18
19
|
from .integrate import integrate_summation
|
|
19
20
|
from .integrate import rm_const as integrate_const
|
|
20
21
|
from .integrate import solve_integrate as integrate_clean
|
|
21
|
-
from .integrate import inteq as integrate_recursive
|
|
22
22
|
from .integrate import integrate_formula
|
|
23
23
|
|
|
24
24
|
from .diff import diff
|
mathai/base.py
CHANGED
|
@@ -403,7 +403,7 @@ def string_equation_helper(equation_tree):
|
|
|
403
403
|
if equation_tree.name == "f_index":
|
|
404
404
|
return string_equation_helper(equation_tree.children[0])+"["+",".join([string_equation_helper(child) for child in equation_tree.children[1:]])+"]"
|
|
405
405
|
s = "("
|
|
406
|
-
if len(equation_tree.children) == 1 or equation_tree.name[2:] in [chr(ord("A")+i) for i in range(26)]+["limitpinf", "subs", "try", "ref","limit", "integrate", "exist", "forall", "sum2", "int", "pdif", "dif", "A", "B", "C", "covariance", "sum"]:
|
|
406
|
+
if len(equation_tree.children) == 1 or equation_tree.name[2:] in [chr(ord("A")+i) for i in range(26)]+["want", "limitpinf", "subs", "try", "ref","limit", "integrate", "exist", "forall", "sum2", "int", "pdif", "dif", "A", "B", "C", "covariance", "sum"]:
|
|
407
407
|
s = equation_tree.name[2:] + s
|
|
408
408
|
sign = {"f_not":"~", "f_wadd":"+", "f_wmul":"@", "f_intersection":"&", "f_union":"|", "f_sum2":",", "f_exist":",", "f_forall":",", "f_sum":",","f_covariance": ",", "f_B":",", "f_imply":"->", "f_ge":">=", "f_le":"<=", "f_gt":">", "f_lt":"<", "f_cosec":"?" , "f_equiv": "<->", "f_sec":"?", "f_cot": "?", "f_dot": ".", "f_circumcenter":"?", "f_transpose":"?", "f_exp":"?", "f_abs":"?", "f_log":"?", "f_and":"&", "f_or":"|", "f_sub":"-", "f_neg":"?", "f_inv":"?", "f_add": "+", "f_mul": "*", "f_pow": "^", "f_poly": ",", "f_div": "/", "f_sub": "-", "f_dif": ",", "f_sin": "?", "f_cos": "?", "f_tan": "?", "f_eq": "=", "f_sqrt": "?"}
|
|
409
409
|
arr = []
|
mathai/integrate.py
CHANGED
|
@@ -376,6 +376,7 @@ def integration_formula_init():
|
|
|
376
376
|
(f"1/cos(A*{var}+B)^2", f"tan(A*{var}+B)/A"),
|
|
377
377
|
(f"1/sin(A*{var}+B)", f"log(abs(tan((A*{var}+B)/2)))/A"),
|
|
378
378
|
(f"1/cos(A*{var}+B)^3", f"(sec(A*{var}+B)*tan(A*{var}+B)+log(abs(sec(A*{var}+B)+tan(A*{var}+B))))/(2*A)")
|
|
379
|
+
#(f"cos({var})*e^(A*{var})", f"e^(A*{var})/(A^2+1)*(A*cos({var})+sin({var}))")
|
|
379
380
|
]
|
|
380
381
|
formula_list = [[simplify(parse(y)) for y in x] for x in formula_list]
|
|
381
382
|
expr = [[parse("A"), parse("1")], [parse("B"), parse("0")]]
|
|
@@ -449,13 +450,18 @@ def integrate_formula(equation):
|
|
|
449
450
|
if out is not None:
|
|
450
451
|
|
|
451
452
|
return out
|
|
452
|
-
|
|
453
|
-
|
|
453
|
+
|
|
454
|
+
short = shorten(integrand)
|
|
455
|
+
expr_str = str_form(short)
|
|
456
|
+
|
|
457
|
+
if len(str(short)) < 25:
|
|
458
|
+
|
|
454
459
|
if expr_str.count("f_sin") + expr_str.count("f_cos") > 2:
|
|
455
460
|
out = transform_formula(integrand, wrt.name, formula_gen4[0], formula_gen4[1], formula_gen4[2])
|
|
456
461
|
if out is not None:
|
|
457
462
|
return out
|
|
458
463
|
if "f_cos" in expr_str and contain(integrand, tree_form("s_e")):
|
|
464
|
+
|
|
459
465
|
out = transform_formula(integrand, wrt.name, formula_gen11[0], formula_gen11[1], formula_gen11[2])
|
|
460
466
|
if out is not None:
|
|
461
467
|
return out
|
mathai/ode.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from collections import Counter
|
|
1
2
|
from .diff import diff
|
|
2
3
|
from .factor import factor
|
|
3
4
|
from .expand import expand
|
|
@@ -7,7 +8,7 @@ from .simplify import simplify
|
|
|
7
8
|
import copy
|
|
8
9
|
|
|
9
10
|
def inversediff(lhs, rhs):
|
|
10
|
-
count =
|
|
11
|
+
count = 5
|
|
11
12
|
while contain(rhs, tree_form("v_1")) or contain(lhs, tree_form("v_0")):
|
|
12
13
|
success = False
|
|
13
14
|
if rhs.name == "f_add":
|
|
@@ -49,10 +50,8 @@ def inversediff(lhs, rhs):
|
|
|
49
50
|
return simplify(e0(lhs-rhs))
|
|
50
51
|
return simplify(e0(lhs-rhs))
|
|
51
52
|
|
|
52
|
-
intconst = ["v_"+str(i) for i in range(101,150)]
|
|
53
53
|
def allocvar():
|
|
54
|
-
|
|
55
|
-
return tree_form(intconst.pop(0))
|
|
54
|
+
return tree_form("v_101")
|
|
56
55
|
|
|
57
56
|
def epowersplit(eq):
|
|
58
57
|
if eq.name == "f_pow" and eq.children[1].name == "f_add":
|
|
@@ -131,5 +130,60 @@ def diffsolve(eq):
|
|
|
131
130
|
eq2 = diffsolve_sep2(eq2)
|
|
132
131
|
if eq2 is not None:
|
|
133
132
|
return e0(TreeNode("f_subs", [replace(eq2.children[0],b,c), c,b/a]).fx("try"))
|
|
134
|
-
|
|
133
|
+
eq = orig
|
|
134
|
+
|
|
135
|
+
eq = fraction(eq)
|
|
136
|
+
eq = simplify(eq)
|
|
137
|
+
for i in range(2):
|
|
138
|
+
out = linear_dif(eq, tree_form(f"v_{i}"), tree_form(f"v_{1-i}"))
|
|
139
|
+
if out is not None:
|
|
140
|
+
return out
|
|
135
141
|
return eq
|
|
142
|
+
def clist(x):
|
|
143
|
+
return list(x.elements())
|
|
144
|
+
def collect_term(eq, term_lst):
|
|
145
|
+
|
|
146
|
+
lst = None
|
|
147
|
+
if eq.name == "f_add":
|
|
148
|
+
lst = eq.children
|
|
149
|
+
else:
|
|
150
|
+
lst = [eq]
|
|
151
|
+
|
|
152
|
+
other = []
|
|
153
|
+
dic = {}
|
|
154
|
+
term_lst = sorted(term_lst, key=lambda x: -len(factor_generation(x)))
|
|
155
|
+
for item2 in lst:
|
|
156
|
+
done = True
|
|
157
|
+
tmp2 = Counter(factor_generation(item2))
|
|
158
|
+
for index, item in enumerate(term_lst):
|
|
159
|
+
tmp = Counter(factor_generation(item))
|
|
160
|
+
|
|
161
|
+
if (tmp2&tmp) == tmp and clist((tmp2 - tmp)&tmp)==[]:
|
|
162
|
+
if item in dic.keys():
|
|
163
|
+
dic[item] += product(clist(tmp2-tmp))
|
|
164
|
+
else:
|
|
165
|
+
dic[item] = product(clist(tmp2-tmp))
|
|
166
|
+
done = False
|
|
167
|
+
break
|
|
168
|
+
if done:
|
|
169
|
+
other.append(item2)
|
|
170
|
+
other = summation(other)
|
|
171
|
+
|
|
172
|
+
for key in dic.keys():
|
|
173
|
+
dic[key] = simplify(dic[key])
|
|
174
|
+
return [dic, simplify(other)]
|
|
175
|
+
def linear_dif(eq, a, b):
|
|
176
|
+
eq = simplify(eq)
|
|
177
|
+
out = collect_term(eq.children[0], [b.fx("dif"), b*a.fx("dif"), a.fx("dif")])
|
|
178
|
+
|
|
179
|
+
if out[1] == tree_form("d_0"):
|
|
180
|
+
tmp = out[0][b.fx("dif")]
|
|
181
|
+
if tmp != tree_form("d_0"):
|
|
182
|
+
|
|
183
|
+
for key in out[0].keys():
|
|
184
|
+
out[0][key] = simplify(out[0][key]/tmp)
|
|
185
|
+
p, q = out[0][b*a.fx("dif")], -out[0][a.fx("dif")]
|
|
186
|
+
|
|
187
|
+
f = tree_form("s_e") ** TreeNode("f_integrate", [p, a])
|
|
188
|
+
return simplify(TreeNode("f_eq", [b*f, TreeNode("f_integrate", [q*f, a])+allocvar()]))
|
|
189
|
+
return None
|
mathai/pde.py
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
from .ode import diffsolve
|
|
2
|
+
from .base import *
|
|
3
|
+
from .simplify import simplify
|
|
4
|
+
from .diff import diff
|
|
5
|
+
from .fraction import fraction
|
|
6
|
+
from .parser import parse
|
|
7
|
+
from .inverse import inverse
|
|
8
|
+
def capital2(eq):
|
|
9
|
+
if eq.name == "f_pdif":
|
|
10
|
+
return eq.children[0]
|
|
11
|
+
for child in eq.children:
|
|
12
|
+
out = capital2(child)
|
|
13
|
+
if out is not None:
|
|
14
|
+
return out
|
|
15
|
+
return None
|
|
16
|
+
def subs(eq, r2):
|
|
17
|
+
if eq.name == "f_dif":
|
|
18
|
+
return TreeNode("f_pdif", eq.children)
|
|
19
|
+
if eq == r2:
|
|
20
|
+
return parse("x").fx("X") * parse("y").fx("Y")
|
|
21
|
+
if eq.name == "f_pdif":
|
|
22
|
+
return subs(diff(subs(eq.children[0], r2), str_form(eq.children[1])), r2)
|
|
23
|
+
return TreeNode(eq.name, [subs(child, r2) for child in eq.children])
|
|
24
|
+
def inverse_pde(lhs, rhs, depth=3):
|
|
25
|
+
if depth < 0:
|
|
26
|
+
return None
|
|
27
|
+
|
|
28
|
+
lhs = simplify(lhs.copy_tree())
|
|
29
|
+
rhs = simplify(rhs.copy_tree())
|
|
30
|
+
|
|
31
|
+
# separation check: lhs has no y, rhs has no x
|
|
32
|
+
lhs_str = str_form(lhs)
|
|
33
|
+
rhs_str = str_form(rhs)
|
|
34
|
+
|
|
35
|
+
if "v_1" not in lhs_str and "v_0" not in rhs_str:
|
|
36
|
+
return [lhs, rhs]
|
|
37
|
+
|
|
38
|
+
sides = [lhs, rhs]
|
|
39
|
+
|
|
40
|
+
for side in range(2):
|
|
41
|
+
eq = sides[side]
|
|
42
|
+
|
|
43
|
+
if eq.name not in ("f_add", "f_mul"):
|
|
44
|
+
continue
|
|
45
|
+
|
|
46
|
+
# iterate over a COPY — never mutate while iterating
|
|
47
|
+
for i, child in enumerate(eq.children.copy()):
|
|
48
|
+
# rebuild remaining expression safely
|
|
49
|
+
rest_children = [
|
|
50
|
+
c.copy_tree()
|
|
51
|
+
for j, c in enumerate(eq.children)
|
|
52
|
+
if j != i
|
|
53
|
+
]
|
|
54
|
+
|
|
55
|
+
if not rest_children:
|
|
56
|
+
continue
|
|
57
|
+
|
|
58
|
+
if len(rest_children) == 1:
|
|
59
|
+
rest = rest_children[0]
|
|
60
|
+
else:
|
|
61
|
+
rest = TreeNode(eq.name, rest_children)
|
|
62
|
+
|
|
63
|
+
other = sides[1 - side].copy_tree()
|
|
64
|
+
|
|
65
|
+
# move term across
|
|
66
|
+
if eq.name == "f_add":
|
|
67
|
+
moved = TreeNode("f_add", [other, -child.copy_tree()])
|
|
68
|
+
else: # f_mul
|
|
69
|
+
moved = TreeNode("f_mul", [other, TreeNode("f_pow", [child.copy_tree(), tree_form("d_-1")])])
|
|
70
|
+
|
|
71
|
+
moved = simplify(moved)
|
|
72
|
+
rest = simplify(rest)
|
|
73
|
+
|
|
74
|
+
if side == 0:
|
|
75
|
+
out = inverse_pde(rest, moved, depth - 1)
|
|
76
|
+
else:
|
|
77
|
+
out = inverse_pde(moved, rest, depth - 1)
|
|
78
|
+
|
|
79
|
+
if out is not None:
|
|
80
|
+
return out
|
|
81
|
+
|
|
82
|
+
return None
|
|
83
|
+
def subs2(eq):
|
|
84
|
+
if eq.name == "f_pdif":
|
|
85
|
+
return eq.children[0].fx("dif")/eq.children[1].fx("dif")
|
|
86
|
+
return TreeNode(eq.name, [subs2(child) for child in eq.children])
|
|
87
|
+
def capital(eq):
|
|
88
|
+
if eq.name[:2] == "f_" and eq.name != eq.name.lower():
|
|
89
|
+
return eq
|
|
90
|
+
for child in eq.children:
|
|
91
|
+
out = capital(child)
|
|
92
|
+
if out is not None:
|
|
93
|
+
return out
|
|
94
|
+
return None
|
|
95
|
+
def abs_const(eq):
|
|
96
|
+
if eq.name == "f_abs":
|
|
97
|
+
return tree_form("v_101")*eq.children[0]
|
|
98
|
+
return TreeNode(eq.name, [abs_const(child) for child in eq.children])
|
|
99
|
+
def want(eq):
|
|
100
|
+
if eq.name == "f_want":
|
|
101
|
+
eq2 = eq.children[0]
|
|
102
|
+
v = [tree_form(item) for item in vlist(eq.children[0])]
|
|
103
|
+
lst = {}
|
|
104
|
+
if eq.children[1].name == "f_and":
|
|
105
|
+
for item in eq.children[1].children:
|
|
106
|
+
item = abs_const(item)
|
|
107
|
+
for item2 in v:
|
|
108
|
+
if contain(item, item2):
|
|
109
|
+
out = inverse(item.children[0], str_form(item2))
|
|
110
|
+
if out is not None:
|
|
111
|
+
lst[item2] = out
|
|
112
|
+
break
|
|
113
|
+
for key in lst.keys():
|
|
114
|
+
eq2 = replace(eq2, key, lst[key])
|
|
115
|
+
if len(lst.keys()) == len(v):
|
|
116
|
+
return simplify(eq2)
|
|
117
|
+
return TreeNode(eq.name, [want(child) for child in eq.children])
|
|
118
|
+
def pde_sep(eq):
|
|
119
|
+
if eq.name == "f_eq":
|
|
120
|
+
eq = eq.children[0]
|
|
121
|
+
r2 = capital2(eq)
|
|
122
|
+
|
|
123
|
+
eq = simplify(fraction(subs(eq, r2)))
|
|
124
|
+
out = inverse_pde(eq,tree_form("d_0"))
|
|
125
|
+
if out is not None:
|
|
126
|
+
out = list(out)
|
|
127
|
+
lst = []
|
|
128
|
+
for i in range(2):
|
|
129
|
+
out[i] = subs2(out[i])
|
|
130
|
+
out[i] = TreeNode("f_eq", [out[i], tree_form("v_102")])
|
|
131
|
+
out[i] = fraction(simplify(out[i]))
|
|
132
|
+
r = capital(out[i])
|
|
133
|
+
lst.append(r)
|
|
134
|
+
out[i] = replace(out[i], r, tree_form(f"v_{1-i}"))
|
|
135
|
+
out[i] = diffsolve(out[i])
|
|
136
|
+
out[i] = replace(out[i], tree_form(f"v_{1-i}"), r)
|
|
137
|
+
out = TreeNode("f_eq", [r2, TreeNode("f_want", [product(lst), TreeNode("f_and", out)])])
|
|
138
|
+
return replace(replace(out, lst[0], parse("a")), lst[1], parse("b"))
|
|
139
|
+
return out
|
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
mathai/__init__.py,sha256=
|
|
1
|
+
mathai/__init__.py,sha256=XkmMsqLr7MkYu1lMwwgsiEagtuOK_KsxLTbAHXgYSmo,1510
|
|
2
2
|
mathai/apart.py,sha256=VSS3khE9PNuxiRvdU5JDl4IN-KJBSIFjwR17pkhviXI,4197
|
|
3
|
-
mathai/base.py,sha256=
|
|
3
|
+
mathai/base.py,sha256=LdIpxwqhqjL-O7GTfzyzCNN5_Zibp6dNZQVD42SwfIw,14862
|
|
4
4
|
mathai/bivariate_inequality.py,sha256=Da-A1kqVynR0tNOlEI7GSTf5T2vNkcF4etL9-EoyPJg,11415
|
|
5
5
|
mathai/console.py,sha256=Sn58iwYE79MLEh67s8X3q6vZjw6g7f9XM1T8_dBBR2o,3048
|
|
6
6
|
mathai/diff.py,sha256=3__PoEqs_JlS2fRkebXyL-7eyV69ZoV8vCjpYgDWcXE,3297
|
|
7
7
|
mathai/expand.py,sha256=IuzMX6emCT480VE27aCtR0eWU-rJ2VElvRLVa2xcRw0,2582
|
|
8
8
|
mathai/factor.py,sha256=mz_UlPuAqwvsextLB0FM5KWIuuDiMMKG51bXrofqzw8,12830
|
|
9
9
|
mathai/fraction.py,sha256=3Qer3K20ZO2exMAYp1z80H69qRjVMfWKg5Ik0Ud8wf4,4402
|
|
10
|
-
mathai/integrate.py,sha256=
|
|
10
|
+
mathai/integrate.py,sha256=nUE2_ubklNIfj6QGtZTGuZmprYX-U3Ln454W-I1JddQ,17365
|
|
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=ABsGyA0TMfeHNG1kh_MsDcnmzkEnOHOzwNMw0QocyY0,7073
|
|
17
17
|
mathai/parser.py,sha256=FcjOTM_2-YFqPNS9EyZfo76pa4CedDJCbcs8wOXc_uU,7130
|
|
18
18
|
mathai/parsetab.py,sha256=TL-4jvRM_Tx6ipwet8CFJc2DkjR4tGsbrGF_r4IC8xI,9651
|
|
19
|
+
mathai/pde.py,sha256=1EuVO2y9QAQK42fMbtmxvQyAV_7wsWH9zWLvH6ZDoZQ,4710
|
|
19
20
|
mathai/printeq.py,sha256=4UgLJo-vV_YlVw_3QUQY_jQMHrFnG-ZKAyVZsd7yD6o,1450
|
|
20
21
|
mathai/simplify.py,sha256=bCtYyLyc3pY04hta-MU62ii5-O4zUwGHjs1Q4WBYEvY,19680
|
|
21
22
|
mathai/statistics.py,sha256=ifmaXFzRc6vIgPFWP-9EDfZZYmmMGw-WEKhoQZUaHXo,884
|
|
@@ -23,7 +24,7 @@ mathai/structure.py,sha256=wrU7kqphSN7CqaVffyHHXD2-3t5My_Z_TtYFoUe_lTU,4099
|
|
|
23
24
|
mathai/tool.py,sha256=ozcXTXLbKUnyPM9r9kz9M43YA2CBcWezcqLZfEs8rpc,6051
|
|
24
25
|
mathai/trig.py,sha256=fnBbfiopcQzFg4ya1BoO5M0X_aCBnse2bjnKh1juw4I,11223
|
|
25
26
|
mathai/univariate_inequality.py,sha256=LPFdWgC1y5zBwnsy1wwZxj-yP_SbqFDhCmTTzhuwoiY,16469
|
|
26
|
-
mathai-0.7.
|
|
27
|
-
mathai-0.7.
|
|
28
|
-
mathai-0.7.
|
|
29
|
-
mathai-0.7.
|
|
27
|
+
mathai-0.7.7.dist-info/METADATA,sha256=mV07F05pSZIebDjsHe3QNUo3dEmFiZ6tNR2TR6Grxlk,7735
|
|
28
|
+
mathai-0.7.7.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
29
|
+
mathai-0.7.7.dist-info/top_level.txt,sha256=ROP4l3OhGYw3ihkQGASr18xM9GsK4z3_6whV5AyXLwE,7
|
|
30
|
+
mathai-0.7.7.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|