mathai 0.2.0__py3-none-any.whl → 0.2.1__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 +1 -0
- mathai/base.py +2 -0
- mathai/expand.py +2 -0
- mathai/limit.py +126 -0
- mathai/simplify.py +16 -2
- mathai/structure.py +2 -1
- mathai/trig.py +2 -0
- {mathai-0.2.0.dist-info → mathai-0.2.1.dist-info}/METADATA +1 -1
- {mathai-0.2.0.dist-info → mathai-0.2.1.dist-info}/RECORD +11 -10
- {mathai-0.2.0.dist-info → mathai-0.2.1.dist-info}/WHEEL +0 -0
- {mathai-0.2.0.dist-info → mathai-0.2.1.dist-info}/top_level.txt +0 -0
mathai/__init__.py
CHANGED
mathai/base.py
CHANGED
mathai/expand.py
CHANGED
mathai/limit.py
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
from .structure import structure
|
2
|
+
from .base import *
|
3
|
+
from .parser import parse
|
4
|
+
from .simplify import simplify, solve
|
5
|
+
from .expand import expand
|
6
|
+
from .diff import diff
|
7
|
+
from .trig import trig0
|
8
|
+
from .fraction import fraction
|
9
|
+
from .printeq import printeq_str
|
10
|
+
tab=0
|
11
|
+
def substitute_val(eq, val, var="v_0"):
|
12
|
+
eq = replace(eq, tree_form(var), tree_form("d_"+str(val)))
|
13
|
+
return eq
|
14
|
+
|
15
|
+
def subslimit(equation, var):
|
16
|
+
equation2 = trig0(replace(equation, var, tree_form("d_0")))
|
17
|
+
try:
|
18
|
+
tmp = simplify(equation2)
|
19
|
+
return simplify(expand(tmp))
|
20
|
+
except:
|
21
|
+
return None
|
22
|
+
|
23
|
+
def check(num, den, var):
|
24
|
+
n, d = None, None
|
25
|
+
|
26
|
+
n, d = (dowhile(replace(e, var, tree_form("d_0")), lambda x: trig0(simplify(x))) for e in (num, den))
|
27
|
+
if n is None or d is None:
|
28
|
+
return False
|
29
|
+
if n == 0 and d == 0: return True
|
30
|
+
if d != 0: return simplify(n/d)
|
31
|
+
return False
|
32
|
+
def lhospital(num, den, steps,var):
|
33
|
+
logs = []
|
34
|
+
out = check(num, den, var)
|
35
|
+
if isinstance(out, TreeNode):
|
36
|
+
return out
|
37
|
+
for _ in range(steps):
|
38
|
+
num2, den2 = map(lambda e: simplify(diff(e, var.name)), (num, den))
|
39
|
+
out = check(num2, den2, var)
|
40
|
+
if out is True:
|
41
|
+
num, den = num2, den2
|
42
|
+
logs += [(0,"lim x->0 "+printeq_str(simplify(num/den)))]
|
43
|
+
continue
|
44
|
+
if out is False:
|
45
|
+
eq2 = simplify(fraction(simplify(num/den)))
|
46
|
+
return eq2,logs
|
47
|
+
return out,logs
|
48
|
+
def lhospital2(eq, var):
|
49
|
+
eq= simplify(eq)
|
50
|
+
if eq is None:
|
51
|
+
return None
|
52
|
+
if not contain(eq, var):
|
53
|
+
return eq,[]
|
54
|
+
num, dem = [simplify(item) for item in num_dem(eq)]
|
55
|
+
if num is None or dem is None:
|
56
|
+
return eq,[]
|
57
|
+
|
58
|
+
return lhospital(num, dem, 10,var)
|
59
|
+
ls = [parse("sin(A)"), parse("A^B-1"),parse("log(1+A)"), parse("cos(A)")]
|
60
|
+
ls= [simplify(item) for item in ls]
|
61
|
+
|
62
|
+
def approx(eq, var):
|
63
|
+
n, d= num_dem(eq)
|
64
|
+
n, d = solve(n), solve(d)
|
65
|
+
n, d = expand(n), expand(d)
|
66
|
+
out = []
|
67
|
+
for equation in [n, d]:
|
68
|
+
for item in factor_generation(equation):
|
69
|
+
tmp = structure(item, ls[0])
|
70
|
+
if tmp is not None and contain(tmp["v_-1"], var):
|
71
|
+
item2 = substitute_val(tmp["v_-1"], 0, var.name)
|
72
|
+
if tree_form("d_0") == expand(simplify(item2)):
|
73
|
+
equation = equation/item
|
74
|
+
equation = equation*tmp["v_-1"]
|
75
|
+
break
|
76
|
+
elif tree_form("d_0") == expand(simplify(tree_form("s_pi") - item2)):
|
77
|
+
equation = equation/item
|
78
|
+
equation = equation*(tree_form("s_pi") - tmp["v_-1"])
|
79
|
+
break
|
80
|
+
tmp = structure(item, ls[1])
|
81
|
+
if tmp is not None and contain(tmp["v_-1"], var) and not contain(tmp["v_-2"], var):
|
82
|
+
item2 = substitute_val(tmp["v_-1"], 0, var.name)
|
83
|
+
item2 = expand(solve(item2))
|
84
|
+
if tree_form("d_0") == item2:
|
85
|
+
equation = equation/item
|
86
|
+
equation = solve(equation*tmp["v_-1"]*tmp["v_-2"].fx("log"))
|
87
|
+
break
|
88
|
+
tmp = structure(item, ls[2])
|
89
|
+
if tmp is not None and contain(tmp["v_-1"], var):
|
90
|
+
|
91
|
+
item2 = substitute_val(tmp["v_-1"], 0, var.name)
|
92
|
+
item2 = expand(solve(item2))
|
93
|
+
if tree_form("d_0") == item2:
|
94
|
+
equation = equation/item
|
95
|
+
equation = solve(equation*tmp["v_-1"])
|
96
|
+
break
|
97
|
+
tmp = structure(item, ls[3])
|
98
|
+
if tmp is not None and contain(tmp["v_-1"], var):
|
99
|
+
item2 = substitute_val(item, 0, var.name)
|
100
|
+
|
101
|
+
if tree_form("d_0") == expand(solve(item2)):
|
102
|
+
|
103
|
+
equation = equation/item
|
104
|
+
equation = equation*(tree_form("d_1") - tmp["v_-1"]**tree_form("d_2"))
|
105
|
+
break
|
106
|
+
|
107
|
+
equation = solve(equation)
|
108
|
+
out.append(equation)
|
109
|
+
return simplify(out[0]/out[1])
|
110
|
+
def approx_limit(equation, var):
|
111
|
+
return dowhile(equation, lambda x: approx(x, var))
|
112
|
+
|
113
|
+
def limit(equation, var=tree_form("v_0")):
|
114
|
+
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):
|
117
|
+
return eq2,logs
|
118
|
+
equation, tmp = lhospital2(equation, var)
|
119
|
+
equation = simplify(expand(simplify(equation)))
|
120
|
+
if not contain(equation, var):
|
121
|
+
return equation,logs+tmp
|
122
|
+
'''
|
123
|
+
if equation.name == "f_add":
|
124
|
+
return simplify(summation([limit(child, var) for child in equation.children]))
|
125
|
+
'''
|
126
|
+
return equation,logs+tmp
|
mathai/simplify.py
CHANGED
@@ -157,6 +157,7 @@ def clear_div(eq):
|
|
157
157
|
return solve(product(lst2))
|
158
158
|
|
159
159
|
def simplify(eq):
|
160
|
+
error = False
|
160
161
|
if eq.name == "f_eq":
|
161
162
|
if eq.children[1] != 0:
|
162
163
|
return TreeNode(eq.name, [clear_div(simplify(eq.children[0]-eq.children[1])), tree_form("d_0")])
|
@@ -170,6 +171,11 @@ def simplify(eq):
|
|
170
171
|
|
171
172
|
a, b = int(eq.children[0].name[2:]), int(eq.children[1].name[2:])
|
172
173
|
a = a**abs(b)
|
174
|
+
if b == 0 and a == 0:
|
175
|
+
error= True
|
176
|
+
return eq
|
177
|
+
if b == 0:
|
178
|
+
b = 1
|
173
179
|
b = int(b/abs(b))
|
174
180
|
if b == 1:
|
175
181
|
eq = tree_form("d_"+str(a))
|
@@ -195,6 +201,9 @@ def simplify(eq):
|
|
195
201
|
for i in range(len(eq.children)-1,-1,-1):
|
196
202
|
child= eq.children[i]
|
197
203
|
if child.name == "f_pow" and child.children[0].name[:2] == "d_" and child.children[1] == -1:
|
204
|
+
if int(child.children[0].name[2:]) == 0:
|
205
|
+
error = True
|
206
|
+
return eq
|
198
207
|
n = n*Fraction(1,int(child.children[0].name[2:]))
|
199
208
|
eq.children.pop(i)
|
200
209
|
elif child.name[:2] == "d_":
|
@@ -209,7 +218,7 @@ def simplify(eq):
|
|
209
218
|
eq = eq.children[0]
|
210
219
|
return TreeNode(eq.name, [helper3(child) for child in eq.children])
|
211
220
|
def helper4(eq):
|
212
|
-
|
221
|
+
nonlocal error
|
213
222
|
def perfect_nth_root_value(x, n):
|
214
223
|
"""Return integer y if x is a perfect n-th power (y**n == x), else None."""
|
215
224
|
if x < 0 and n % 2 == 0:
|
@@ -253,7 +262,10 @@ def simplify(eq):
|
|
253
262
|
if eq.name == "f_pow" and eq.children[0] == tree_form("d_1"):
|
254
263
|
eq = tree_form("d_1")
|
255
264
|
if eq.name == "f_pow" and eq.children[0] == tree_form("d_0"):
|
256
|
-
eq
|
265
|
+
if frac(eq.children[1]) is not None and frac(eq.children[1]) <= 0:
|
266
|
+
error = True
|
267
|
+
else:
|
268
|
+
eq = tree_form("d_0")
|
257
269
|
if eq.name == "f_pow" and eq.children[0].name == "f_pow" and eq.children[0].children[1] == tree_form("d_2")**-1 and eq.children[1] == tree_form("d_2"):
|
258
270
|
eq = eq.children[0].children[0]
|
259
271
|
if (eq.name == "f_sin" and eq.children[0].name == "f_arcsin") or (eq.name == "f_cos" and eq.children[0].name == "f_arccos") or (eq.name == "f_tan" and eq.children[0].name == "f_arctan"):
|
@@ -323,4 +335,6 @@ def simplify(eq):
|
|
323
335
|
return eq
|
324
336
|
eq = dowhile(eq, fx3)
|
325
337
|
eq = dowhile(eq, helper8)
|
338
|
+
if error:
|
339
|
+
return None
|
326
340
|
return solve(eq)
|
mathai/structure.py
CHANGED
@@ -55,7 +55,8 @@ def structure(equation, formula, formula_out=None, only_const=False):
|
|
55
55
|
node.name = "f_mul"
|
56
56
|
return TreeNode(node.name, [conversionrev(child) for child in node.children])
|
57
57
|
equation = conversion(equation)
|
58
|
-
formula_out
|
58
|
+
if formula_out is not None:
|
59
|
+
formula_out = conversion(formula_out)
|
59
60
|
for item in lst(formula):
|
60
61
|
varlist = {}
|
61
62
|
if helper(equation, item):
|
mathai/trig.py
CHANGED
@@ -1,22 +1,23 @@
|
|
1
|
-
mathai/__init__.py,sha256=
|
1
|
+
mathai/__init__.py,sha256=myFxwz93RBoOeNg9HhA0tsIqy1exyDrCzt1ewyHf9B0,530
|
2
2
|
mathai/apart.py,sha256=P0B21wHUFitc5RGbNJlwSeOdseOMcav4I7teFNcZmFA,3130
|
3
|
-
mathai/base.py,sha256=
|
3
|
+
mathai/base.py,sha256=y6ARBJWtpXiLXOW1kAZczWq223r2j1dzTxj69YHHh7M,12287
|
4
4
|
mathai/console.py,sha256=FsEMqDsgFeBSUiPCm9sfReZp56NSyoFVldqmVwvW4lg,3119
|
5
5
|
mathai/diff.py,sha256=Dvc-tuiW8jLncybjGqHs2WTg2vpMEdRJqUoIdnDj4sk,2879
|
6
|
-
mathai/expand.py,sha256=
|
6
|
+
mathai/expand.py,sha256=RTSKEa2Jx537kSAnWcGskdNyhJeuHOOR4nWplVO-v9k,1794
|
7
7
|
mathai/factor.py,sha256=1-Bxl3MX6P1mYM-CX0hRskCrTZWHFdaUL-V1OqX48hY,5316
|
8
8
|
mathai/fraction.py,sha256=KGldpi8mndp5cvp6qbN7ZdMZyVmK6popa3AwkWmHXl4,2573
|
9
9
|
mathai/integrate.py,sha256=I_9hIi3m9eoYjYwBbp_Bu1VXVRiXbUqYcJfL3cpLBPk,12652
|
10
10
|
mathai/inverse.py,sha256=jd3YMqFgeHBUh9JoZa-1Wqh5lXZNB_UcrSD1paZYn-Q,2578
|
11
|
+
mathai/limit.py,sha256=UOecxbq1ySSZce3dT0wfGfhyPynG5CmdcAbrzkTPXCo,4855
|
11
12
|
mathai/linear.py,sha256=eVnDbJYC1TWwg4J7ovBKsaHYlSoDmXk5jQpsqwtVPyI,5481
|
12
13
|
mathai/logic.py,sha256=UvHzRmKcO9AD51tRzHmpNSEhgW5gmaf4XPaQKFjGfC4,9653
|
13
14
|
mathai/parser.py,sha256=ENtMMm7Q_5QZL6cjbwsXGVJv-H53ueCPGEosJy4LcjY,6809
|
14
15
|
mathai/printeq.py,sha256=JTB0_RBcgt1yFviqlHtXGXuSXcpKrxzSxj5WHkOHon4,1318
|
15
|
-
mathai/simplify.py,sha256=
|
16
|
-
mathai/structure.py,sha256=
|
16
|
+
mathai/simplify.py,sha256=Cg4ZmpcnE4_qS5e7-v6SS1UYoVhkjdWptLjrYl7jkB8,14196
|
17
|
+
mathai/structure.py,sha256=Hgw2y43dwasa6G8z6OS2lmReh7JHwlChGn-FUdEaWY8,4106
|
17
18
|
mathai/tool.py,sha256=87N5Ya7DmHdFOobTYDAjPHNWZuMzMIDjYN0ZtlHjxqE,1099
|
18
|
-
mathai/trig.py,sha256=
|
19
|
-
mathai-0.2.
|
20
|
-
mathai-0.2.
|
21
|
-
mathai-0.2.
|
22
|
-
mathai-0.2.
|
19
|
+
mathai/trig.py,sha256=ywu89MJfAB81JCzsVPBLpGGv8od0LhLn5cgDtLtYwmw,6897
|
20
|
+
mathai-0.2.1.dist-info/METADATA,sha256=nI6xnVdiD2HHECrof4FWV0t2dV61Tw53pltur-RJIq0,741
|
21
|
+
mathai-0.2.1.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
|
22
|
+
mathai-0.2.1.dist-info/top_level.txt,sha256=ROP4l3OhGYw3ihkQGASr18xM9GsK4z3_6whV5AyXLwE,7
|
23
|
+
mathai-0.2.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|