mathai 0.7.7__py3-none-any.whl → 0.7.8__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
@@ -1,7 +1,7 @@
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
4
+ from .pde import pde_sep, want, absorb
5
5
 
6
6
  from .linear import linear_solve, linear_or
7
7
 
@@ -21,7 +21,7 @@ from .integrate import rm_const as integrate_const
21
21
  from .integrate import solve_integrate as integrate_clean
22
22
  from .integrate import integrate_formula
23
23
 
24
- from .diff import diff
24
+ from .diff import diff, diff2
25
25
 
26
26
  from .factor import factor as factor1
27
27
  from .factor import factor2, factor3
mathai/base.py CHANGED
@@ -14,7 +14,6 @@ def contains_list_or_neg(node):
14
14
  return False
15
15
 
16
16
  class TreeNode:
17
- matmul = None
18
17
 
19
18
  def __init__(self, name, children=None):
20
19
  if children is None:
mathai/diff.py CHANGED
@@ -1,6 +1,87 @@
1
+ from .trig import trig0
1
2
  from .simplify import simplify
2
3
  from .base import *
3
- from .trig import trig0
4
+
5
+ def helper(eq):
6
+ name = eq.name
7
+ if name in ["f_dif", "f_pdif"]:
8
+ if eq.children[0].name == "f_add":
9
+ return summation([TreeNode(name, [child, eq.children[1]]) for child in eq.children[0].children])
10
+
11
+ if eq.children[0].name == "f_mul":
12
+ return summation([product([TreeNode(name, [child, eq.children[1]]) if index==index2 else child for index2, child in enumerate(eq.children[0].children)])\
13
+ for index in range(len(eq.children[0].children))])
14
+ if eq.children[0].name == "f_pow" and "v_" not in str_form(eq.children[0].children[1]):
15
+ base, power = eq.children[0].children
16
+ dbase = TreeNode(name, [base, eq.children[1]])
17
+ b1 = power - tree_form("d_1")
18
+ bab1 = TreeNode("f_pow", [base, b1])
19
+ return power * bab1 * dbase
20
+
21
+ if eq.children[0].name == "f_pow":
22
+ a, b = eq.children
23
+ return a**b * ((b/a) * TreeNode(name, [a, eq.children[1]]) + a.fx("log") * TreeNode(name, [b, eq.children[1]]))
24
+
25
+ if "v_" not in str_form(eq.children[0]):
26
+ return tree_form("d_0")
27
+
28
+ if eq.children[0] == eq.children[1]:
29
+ return tree_form("d_1")
30
+
31
+ if name == "f_pdif" and not contain(eq.children[0], eq.children[1]):
32
+ return tree_form("d_0")
33
+ if eq.children[0].name == "f_sin":
34
+ eq.children[0].name = "f_cos"
35
+ d = TreeNode(name, [eq.children[0].children[0], eq.children[1]])
36
+ return d*eq.children[0]
37
+ if eq.children[0].name == "f_cos":
38
+ eq.children[0].name = "f_sin"
39
+ d = TreeNode(name, [eq.children[0].children[0], eq.children[1]])
40
+ return tree_form("d_-1")*d*eq.children[0]
41
+ if eq.children[0].name == "f_tan":
42
+ d = TreeNode(name, [eq.children[0].children[0], eq.children[1]])
43
+ return d/(eq.children[0].children[0].fx("cos")*eq.children[0].children[0].fx("cos"))
44
+ if eq.children[0].name == "f_log":
45
+ d = TreeNode(name, [eq.children[0].children[0], eq.children[1]])
46
+ return d*(tree_form("d_1")/eq.children[0].children[0])
47
+ if eq.children[0].name == "f_arcsin":
48
+ d = TreeNode(name, [eq.children[0].children[0], eq.children[1]])
49
+ return d/(tree_form("d_1")-eq.children[0].children[0]*eq.children[0].children[0])**(tree_form("d_2")**-1)
50
+ if eq.children[0].name == "f_arccos":
51
+ d = TreeNode(name, [eq.children[0].children[0], eq.children[1]])
52
+ return tree_form("d_-1")*d/(tree_form("d_1")-eq.children[0].children[0]*eq.children[0].children[0])**(tree_form("d_2")**-1)
53
+ if eq.children[0].name == "f_arctan":
54
+ d = TreeNode(name, [eq.children[0].children[0], eq.children[1]])
55
+ return d/(tree_form("d_1")+eq.children[0].children[0]*eq.children[0].children[0])
56
+
57
+ return eq
58
+
59
+ def diff3(eq):
60
+ eq = simplify(eq)
61
+
62
+ stack = [(eq, False)]
63
+ out = {}
64
+
65
+ while stack:
66
+ node, visited = stack.pop()
67
+
68
+ if not visited:
69
+ stack.append((node, True))
70
+ for c in node.children:
71
+ stack.append((c, False))
72
+ continue
73
+
74
+ new_children = [out[c] for c in node.children]
75
+ rebuilt = TreeNode(node.name, new_children)
76
+ rebuilt = helper(rebuilt)
77
+ rebuilt = simplify(rebuilt)
78
+
79
+ out[node] = rebuilt
80
+
81
+ return out[eq]
82
+
83
+ def diff2(eq):
84
+ return dowhile(eq, diff3)
4
85
  def diff(equation, var="v_0"):
5
86
  def diffeq(eq):
6
87
  eq = simplify(eq)
@@ -54,7 +135,7 @@ def diff(equation, var="v_0"):
54
135
  bab1 = TreeNode("f_pow", [base, b1])
55
136
  return power * bab1 * dbase
56
137
  return TreeNode("f_dif", [eq, tree_form(var)])
57
- def helper(equation, var="v_0"):
138
+ def helper2(equation, var="v_0"):
58
139
  if equation.name == "f_dif":
59
140
  if equation.children[0].name == var:
60
141
  return tree_form("d_1")
@@ -62,7 +143,7 @@ def diff(equation, var="v_0"):
62
143
  return tree_form("d_0")
63
144
  else:
64
145
  return equation
65
- return TreeNode(equation.name, [helper(child, var) for child in equation.children])
146
+ return TreeNode(equation.name, [helper2(child, var) for child in equation.children])
66
147
  def calc(eq):
67
148
  if eq.name == "f_dif":
68
149
  return diffeq(trig0(eq.children[0]))
@@ -70,5 +151,6 @@ def diff(equation, var="v_0"):
70
151
  if var is None:
71
152
  return simplify(calc(equation))
72
153
  equation = diffeq(trig0(equation))
73
- equation = helper(equation, var)
154
+ equation = helper2(equation, var)
74
155
  return simplify(equation)
156
+
mathai/integrate.py CHANGED
@@ -159,7 +159,7 @@ def rm(eq):
159
159
  def solve_integrate(eq):
160
160
 
161
161
  eq2 = dowhile(eq, _solve_integrate)
162
- eq2 = dowhile(eq2, handle_try)
162
+ #eq2 = dowhile(eq2, handle_try)
163
163
  eq2 = rm(eq2)
164
164
  if eq2.name == "f_try":
165
165
  eq2.children = list(set(eq2.children))
mathai/ode.py CHANGED
@@ -1,54 +1,80 @@
1
1
  from collections import Counter
2
2
  from .diff import diff
3
- from .factor import factor
3
+ from .factor import factor, factor2
4
4
  from .expand import expand
5
5
  from .base import *
6
6
  from .fraction import fraction
7
7
  from .simplify import simplify
8
8
  import copy
9
+ from .inverse import inverse
10
+ from .parser import parse
11
+
12
+
13
+ def jjj(lhs, rhs):
14
+ lst = [lhs, rhs]
15
+ for i in range(2):
16
+ if lst[i].name in ["f_mul", "f_add"]:
17
+
18
+ out = []
19
+ for child in lst[i].children:
20
+
21
+ if not contain(child, tree_form(f"v_{i}")):
22
+ out.append(child)
23
+ if out == []:
24
+ continue
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
46
+ if not contain(lst[0], tree_form("v_1")) and not contain(lst[1], tree_form("v_0")):
47
+ return lst, True
48
+ orig = copy.deepcopy(lst)
49
+ for i in range(2):
50
+ if lst[i].name in ["f_mul", "f_add"]:
51
+ for child in lst[i].children:
52
+
53
+ out = child
54
+ if lst[i].name == "f_add":
55
+ lst[i] = lst[i] - out
56
+ lst[1-i] = lst[1-i] - out
57
+ else:
58
+ lst[i] = lst[i] / out
59
+ lst[1-i] = lst[1-i] / out
60
+ lst = [simplify(item) for item in lst]
61
+
62
+ output = kkk(lst[0], lst[1], depth-1)
63
+ lst = orig
64
+ if output[1]:
65
+ return output
66
+ return lst, False
9
67
 
10
68
  def inversediff(lhs, rhs):
11
- count = 5
12
- while contain(rhs, tree_form("v_1")) or contain(lhs, tree_form("v_0")):
13
- success = False
14
- if rhs.name == "f_add":
15
- for i in range(len(rhs.children)-1,-1,-1):
16
- if not contain(rhs.children[i], tree_form("v_0")) or str_form(tree_form("v_1").fx("dif")) in [str_form(x) for x in factor_generation(rhs.children[i])]:
17
- if contain(rhs.children[i], tree_form("v_0")) or contain(rhs.children[i], tree_form("v_1")):
18
- success = True
19
- lhs = lhs - rhs.children[i]
20
- rhs.children.pop(i)
21
- elif rhs.name == "f_mul":
22
- for i in range(len(rhs.children)-1,-1,-1):
23
- if not contain(rhs.children[i], tree_form("v_0")):
24
- if contain(rhs.children[i], tree_form("v_0")) or contain(rhs.children[i], tree_form("v_1")):
25
- success = True
26
- lhs = lhs / rhs.children[i]
27
- rhs.children.pop(i)
28
- if len(rhs.children) == 1:
29
- rhs = rhs.children[0]
30
- rhs, lhs = copy.deepcopy([simplify(lhs), simplify(rhs)])
31
- if rhs.name == "f_add":
32
- for i in range(len(rhs.children)-1,-1,-1):
33
- if not contain(rhs.children[i], tree_form("v_1")) or str_form(tree_form("v_0").fx("dif")) in [str_form(x) for x in factor_generation(rhs.children[i])]:
34
- if contain(rhs.children[i], tree_form("v_0")) or contain(rhs.children[i], tree_form("v_1")):
35
- success = True
36
- lhs = lhs - rhs.children[i]
37
- rhs.children.pop(i)
38
- elif rhs.name == "f_mul":
39
- for i in range(len(rhs.children)-1,-1,-1):
40
- if not contain(rhs.children[i], tree_form("v_1")):
41
- if contain(rhs.children[i], tree_form("v_0")) or contain(rhs.children[i], tree_form("v_1")):
42
- success = True
43
- lhs = lhs / rhs.children[i]
44
- rhs.children.pop(i)
45
- rhs, lhs = copy.deepcopy([simplify(lhs), simplify(rhs)])
46
- if not success:
47
- lhs, rhs = factor(lhs),factor(rhs)
48
- count -= 1
49
- if count == 0:
50
- return simplify(e0(lhs-rhs))
51
- return simplify(e0(lhs-rhs))
69
+ out = [[tree_form("d_0"), lhs-rhs], False]
70
+ while True:
71
+ out = list(kkk(out[0][0], out[0][1]))
72
+ if out[1]:
73
+ break
74
+ out[0] = [simplify(item) for item in out[0]]
75
+
76
+ out = out[0]
77
+ return simplify(e0(out[0]-out[1]))
52
78
 
53
79
  def allocvar():
54
80
  return tree_form("v_101")
@@ -110,13 +136,17 @@ def groupe(eq):
110
136
 
111
137
  def diffsolve_sep(eq):
112
138
  eq = epowersplit(eq)
113
-
114
139
  eq = inversediff(tree_form("d_0"), eq.children[0].copy_tree())
115
140
  return eq
116
141
 
117
142
  def diffsolve(eq):
118
143
  orig = eq.copy_tree()
119
-
144
+ if order(eq) == 2:
145
+ for i in range(2):
146
+ out = second_order_dif(eq, tree_form(f"v_{i}"), tree_form(f"v_{1-i}"))
147
+ if out is not None:
148
+ return out
149
+ return orig
120
150
 
121
151
  eq = diffsolve_sep2(diffsolve_sep(eq))
122
152
  if eq is None:
@@ -125,7 +155,8 @@ def diffsolve(eq):
125
155
  b = tree_form(f"v_{1-i}")
126
156
  c = tree_form("v_2")
127
157
  eq2 = replace(orig, b,b*a)
128
- eq2 = expand(simplify(fraction(simplify(diff(eq2, None)))))
158
+ eq2 = replace(eq2, (a*b).fx("dif"), a.fx("dif")*b + b.fx("dif")*a)
159
+ eq2 = expand(simplify(fraction(simplify(eq2))))
129
160
  eq2 = diffsolve_sep(eq2)
130
161
  eq2 = diffsolve_sep2(eq2)
131
162
  if eq2 is not None:
@@ -135,6 +166,7 @@ def diffsolve(eq):
135
166
  eq = fraction(eq)
136
167
  eq = simplify(eq)
137
168
  for i in range(2):
169
+
138
170
  out = linear_dif(eq, tree_form(f"v_{i}"), tree_form(f"v_{1-i}"))
139
171
  if out is not None:
140
172
  return out
@@ -145,23 +177,28 @@ def collect_term(eq, term_lst):
145
177
 
146
178
  lst = None
147
179
  if eq.name == "f_add":
148
- lst = eq.children
180
+ lst = copy.deepcopy(eq.children)
149
181
  else:
150
182
  lst = [eq]
151
183
 
152
184
  other = []
153
185
  dic = {}
154
- term_lst = sorted(term_lst, key=lambda x: -len(factor_generation(x)))
186
+ term_lst = list(sorted(term_lst, key=lambda x: -len(factor_generation(x))))
187
+ for item in term_lst:
188
+ dic[item] = tree_form("d_0")
155
189
  for item2 in lst:
156
190
  done = True
157
191
  tmp2 = Counter(factor_generation(item2))
158
192
  for index, item in enumerate(term_lst):
193
+
159
194
  tmp = Counter(factor_generation(item))
160
195
 
161
- if (tmp2&tmp) == tmp and clist((tmp2 - tmp)&tmp)==[]:
196
+ if (tmp2&tmp) == tmp:
162
197
  if item in dic.keys():
198
+
163
199
  dic[item] += product(clist(tmp2-tmp))
164
200
  else:
201
+
165
202
  dic[item] = product(clist(tmp2-tmp))
166
203
  done = False
167
204
  break
@@ -172,8 +209,48 @@ def collect_term(eq, term_lst):
172
209
  for key in dic.keys():
173
210
  dic[key] = simplify(dic[key])
174
211
  return [dic, simplify(other)]
212
+ def order(eq,m=0):
213
+ best = m
214
+ if eq.name in ["f_pdif", "f_dif"]:
215
+ out = order(eq.children[0], m+1)
216
+ best = max(out, best)
217
+ else:
218
+ for child in eq.children:
219
+ out = order(child, m)
220
+ best = max(out, best)
221
+ return best
222
+ def second_order_dif(eq, a, b):
223
+ eq = simplify(eq)
224
+ nn = [TreeNode("f_dif", [TreeNode("f_dif", [b,a]),a]), TreeNode("f_dif", [b,a]), b]
225
+ out = collect_term(eq.children[0], nn)
226
+ if out[1] == tree_form("d_0"):
227
+ tmp = out[0][nn[0]]
228
+ if tmp != tree_form("d_0"):
229
+ for key in out[0].keys():
230
+ out[0][key] = simplify(out[0][key]/tmp)
231
+
232
+ B = out[0][nn[1]]
233
+ C = out[0][nn[2]]
234
+
235
+ if all(all(not contain(item, item2) for item2 in [a,b]) for item in [B, C]):
236
+ r = parse("r")
237
+ s = simplify(factor2(simplify(TreeNode("f_eq", [r**2 + B*r + C, tree_form("d_0")])), True))
238
+ r1, r2 = [inverse(item, r.name) for item in s.children[0].children]
239
+ out = None
240
+ if contain(r1, tree_form("s_i")):
241
+ real = simplify(fraction((r1+r2)/tree_form("d_2")))
242
+ imagine = simplify((r1-real)/tree_form("s_i"))
243
+ out = tree_form("s_e")**(real*a)*(tree_form("v_101")*(imagine*a).fx("cos")+tree_form("v_102")*(imagine*a).fx("sin"))
244
+ elif fraction(simplify(r1-r2)) == tree_form("d_0"):
245
+ out =(tree_form("v_101")+tree_form("v_102")*a)*tree_form("s_e")**(r1*a)
246
+ else:
247
+ out = tree_form("v_101")*tree_form("s_e")**(r1*a) + tree_form("v_102")*tree_form("s_e")**(r2*a)
248
+ return TreeNode("f_eq", [b, out])
249
+ return None
250
+
175
251
  def linear_dif(eq, a, b):
176
252
  eq = simplify(eq)
253
+
177
254
  out = collect_term(eq.children[0], [b.fx("dif"), b*a.fx("dif"), a.fx("dif")])
178
255
 
179
256
  if out[1] == tree_form("d_0"):
mathai/parser.py CHANGED
@@ -60,7 +60,7 @@ grammar = """
60
60
  | ESCAPED_STRING -> string
61
61
  | CAPITAL_ID -> matrix
62
62
 
63
- FUNC_NAME: "midpoint" | "ref" | "expect" | "covariance" | "variance" | "subs" | "try" | "limit" | "forall" | "limitpinf" | "imply" | "exist" | "len" | "sum" | "angle" | "line" | "sum2" | "charge" | "electricfield" | "perm" | "point" | "equationrhs" | "transpose" | "equationlhs" | "equation" | "error" | "covariance" | "variance" | "expect" | "mag" | "rad" | "laplace" | "diverge" | "pdif" | "gradient" | "curl" | "point1" | "point2" | "dot" | "point3" | "line1" | "line2" | "line3" | "sin" | "circumcenter" | "eqtri" | "linesegment" | "cos" | "tan" | "log" | "sqrt" | "integrate" | "dif" | "abs" | "cosec" | "sec" | "cot" | "arctan" | "arcsin" | "arccos" | "log10"
63
+ FUNC_NAME: "midpoint" | "ref" | "expect" | "U" | "covariance" | "variance" | "subs" | "try" | "limit" | "forall" | "limitpinf" | "imply" | "exist" | "len" | "sum" | "angle" | "line" | "sum2" | "charge" | "electricfield" | "perm" | "point" | "equationrhs" | "transpose" | "equationlhs" | "equation" | "error" | "covariance" | "variance" | "expect" | "mag" | "rad" | "laplace" | "diverge" | "pdif" | "gradient" | "curl" | "point1" | "point2" | "dot" | "point3" | "line1" | "line2" | "line3" | "sin" | "circumcenter" | "eqtri" | "linesegment" | "cos" | "tan" | "log" | "sqrt" | "integrate" | "dif" | "abs" | "cosec" | "sec" | "cot" | "arctan" | "arcsin" | "arccos" | "log10"
64
64
 
65
65
  VARIABLE: /[a-z]/ | "nabla" | "pi" | "kc" | "hbar" | "em" | "ec" | "anot" | "false" | "true"
66
66
 
@@ -131,7 +131,7 @@ def parse(equation, funclist=None):
131
131
  if tree_node.name == "pass_through":
132
132
  return fxchange(tree_node.children[0])
133
133
  return TreeNode(
134
- "f_" + tree_node.name if tree_node.name in tmp3 + ["limitpinf", "limit", "try", "ref", "sqrt","imply","forall","exist","exclude","union","intersection","len","index","angle","charge","sum2","electricfield","line","point","sum","transpose","equationrhs","equationlhs","equation","covariance","variance","expect","error","laplace","dot","curl","pdif","diverge","gradient","rad","ge","le","gt","lt","eqtri","linesegment","midpoint","mag","point1","point2","point3","line1","line2","line3","log10","arcsin","arccos","arctan","list","cosec","sec","cot","equiv","or","not","and","circumcenter","eq","sub","add","sin","cos","tan","mul", "cross", "wmul","integrate","dif","pow","div","log","abs"] else "d_" + tree_node.name,
134
+ "f_" + tree_node.name if tree_node.name in tmp3 + ["U", "limitpinf", "limit", "try", "ref", "sqrt","imply","forall","exist","exclude","union","intersection","len","index","angle","charge","sum2","electricfield","line","point","sum","transpose","equationrhs","equationlhs","equation","covariance","variance","expect","error","laplace","dot","curl","pdif","diverge","gradient","rad","ge","le","gt","lt","eqtri","linesegment","midpoint","mag","point1","point2","point3","line1","line2","line3","log10","arcsin","arccos","arctan","list","cosec","sec","cot","equiv","or","not","and","circumcenter","eq","sub","add","sin","cos","tan","mul", "cross", "wmul","integrate","dif","pow","div","log","abs"] else "d_" + tree_node.name,
135
135
  [fxchange(child) for child in tree_node.children]
136
136
  )
137
137
 
@@ -155,5 +155,4 @@ def parse(equation, funclist=None):
155
155
  return tree_node
156
156
 
157
157
  tree_node = rfx(tree_node)
158
- tree_node = flatten_tree(tree_node)
159
158
  return tree_node
mathai/pde.py CHANGED
@@ -1,89 +1,28 @@
1
- from .ode import diffsolve
1
+ from .expand import expand
2
+ from .ode import diffsolve, inversediff, order, groupe, epowersplit
2
3
  from .base import *
3
4
  from .simplify import simplify
4
- from .diff import diff
5
+ from .diff import diff2
5
6
  from .fraction import fraction
6
7
  from .parser import parse
7
8
  from .inverse import inverse
9
+ from .factor import factor
10
+
8
11
  def capital2(eq):
9
- if eq.name == "f_pdif":
12
+ if eq.name == "f_pdif" and eq.children[0].name != "f_pdif":
10
13
  return eq.children[0]
11
14
  for child in eq.children:
12
15
  out = capital2(child)
13
16
  if out is not None:
14
17
  return out
15
18
  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")
19
+ def subs2(eq, orde):
21
20
  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])
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])
87
26
  def capital(eq):
88
27
  if eq.name[:2] == "f_" and eq.name != eq.name.lower():
89
28
  return eq
@@ -98,12 +37,14 @@ def abs_const(eq):
98
37
  return TreeNode(eq.name, [abs_const(child) for child in eq.children])
99
38
  def want(eq):
100
39
  if eq.name == "f_want":
40
+
101
41
  eq2 = eq.children[0]
102
42
  v = [tree_form(item) for item in vlist(eq.children[0])]
103
43
  lst = {}
104
44
  if eq.children[1].name == "f_and":
105
45
  for item in eq.children[1].children:
106
46
  item = abs_const(item)
47
+ item = groupe(item)
107
48
  for item2 in v:
108
49
  if contain(item, item2):
109
50
  out = inverse(item.children[0], str_form(item2))
@@ -113,26 +54,51 @@ def want(eq):
113
54
  for key in lst.keys():
114
55
  eq2 = replace(eq2, key, lst[key])
115
56
  if len(lst.keys()) == len(v):
116
- return simplify(eq2)
57
+ return fraction(groupe(simplify(eq2)))
117
58
  return TreeNode(eq.name, [want(child) for child in eq.children])
59
+ def absorb2(eq):
60
+ if "v_103" in vlist(eq):
61
+ v = vlist(eq)
62
+ v.remove("v_103")
63
+ if set(v)<set(["v_101", "v_102"]):
64
+ return tree_form("v_103")
65
+ if ["v_101"] == vlist(eq):
66
+ return tree_form("v_101")
67
+ if ["v_102"] == vlist(eq):
68
+ return tree_form("v_102")
69
+ if ["v_103"] == vlist(eq):
70
+ return tree_form("v_103")
71
+ return TreeNode(eq.name, [absorb2(child) for child in eq.children])
72
+ def absorb(eq):
73
+ return dowhile(epowersplit(eq), absorb2)
118
74
  def pde_sep(eq):
119
75
  if eq.name == "f_eq":
120
76
  eq = eq.children[0]
121
- r2 = capital2(eq)
77
+ r2 = parse("U(x,y)")
78
+ eq = replace(eq, r2, parse("x").fx("X") * parse("y").fx("Y"))
79
+
80
+ eq = fraction(simplify(fraction(TreeNode("f_eq", [diff2(eq), tree_form("d_0")]))))
81
+
82
+ out = inversediff(eq.children[0], tree_form("d_0"))
122
83
 
123
- eq = simplify(fraction(subs(eq, r2)))
124
- out = inverse_pde(eq,tree_form("d_0"))
125
84
  if out is not None:
126
- out = list(out)
85
+ out = list(out.children[0].children)
86
+ if contain(out[0], tree_form("v_1")):
87
+ out = out[::-1]
88
+ out[0] = simplify(-out[0])
89
+
127
90
  lst = []
128
91
  for i in range(2):
129
- out[i] = subs2(out[i])
130
- out[i] = TreeNode("f_eq", [out[i], tree_form("v_102")])
92
+
93
+ out[i] = TreeNode("f_eq", [out[i], tree_form("v_103")])
131
94
  out[i] = fraction(simplify(out[i]))
132
95
  r = capital(out[i])
133
96
  lst.append(r)
134
97
  out[i] = replace(out[i], r, tree_form(f"v_{1-i}"))
98
+ out[i] = subs2(out[i], order(out[i]))
99
+
135
100
  out[i] = diffsolve(out[i])
101
+
136
102
  out[i] = replace(out[i], tree_form(f"v_{1-i}"), r)
137
103
  out = TreeNode("f_eq", [r2, TreeNode("f_want", [product(lst), TreeNode("f_and", out)])])
138
104
  return replace(replace(out, lst[0], parse("a")), lst[1], parse("b"))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mathai
3
- Version: 0.7.7
3
+ Version: 0.7.8
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,22 +1,22 @@
1
- mathai/__init__.py,sha256=XkmMsqLr7MkYu1lMwwgsiEagtuOK_KsxLTbAHXgYSmo,1510
1
+ mathai/__init__.py,sha256=JdRPSes54qhzvi6f8Rni2sXljzzirrWZsaCmu9W9rws,1525
2
2
  mathai/apart.py,sha256=VSS3khE9PNuxiRvdU5JDl4IN-KJBSIFjwR17pkhviXI,4197
3
- mathai/base.py,sha256=LdIpxwqhqjL-O7GTfzyzCNN5_Zibp6dNZQVD42SwfIw,14862
3
+ mathai/base.py,sha256=zha7eOnfLjJuQcwi29rE0588U1R8v-0zulVPatr2aQo,14843
4
4
  mathai/bivariate_inequality.py,sha256=Da-A1kqVynR0tNOlEI7GSTf5T2vNkcF4etL9-EoyPJg,11415
5
5
  mathai/console.py,sha256=Sn58iwYE79MLEh67s8X3q6vZjw6g7f9XM1T8_dBBR2o,3048
6
- mathai/diff.py,sha256=3__PoEqs_JlS2fRkebXyL-7eyV69ZoV8vCjpYgDWcXE,3297
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
9
  mathai/fraction.py,sha256=3Qer3K20ZO2exMAYp1z80H69qRjVMfWKg5Ik0Ud8wf4,4402
10
- mathai/integrate.py,sha256=nUE2_ubklNIfj6QGtZTGuZmprYX-U3Ln454W-I1JddQ,17365
10
+ mathai/integrate.py,sha256=dA5AilUSOf4axVzi6KAF3OIaxmTetFjKt-5OpEaiYuo,17366
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=ABsGyA0TMfeHNG1kh_MsDcnmzkEnOHOzwNMw0QocyY0,7073
17
- mathai/parser.py,sha256=FcjOTM_2-YFqPNS9EyZfo76pa4CedDJCbcs8wOXc_uU,7130
16
+ mathai/ode.py,sha256=x6pAzml9pWZ-sr2k6JRfHTX1OJT82Tx7Yf-kTfAOe7E,9104
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=1EuVO2y9QAQK42fMbtmxvQyAV_7wsWH9zWLvH6ZDoZQ,4710
19
+ mathai/pde.py,sha256=JpPU73tGu1UH4ysLFeM1GaX-3ZdjykLu7CUdi1tfUTo,3814
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
@@ -24,7 +24,7 @@ mathai/structure.py,sha256=wrU7kqphSN7CqaVffyHHXD2-3t5My_Z_TtYFoUe_lTU,4099
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.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,,
27
+ mathai-0.7.8.dist-info/METADATA,sha256=13qi9377FQiULbVaonDa0-auk8pBon8jah_xZykHCP4,7735
28
+ mathai-0.7.8.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
29
+ mathai-0.7.8.dist-info/top_level.txt,sha256=ROP4l3OhGYw3ihkQGASr18xM9GsK4z3_6whV5AyXLwE,7
30
+ mathai-0.7.8.dist-info/RECORD,,
File without changes