mathai 0.7.6__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 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
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/ode.py CHANGED
@@ -8,7 +8,7 @@ from .simplify import simplify
8
8
  import copy
9
9
 
10
10
  def inversediff(lhs, rhs):
11
- count = 4
11
+ count = 5
12
12
  while contain(rhs, tree_form("v_1")) or contain(lhs, tree_form("v_0")):
13
13
  success = False
14
14
  if rhs.name == "f_add":
@@ -50,10 +50,8 @@ def inversediff(lhs, rhs):
50
50
  return simplify(e0(lhs-rhs))
51
51
  return simplify(e0(lhs-rhs))
52
52
 
53
- intconst = ["v_"+str(i) for i in range(101,150)]
54
53
  def allocvar():
55
- global intconst
56
- return tree_form(intconst.pop(0))
54
+ return tree_form("v_101")
57
55
 
58
56
  def epowersplit(eq):
59
57
  if eq.name == "f_pow" and eq.children[1].name == "f_add":
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,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mathai
3
- Version: 0.7.6
3
+ Version: 0.7.7
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,6 +1,6 @@
1
- mathai/__init__.py,sha256=uSG7914Pp9wW9801C38J76gWD3MIoJa5hbJyVEpXfgg,1476
1
+ mathai/__init__.py,sha256=XkmMsqLr7MkYu1lMwwgsiEagtuOK_KsxLTbAHXgYSmo,1510
2
2
  mathai/apart.py,sha256=VSS3khE9PNuxiRvdU5JDl4IN-KJBSIFjwR17pkhviXI,4197
3
- mathai/base.py,sha256=XNmXWADG7mA4AeyFbCUsjBvUzDnw8AzWscX0Cc3GjvA,14854
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
@@ -13,9 +13,10 @@ 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
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.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.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