mathai 0.7.4__py3-none-any.whl → 0.7.6__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
@@ -11,14 +11,12 @@ from .printeq import printeq, printeq_str
11
11
 
12
12
  from .simplify import simplify
13
13
 
14
- from .integrate import ref as integrate_save
15
14
  from .integrate import integrate_subs_main as integrate_subs
16
15
  from .integrate import byparts as integrate_byparts
17
16
  from .integrate import sqint as integrate_fraction
18
17
  from .integrate import integrate_summation
19
18
  from .integrate import rm_const as integrate_const
20
19
  from .integrate import solve_integrate as integrate_clean
21
- from .integrate import inteq as integrate_recursive
22
20
  from .integrate import integrate_formula
23
21
 
24
22
  from .diff import diff
mathai/diff.py CHANGED
@@ -63,6 +63,12 @@ def diff(equation, var="v_0"):
63
63
  else:
64
64
  return equation
65
65
  return TreeNode(equation.name, [helper(child, var) for child in equation.children])
66
+ def calc(eq):
67
+ if eq.name == "f_dif":
68
+ return diffeq(trig0(eq.children[0]))
69
+ return TreeNode(eq.name, [calc(child) for child in eq.children])
70
+ if var is None:
71
+ return simplify(calc(equation))
66
72
  equation = diffeq(trig0(equation))
67
73
  equation = helper(equation, var)
68
74
  return simplify(equation)
mathai/expand.py CHANGED
@@ -70,6 +70,9 @@ def expand_nc(expr, label="f_mul"):
70
70
  return TreeNode(label, factors)
71
71
 
72
72
 
73
- def expand(eq, over="*"):
73
+ def expand2(eq, over="*"):
74
74
  over = {"@": "f_wmul", ".":"f_dot", "*":"f_mul"}[over]
75
75
  return expand_nc(eq, over)
76
+ def expand(eq, over="*"):
77
+ eq = expand2(eq, over)
78
+ return TreeNode(eq.name, [expand(child, over) for child in eq.children])
mathai/factor.py CHANGED
@@ -134,6 +134,11 @@ def merge_sqrt(eq):
134
134
  n = int(eq.children[0].name[2:])
135
135
  a, b =sqrt_to_a_sqrt_b(n)
136
136
  return tree_form("d_"+str(b))**(tree_form("d_2")**-1)*tree_form("d_"+str(a))
137
+ if eq.name == "f_pow" and frac(eq.children[1]) == Fraction(-1,2):
138
+ if frac(eq.children[0]) is not None:
139
+ out = frac(eq.children[0])
140
+ b, a = [tree_form("d_"+str(x)) for x in [out.numerator, out.denominator]]
141
+ return a**(tree_form("d_2")**-1)/b**(tree_form("d_2")**-1)
137
142
  return TreeNode(eq.name, [helper(child) for child in eq.children])
138
143
  return helper(_merge_sqrt(eq))
139
144
  def rationalize_sqrt(eq):
mathai/fraction.py CHANGED
@@ -92,7 +92,7 @@ def fraction(eq):
92
92
  c = TreeNode("f_mul", c_children)
93
93
  c = TreeNode("f_pow", [c, tree_form("d_-1")])
94
94
 
95
- result_map[node] = TreeNode("f_mul", [simplify(expand(a)), c])
95
+ result_map[node] = TreeNode("f_mul", [simplify(expand(simplify(a))), c])
96
96
  continue
97
97
 
98
98
  # Default: just reconstruct node
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
- expr_str = str_form(shorten(integrand))
453
- if len(expr_str) < 30:
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,5 @@
1
+ from collections import Counter
2
+ from .diff import diff
1
3
  from .factor import factor
2
4
  from .expand import expand
3
5
  from .base import *
@@ -118,7 +120,72 @@ def diffsolve(eq):
118
120
  orig = eq.copy_tree()
119
121
 
120
122
 
121
- eq = diffsolve_sep2(eq)
123
+ eq = diffsolve_sep2(diffsolve_sep(eq))
122
124
  if eq is None:
123
- return orig
125
+ for i in range(2):
126
+ a = tree_form(f"v_{i}")
127
+ b = tree_form(f"v_{1-i}")
128
+ c = tree_form("v_2")
129
+ eq2 = replace(orig, b,b*a)
130
+ eq2 = expand(simplify(fraction(simplify(diff(eq2, None)))))
131
+ eq2 = diffsolve_sep(eq2)
132
+ eq2 = diffsolve_sep2(eq2)
133
+ if eq2 is not None:
134
+ return e0(TreeNode("f_subs", [replace(eq2.children[0],b,c), c,b/a]).fx("try"))
135
+ eq = orig
136
+
137
+ eq = fraction(eq)
138
+ eq = simplify(eq)
139
+ for i in range(2):
140
+ out = linear_dif(eq, tree_form(f"v_{i}"), tree_form(f"v_{1-i}"))
141
+ if out is not None:
142
+ return out
124
143
  return eq
144
+ def clist(x):
145
+ return list(x.elements())
146
+ def collect_term(eq, term_lst):
147
+
148
+ lst = None
149
+ if eq.name == "f_add":
150
+ lst = eq.children
151
+ else:
152
+ lst = [eq]
153
+
154
+ other = []
155
+ dic = {}
156
+ term_lst = sorted(term_lst, key=lambda x: -len(factor_generation(x)))
157
+ for item2 in lst:
158
+ done = True
159
+ tmp2 = Counter(factor_generation(item2))
160
+ for index, item in enumerate(term_lst):
161
+ tmp = Counter(factor_generation(item))
162
+
163
+ if (tmp2&tmp) == tmp and clist((tmp2 - tmp)&tmp)==[]:
164
+ if item in dic.keys():
165
+ dic[item] += product(clist(tmp2-tmp))
166
+ else:
167
+ dic[item] = product(clist(tmp2-tmp))
168
+ done = False
169
+ break
170
+ if done:
171
+ other.append(item2)
172
+ other = summation(other)
173
+
174
+ for key in dic.keys():
175
+ dic[key] = simplify(dic[key])
176
+ return [dic, simplify(other)]
177
+ def linear_dif(eq, a, b):
178
+ eq = simplify(eq)
179
+ out = collect_term(eq.children[0], [b.fx("dif"), b*a.fx("dif"), a.fx("dif")])
180
+
181
+ if out[1] == tree_form("d_0"):
182
+ tmp = out[0][b.fx("dif")]
183
+ if tmp != tree_form("d_0"):
184
+
185
+ for key in out[0].keys():
186
+ out[0][key] = simplify(out[0][key]/tmp)
187
+ p, q = out[0][b*a.fx("dif")], -out[0][a.fx("dif")]
188
+
189
+ f = tree_form("s_e") ** TreeNode("f_integrate", [p, a])
190
+ return simplify(TreeNode("f_eq", [b*f, TreeNode("f_integrate", [q*f, a])+allocvar()]))
191
+ return None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mathai
3
- Version: 0.7.4
3
+ Version: 0.7.6
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,19 +1,19 @@
1
- mathai/__init__.py,sha256=elVGU1vjxbvzY3CQ8M5kzj5i6o8YyCsdb2vw-kSxTN0,1575
1
+ mathai/__init__.py,sha256=uSG7914Pp9wW9801C38J76gWD3MIoJa5hbJyVEpXfgg,1476
2
2
  mathai/apart.py,sha256=VSS3khE9PNuxiRvdU5JDl4IN-KJBSIFjwR17pkhviXI,4197
3
3
  mathai/base.py,sha256=XNmXWADG7mA4AeyFbCUsjBvUzDnw8AzWscX0Cc3GjvA,14854
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=RSTwlfeddvYXUDShCeRdcPjsmAS8Vf5OkYJAaUBPaiM,3060
7
- mathai/expand.py,sha256=-nMd-TM4m5eIu61yW7YeaH_QCIPUdOqmtUfa9E7Fy94,2448
8
- mathai/factor.py,sha256=3wcmZOGUqMlLj4v2DA14ZLqEQ7khavOi7PjZJU6VX40,12494
9
- mathai/fraction.py,sha256=88xvRpDGfFi8tbe1QIyejdSP91HcErrN4VS2MxzbhrY,4392
10
- mathai/integrate.py,sha256=C_lqYgQN4UiriCb_LDkpwtKx7XJhp_K8T9skCkxWqas,17208
6
+ mathai/diff.py,sha256=3__PoEqs_JlS2fRkebXyL-7eyV69ZoV8vCjpYgDWcXE,3297
7
+ mathai/expand.py,sha256=IuzMX6emCT480VE27aCtR0eWU-rJ2VElvRLVa2xcRw0,2582
8
+ mathai/factor.py,sha256=mz_UlPuAqwvsextLB0FM5KWIuuDiMMKG51bXrofqzw8,12830
9
+ mathai/fraction.py,sha256=3Qer3K20ZO2exMAYp1z80H69qRjVMfWKg5Ik0Ud8wf4,4402
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=zxxTXAOpt7oSsfpgI4vHsCWKXevmM96ZOBZWWs-vj8Y,4801
16
+ mathai/ode.py,sha256=vQmCedrfC8-Z0nTSogDYyFu7ASk9pu0E2iYLsfw0zvw,7152
17
17
  mathai/parser.py,sha256=FcjOTM_2-YFqPNS9EyZfo76pa4CedDJCbcs8wOXc_uU,7130
18
18
  mathai/parsetab.py,sha256=TL-4jvRM_Tx6ipwet8CFJc2DkjR4tGsbrGF_r4IC8xI,9651
19
19
  mathai/printeq.py,sha256=4UgLJo-vV_YlVw_3QUQY_jQMHrFnG-ZKAyVZsd7yD6o,1450
@@ -23,7 +23,7 @@ mathai/structure.py,sha256=wrU7kqphSN7CqaVffyHHXD2-3t5My_Z_TtYFoUe_lTU,4099
23
23
  mathai/tool.py,sha256=ozcXTXLbKUnyPM9r9kz9M43YA2CBcWezcqLZfEs8rpc,6051
24
24
  mathai/trig.py,sha256=fnBbfiopcQzFg4ya1BoO5M0X_aCBnse2bjnKh1juw4I,11223
25
25
  mathai/univariate_inequality.py,sha256=LPFdWgC1y5zBwnsy1wwZxj-yP_SbqFDhCmTTzhuwoiY,16469
26
- mathai-0.7.4.dist-info/METADATA,sha256=KrAeV2SCsA8woWqHAHlIHTrkXpGNXiAYG3Q9qMQ6q_Y,7735
27
- mathai-0.7.4.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
28
- mathai-0.7.4.dist-info/top_level.txt,sha256=ROP4l3OhGYw3ihkQGASr18xM9GsK4z3_6whV5AyXLwE,7
29
- mathai-0.7.4.dist-info/RECORD,,
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,,
File without changes