mathai 0.7.6__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,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, absorb
5
+
4
6
  from .linear import linear_solve, linear_or
5
7
 
6
8
  from .expand import expand
@@ -19,7 +21,7 @@ from .integrate import rm_const as integrate_const
19
21
  from .integrate import solve_integrate as integrate_clean
20
22
  from .integrate import integrate_formula
21
23
 
22
- from .diff import diff
24
+ from .diff import diff, diff2
23
25
 
24
26
  from .factor import factor as factor1
25
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:
@@ -403,7 +402,7 @@ def string_equation_helper(equation_tree):
403
402
  if equation_tree.name == "f_index":
404
403
  return string_equation_helper(equation_tree.children[0])+"["+",".join([string_equation_helper(child) for child in equation_tree.children[1:]])+"]"
405
404
  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"]:
405
+ 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
406
  s = equation_tree.name[2:] + s
408
407
  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
408
  arr = []
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,59 +1,83 @@
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 = 4
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
- intconst = ["v_"+str(i) for i in range(101,150)]
54
79
  def allocvar():
55
- global intconst
56
- return tree_form(intconst.pop(0))
80
+ return tree_form("v_101")
57
81
 
58
82
  def epowersplit(eq):
59
83
  if eq.name == "f_pow" and eq.children[1].name == "f_add":
@@ -112,13 +136,17 @@ def groupe(eq):
112
136
 
113
137
  def diffsolve_sep(eq):
114
138
  eq = epowersplit(eq)
115
-
116
139
  eq = inversediff(tree_form("d_0"), eq.children[0].copy_tree())
117
140
  return eq
118
141
 
119
142
  def diffsolve(eq):
120
143
  orig = eq.copy_tree()
121
-
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
122
150
 
123
151
  eq = diffsolve_sep2(diffsolve_sep(eq))
124
152
  if eq is None:
@@ -127,7 +155,8 @@ def diffsolve(eq):
127
155
  b = tree_form(f"v_{1-i}")
128
156
  c = tree_form("v_2")
129
157
  eq2 = replace(orig, b,b*a)
130
- 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))))
131
160
  eq2 = diffsolve_sep(eq2)
132
161
  eq2 = diffsolve_sep2(eq2)
133
162
  if eq2 is not None:
@@ -137,6 +166,7 @@ def diffsolve(eq):
137
166
  eq = fraction(eq)
138
167
  eq = simplify(eq)
139
168
  for i in range(2):
169
+
140
170
  out = linear_dif(eq, tree_form(f"v_{i}"), tree_form(f"v_{1-i}"))
141
171
  if out is not None:
142
172
  return out
@@ -147,23 +177,28 @@ def collect_term(eq, term_lst):
147
177
 
148
178
  lst = None
149
179
  if eq.name == "f_add":
150
- lst = eq.children
180
+ lst = copy.deepcopy(eq.children)
151
181
  else:
152
182
  lst = [eq]
153
183
 
154
184
  other = []
155
185
  dic = {}
156
- 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")
157
189
  for item2 in lst:
158
190
  done = True
159
191
  tmp2 = Counter(factor_generation(item2))
160
192
  for index, item in enumerate(term_lst):
193
+
161
194
  tmp = Counter(factor_generation(item))
162
195
 
163
- if (tmp2&tmp) == tmp and clist((tmp2 - tmp)&tmp)==[]:
196
+ if (tmp2&tmp) == tmp:
164
197
  if item in dic.keys():
198
+
165
199
  dic[item] += product(clist(tmp2-tmp))
166
200
  else:
201
+
167
202
  dic[item] = product(clist(tmp2-tmp))
168
203
  done = False
169
204
  break
@@ -174,8 +209,48 @@ def collect_term(eq, term_lst):
174
209
  for key in dic.keys():
175
210
  dic[key] = simplify(dic[key])
176
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
+
177
251
  def linear_dif(eq, a, b):
178
252
  eq = simplify(eq)
253
+
179
254
  out = collect_term(eq.children[0], [b.fx("dif"), b*a.fx("dif"), a.fx("dif")])
180
255
 
181
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 ADDED
@@ -0,0 +1,105 @@
1
+ from .expand import expand
2
+ from .ode import diffsolve, inversediff, order, groupe, epowersplit
3
+ from .base import *
4
+ from .simplify import simplify
5
+ from .diff import diff2
6
+ from .fraction import fraction
7
+ from .parser import parse
8
+ from .inverse import inverse
9
+ from .factor import factor
10
+
11
+ def capital2(eq):
12
+ if eq.name == "f_pdif" and eq.children[0].name != "f_pdif":
13
+ return eq.children[0]
14
+ for child in eq.children:
15
+ out = capital2(child)
16
+ if out is not None:
17
+ return out
18
+ return None
19
+ def subs2(eq, orde):
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])
26
+ def capital(eq):
27
+ if eq.name[:2] == "f_" and eq.name != eq.name.lower():
28
+ return eq
29
+ for child in eq.children:
30
+ out = capital(child)
31
+ if out is not None:
32
+ return out
33
+ return None
34
+ def abs_const(eq):
35
+ if eq.name == "f_abs":
36
+ return tree_form("v_101")*eq.children[0]
37
+ return TreeNode(eq.name, [abs_const(child) for child in eq.children])
38
+ def want(eq):
39
+ if eq.name == "f_want":
40
+
41
+ eq2 = eq.children[0]
42
+ v = [tree_form(item) for item in vlist(eq.children[0])]
43
+ lst = {}
44
+ if eq.children[1].name == "f_and":
45
+ for item in eq.children[1].children:
46
+ item = abs_const(item)
47
+ item = groupe(item)
48
+ for item2 in v:
49
+ if contain(item, item2):
50
+ out = inverse(item.children[0], str_form(item2))
51
+ if out is not None:
52
+ lst[item2] = out
53
+ break
54
+ for key in lst.keys():
55
+ eq2 = replace(eq2, key, lst[key])
56
+ if len(lst.keys()) == len(v):
57
+ return fraction(groupe(simplify(eq2)))
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)
74
+ def pde_sep(eq):
75
+ if eq.name == "f_eq":
76
+ eq = eq.children[0]
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"))
83
+
84
+ if out is not None:
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
+
90
+ lst = []
91
+ for i in range(2):
92
+
93
+ out[i] = TreeNode("f_eq", [out[i], tree_form("v_103")])
94
+ out[i] = fraction(simplify(out[i]))
95
+ r = capital(out[i])
96
+ lst.append(r)
97
+ out[i] = replace(out[i], r, tree_form(f"v_{1-i}"))
98
+ out[i] = subs2(out[i], order(out[i]))
99
+
100
+ out[i] = diffsolve(out[i])
101
+
102
+ out[i] = replace(out[i], tree_form(f"v_{1-i}"), r)
103
+ out = TreeNode("f_eq", [r2, TreeNode("f_want", [product(lst), TreeNode("f_and", out)])])
104
+ return replace(replace(out, lst[0], parse("a")), lst[1], parse("b"))
105
+ return out
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mathai
3
- Version: 0.7.6
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,21 +1,22 @@
1
- mathai/__init__.py,sha256=uSG7914Pp9wW9801C38J76gWD3MIoJa5hbJyVEpXfgg,1476
1
+ mathai/__init__.py,sha256=JdRPSes54qhzvi6f8Rni2sXljzzirrWZsaCmu9W9rws,1525
2
2
  mathai/apart.py,sha256=VSS3khE9PNuxiRvdU5JDl4IN-KJBSIFjwR17pkhviXI,4197
3
- mathai/base.py,sha256=XNmXWADG7mA4AeyFbCUsjBvUzDnw8AzWscX0Cc3GjvA,14854
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=vQmCedrfC8-Z0nTSogDYyFu7ASk9pu0E2iYLsfw0zvw,7152
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=JpPU73tGu1UH4ysLFeM1GaX-3ZdjykLu7CUdi1tfUTo,3814
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.6.dist-info/METADATA,sha256=CtT2xE0HxPzOuwYgjgbr-jU-idsfJC8Zh8azf53h3eA,7735
27
- mathai-0.7.6.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
28
- mathai-0.7.6.dist-info/top_level.txt,sha256=ROP4l3OhGYw3ihkQGASr18xM9GsK4z3_6whV5AyXLwE,7
29
- mathai-0.7.6.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