mathai 0.2.0__tar.gz → 0.2.1__tar.gz

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.
Files changed (28) hide show
  1. {mathai-0.2.0 → mathai-0.2.1}/PKG-INFO +1 -1
  2. {mathai-0.2.0 → mathai-0.2.1}/mathai/__init__.py +1 -0
  3. {mathai-0.2.0 → mathai-0.2.1}/mathai/base.py +2 -0
  4. {mathai-0.2.0 → mathai-0.2.1}/mathai/expand.py +2 -0
  5. mathai-0.2.1/mathai/limit.py +126 -0
  6. {mathai-0.2.0 → mathai-0.2.1}/mathai/simplify.py +16 -2
  7. {mathai-0.2.0 → mathai-0.2.1}/mathai/structure.py +2 -1
  8. {mathai-0.2.0 → mathai-0.2.1}/mathai/trig.py +2 -0
  9. {mathai-0.2.0 → mathai-0.2.1}/mathai.egg-info/PKG-INFO +1 -1
  10. {mathai-0.2.0 → mathai-0.2.1}/mathai.egg-info/SOURCES.txt +1 -0
  11. {mathai-0.2.0 → mathai-0.2.1}/setup.py +1 -1
  12. {mathai-0.2.0 → mathai-0.2.1}/README.md +0 -0
  13. {mathai-0.2.0 → mathai-0.2.1}/mathai/apart.py +0 -0
  14. {mathai-0.2.0 → mathai-0.2.1}/mathai/console.py +0 -0
  15. {mathai-0.2.0 → mathai-0.2.1}/mathai/diff.py +0 -0
  16. {mathai-0.2.0 → mathai-0.2.1}/mathai/factor.py +0 -0
  17. {mathai-0.2.0 → mathai-0.2.1}/mathai/fraction.py +0 -0
  18. {mathai-0.2.0 → mathai-0.2.1}/mathai/integrate.py +0 -0
  19. {mathai-0.2.0 → mathai-0.2.1}/mathai/inverse.py +0 -0
  20. {mathai-0.2.0 → mathai-0.2.1}/mathai/linear.py +0 -0
  21. {mathai-0.2.0 → mathai-0.2.1}/mathai/logic.py +0 -0
  22. {mathai-0.2.0 → mathai-0.2.1}/mathai/parser.py +0 -0
  23. {mathai-0.2.0 → mathai-0.2.1}/mathai/printeq.py +0 -0
  24. {mathai-0.2.0 → mathai-0.2.1}/mathai/tool.py +0 -0
  25. {mathai-0.2.0 → mathai-0.2.1}/mathai.egg-info/dependency_links.txt +0 -0
  26. {mathai-0.2.0 → mathai-0.2.1}/mathai.egg-info/requires.txt +0 -0
  27. {mathai-0.2.0 → mathai-0.2.1}/mathai.egg-info/top_level.txt +0 -0
  28. {mathai-0.2.0 → mathai-0.2.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: mathai
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: Mathematics solving Ai tailored to NCERT
5
5
  Home-page: https://github.com/infinity390/mathai4
6
6
  Author: educated indians are having a low iq and are good for nothing
@@ -11,4 +11,5 @@ from .trig import trig0, trig1, trig2, trig3, trig4
11
11
  from .logic import logic0, logic1, logic2, logic3
12
12
  from .apart import apart
13
13
  from .console import console
14
+ from .limit import limit
14
15
  from .base import *
@@ -145,6 +145,8 @@ def frac(eq):
145
145
  a = frac(eq.children[0])
146
146
  b = frac(eq.children[1])
147
147
  if isinstance(a, Fraction) and isinstance(b, Fraction) and b.denominator==1:
148
+ if a == 0 and b <= 0:
149
+ return None
148
150
  return a**b
149
151
  else:
150
152
  return None
@@ -4,6 +4,8 @@ from .base import *
4
4
  from .simplify import solve, simplify
5
5
 
6
6
  def expand(eq):
7
+ if eq is None:
8
+ return None
7
9
  if eq.name == "f_mul" or eq.name == "f_pow":
8
10
  if eq.name == "f_pow":
9
11
  eq = TreeNode("f_pow", [eq])
@@ -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
@@ -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 = tree_form("d_0")
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)
@@ -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 = conversion(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):
@@ -32,6 +32,8 @@ for key in trig_cos_table.keys():
32
32
  for key in trig_sin_table.keys():
33
33
  trig_sin_table[key] = simplify(trig_sin_table[key])
34
34
  def trig0(eq):
35
+ if eq is None:
36
+ return None
35
37
  def isneg(eq):
36
38
  if eq.name[:2] != "d_":
37
39
  return False
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: mathai
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: Mathematics solving Ai tailored to NCERT
5
5
  Home-page: https://github.com/infinity390/mathai4
6
6
  Author: educated indians are having a low iq and are good for nothing
@@ -10,6 +10,7 @@ mathai/factor.py
10
10
  mathai/fraction.py
11
11
  mathai/integrate.py
12
12
  mathai/inverse.py
13
+ mathai/limit.py
13
14
  mathai/linear.py
14
15
  mathai/logic.py
15
16
  mathai/parser.py
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="mathai",
5
- version="0.2.0",
5
+ version="0.2.1",
6
6
  description="Mathematics solving Ai tailored to NCERT",
7
7
  long_description=open("README.md").read(),
8
8
  long_description_content_type="text/markdown",
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes