mathai 0.6.9__py3-none-any.whl → 0.7.1__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/base.py +5 -3
- mathai/expand.py +80 -0
- mathai/matrix.py +1 -1
- mathai/parser.py +1 -1
- mathai-0.7.1.dist-info/METADATA +239 -0
- {mathai-0.6.9.dist-info → mathai-0.7.1.dist-info}/RECORD +8 -8
- {mathai-0.6.9.dist-info → mathai-0.7.1.dist-info}/WHEEL +1 -1
- mathai-0.6.9.dist-info/METADATA +0 -234
- {mathai-0.6.9.dist-info → mathai-0.7.1.dist-info}/top_level.txt +0 -0
mathai/base.py
CHANGED
|
@@ -370,21 +370,23 @@ def product(lst):
|
|
|
370
370
|
for item in lst[1:]:
|
|
371
371
|
s *= item
|
|
372
372
|
return s
|
|
373
|
-
def flatten_tree(node
|
|
373
|
+
def flatten_tree(node):
|
|
374
|
+
if node is None:
|
|
375
|
+
return None
|
|
374
376
|
if not node.children:
|
|
375
377
|
return node
|
|
376
378
|
ad = []
|
|
377
379
|
if node.name in ["f_add", "f_mul", "f_and", "f_or", "f_wmul"]:
|
|
378
380
|
merged_children = []
|
|
379
381
|
for child in node.children:
|
|
380
|
-
flattened_child = flatten_tree(child
|
|
382
|
+
flattened_child = flatten_tree(child)
|
|
381
383
|
if flattened_child.name == node.name:
|
|
382
384
|
merged_children.extend(flattened_child.children)
|
|
383
385
|
else:
|
|
384
386
|
merged_children.append(flattened_child)
|
|
385
387
|
return TreeNode(node.name, merged_children)
|
|
386
388
|
else:
|
|
387
|
-
node.children = [flatten_tree(child
|
|
389
|
+
node.children = [flatten_tree(child) for child in node.children]
|
|
388
390
|
return node
|
|
389
391
|
def dowhile(eq, fx):
|
|
390
392
|
if eq is None:
|
mathai/expand.py
CHANGED
|
@@ -72,6 +72,84 @@ def expand_once(node):
|
|
|
72
72
|
|
|
73
73
|
return node, False
|
|
74
74
|
|
|
75
|
+
def _expand2(equation):
|
|
76
|
+
"""Iterative version of _expand without recursion."""
|
|
77
|
+
# Stack: (node, child_index, partially_processed_children)
|
|
78
|
+
stack = [(equation, 0, [])]
|
|
79
|
+
|
|
80
|
+
while stack:
|
|
81
|
+
node, child_index, processed_children = stack.pop()
|
|
82
|
+
|
|
83
|
+
# If all children are processed
|
|
84
|
+
if child_index >= len(node.children):
|
|
85
|
+
# Replace children with processed versions
|
|
86
|
+
node.children = processed_children
|
|
87
|
+
|
|
88
|
+
# === Handle f_pow ===
|
|
89
|
+
if node.name == "f_pow":
|
|
90
|
+
n = frac(node.children[1])
|
|
91
|
+
if n is not None and n.denominator == 1 and n.numerator > 1:
|
|
92
|
+
# Convert power to repeated multiplication
|
|
93
|
+
power_children = [node.children[0] for _ in range(n.numerator)]
|
|
94
|
+
new_node = TreeNode("f_mul", power_children)
|
|
95
|
+
# Flatten tree
|
|
96
|
+
node = flatten_tree(new_node)
|
|
97
|
+
# Push it back for further processing
|
|
98
|
+
stack.append((node, 0, []))
|
|
99
|
+
continue
|
|
100
|
+
|
|
101
|
+
# === Handle f_mul ===
|
|
102
|
+
elif node.name == "f_mul":
|
|
103
|
+
# Separate lone children and bracket children
|
|
104
|
+
lone_children = tree_form("d_1")
|
|
105
|
+
bracket_children = []
|
|
106
|
+
|
|
107
|
+
# Iterate in reverse (like original)
|
|
108
|
+
for child in reversed(node.children):
|
|
109
|
+
if child.name == "f_add":
|
|
110
|
+
bracket_children.append(child)
|
|
111
|
+
elif child.name == "f_pow" and child.children[0].name == "f_add":
|
|
112
|
+
n = frac(child.children[1])
|
|
113
|
+
if n is not None and n.denominator == 1 and n.numerator > 1:
|
|
114
|
+
for _ in range(n.numerator):
|
|
115
|
+
bracket_children.append(child.children[0])
|
|
116
|
+
else:
|
|
117
|
+
lone_children = lone_children * child
|
|
118
|
+
else:
|
|
119
|
+
lone_children = lone_children * child
|
|
120
|
+
|
|
121
|
+
lone_children = simplify(lone_children)
|
|
122
|
+
|
|
123
|
+
# Distribute bracket children over lone children iteratively
|
|
124
|
+
while bracket_children:
|
|
125
|
+
tmp = tree_form("d_0")
|
|
126
|
+
bracket = bracket_children.pop(0)
|
|
127
|
+
for bc in bracket.children:
|
|
128
|
+
if lone_children.name == "f_add":
|
|
129
|
+
for lc in lone_children.children:
|
|
130
|
+
tmp = tmp + bc * lc
|
|
131
|
+
else:
|
|
132
|
+
tmp = tmp + bc * lone_children
|
|
133
|
+
# Simplify after each distribution
|
|
134
|
+
lone_children = flatten_tree(simplify(tmp))
|
|
135
|
+
|
|
136
|
+
node = lone_children
|
|
137
|
+
|
|
138
|
+
# === Return node to parent ===
|
|
139
|
+
if stack:
|
|
140
|
+
parent, idx, parent_children = stack.pop()
|
|
141
|
+
parent_children.append(node)
|
|
142
|
+
stack.append((parent, idx + 1, parent_children))
|
|
143
|
+
else:
|
|
144
|
+
# Root node fully expanded
|
|
145
|
+
return node
|
|
146
|
+
|
|
147
|
+
else:
|
|
148
|
+
# Push current node back for next child
|
|
149
|
+
stack.append((node, child_index, processed_children))
|
|
150
|
+
# Push the child to process next
|
|
151
|
+
child = flatten_tree(node.children[child_index])
|
|
152
|
+
stack.append((child, 0, []))
|
|
75
153
|
|
|
76
154
|
# =====================================================
|
|
77
155
|
# Phase 3: Global fixed-point driver
|
|
@@ -79,6 +157,8 @@ def expand_once(node):
|
|
|
79
157
|
|
|
80
158
|
def expand(eq):
|
|
81
159
|
orig = TreeNode.matmul
|
|
160
|
+
if TreeNode.matmul is None:
|
|
161
|
+
return _expand2(eq)
|
|
82
162
|
eq = simplify(eq)
|
|
83
163
|
if TreeNode.matmul is not None:
|
|
84
164
|
TreeNode.matmul = True
|
mathai/matrix.py
CHANGED
mathai/parser.py
CHANGED
|
@@ -154,7 +154,7 @@ def parse(equation, funclist=None):
|
|
|
154
154
|
return tree_node
|
|
155
155
|
|
|
156
156
|
tree_node = rfx(tree_node)
|
|
157
|
-
tree_node = flatten_tree(tree_node
|
|
157
|
+
tree_node = flatten_tree(tree_node)
|
|
158
158
|
if TreeNode.matmul == True:
|
|
159
159
|
TreeNode.matmul = False
|
|
160
160
|
tree_node = use(tree_form(str_form(tree_node).replace("f_w","f_")))
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mathai
|
|
3
|
+
Version: 0.7.1
|
|
4
|
+
Summary: Mathematics solving Ai tailored to NCERT
|
|
5
|
+
Home-page: https://github.com/infinity390/mathai4
|
|
6
|
+
Author: educated indians are having a low iq and are good for nothing
|
|
7
|
+
Requires-Python: >=3.7
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
Requires-Dist: lark-parser
|
|
10
|
+
Dynamic: author
|
|
11
|
+
Dynamic: description
|
|
12
|
+
Dynamic: description-content-type
|
|
13
|
+
Dynamic: home-page
|
|
14
|
+
Dynamic: requires-dist
|
|
15
|
+
Dynamic: requires-python
|
|
16
|
+
Dynamic: summary
|
|
17
|
+
|
|
18
|
+
# Math AI Documentation
|
|
19
|
+
## Source
|
|
20
|
+
Github repository of the code
|
|
21
|
+
https://github.com/infinity390/mathai4
|
|
22
|
+
|
|
23
|
+
## Philosophy
|
|
24
|
+
I think it is a big realization in computer science and programming to realize that computers can solve mathematics.
|
|
25
|
+
This understanding should be made mainstream. It can help transform education, mathematical research, and computation of mathematical equations for work.
|
|
26
|
+
|
|
27
|
+
## Societal Implications Of Such A Computer Program And The Author's Comment On Universities Of India
|
|
28
|
+
I think mathematics is valued by society because of education. Schools and universities teach them.
|
|
29
|
+
So this kind of software, if made mainstream, could bring real change.
|
|
30
|
+
|
|
31
|
+
## The Summary Of How Computer "Solves" Math
|
|
32
|
+
Math equations are a tree data structure (`TreeNode` class).
|
|
33
|
+
We can manipulate the math equations using various algorithms (functions provided by the `mathai` library).
|
|
34
|
+
We first parse the math equation strings to get the tree data structure (`parse` function in `mathai`).
|
|
35
|
+
|
|
36
|
+
## The Library
|
|
37
|
+
Import the library by doing:
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
from mathai import *
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### str_form
|
|
44
|
+
It is the string representation of a `TreeNode` math equation.
|
|
45
|
+
|
|
46
|
+
#### Example
|
|
47
|
+
```text
|
|
48
|
+
(cos(x)^2)+(sin(x)^2)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Is represented internally as:
|
|
52
|
+
|
|
53
|
+
```text
|
|
54
|
+
f_add
|
|
55
|
+
f_pow
|
|
56
|
+
f_cos
|
|
57
|
+
v_0
|
|
58
|
+
d_2
|
|
59
|
+
f_pow
|
|
60
|
+
f_sin
|
|
61
|
+
v_0
|
|
62
|
+
d_2
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
#### Leaf Nodes
|
|
66
|
+
|
|
67
|
+
**Variables** (start with a `v_` prefix):
|
|
68
|
+
|
|
69
|
+
- `v_0` -> x
|
|
70
|
+
- `v_1` -> y
|
|
71
|
+
- `v_2` -> z
|
|
72
|
+
- `v_3` -> a
|
|
73
|
+
|
|
74
|
+
**Numbers** (start with `d_` prefix; only integers):
|
|
75
|
+
|
|
76
|
+
- `d_-1` -> -1
|
|
77
|
+
- `d_0` -> 0
|
|
78
|
+
- `d_1` -> 1
|
|
79
|
+
- `d_2` -> 2
|
|
80
|
+
|
|
81
|
+
#### Branch Nodes
|
|
82
|
+
- `f_add` -> addition
|
|
83
|
+
- `f_mul` -> multiplication
|
|
84
|
+
- `f_pow` -> power
|
|
85
|
+
|
|
86
|
+
### parse
|
|
87
|
+
Takes a math equation string and outputs a `TreeNode` object.
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
from mathai import *
|
|
91
|
+
|
|
92
|
+
equation = parse("sin(x)^2+cos(x)^2")
|
|
93
|
+
print(equation)
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
#### Output
|
|
97
|
+
```text
|
|
98
|
+
(cos(x)^2)+(sin(x)^2)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### solve, simplify
|
|
102
|
+
It simplifies and cleans up a given math equation.
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
from mathai import *
|
|
106
|
+
|
|
107
|
+
equation = simplify(parse("(x+x+x+x-1-1-1-1)*(4*x-4)*sin(sin(x+x+x)*sin(3*x))"))
|
|
108
|
+
printeq(equation)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
#### Output
|
|
112
|
+
```text
|
|
113
|
+
((-4+(4*x))^2)*sin((sin((3*x))^2))
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Incomplete Documentation, Will be updated and completed later on
|
|
117
|
+
|
|
118
|
+
### Demonstrations
|
|
119
|
+
|
|
120
|
+
#### Example Demonstration 1
|
|
121
|
+
```python
|
|
122
|
+
from mathai import *
|
|
123
|
+
question_list_from_lecture = [
|
|
124
|
+
"2*x/(2*x^2 + 5*x + 2) > 1/(x + 1)",
|
|
125
|
+
"(x + 2)*(x + 3)/((x - 2)*(x - 3)) <= 1",
|
|
126
|
+
"(5*x - 1) < (x + 1)^2 & (x + 1)^2 < 7*x - 3",
|
|
127
|
+
"(2*x - 1)/(2*x^3 + 3*x^2 + x) > 0",
|
|
128
|
+
"abs(x + 5)*x + 2*abs(x + 7) - 2 = 0",
|
|
129
|
+
"x*abs(x) - 5*abs(x + 2) + 6 = 0",
|
|
130
|
+
"x^2 - abs(x + 2) + x > 0",
|
|
131
|
+
"abs(abs(x - 2) - 3) <= 2",
|
|
132
|
+
"abs(3*x - 5) + abs(8 - x) = abs(3 + 2*x)",
|
|
133
|
+
"abs(x^2 + 5*x + 9) < abs(x^2 + 2*x + 2) + abs(3*x + 7)"
|
|
134
|
+
]
|
|
135
|
+
|
|
136
|
+
for item in question_list_from_lecture:
|
|
137
|
+
eq = simplify(parse(item))
|
|
138
|
+
eq = dowhile(eq, absolute)
|
|
139
|
+
eq = simplify(factor1(fraction(eq)))
|
|
140
|
+
eq = prepare(eq)
|
|
141
|
+
eq = factor2(eq)
|
|
142
|
+
c = wavycurvy(eq & domain(eq)).fix()
|
|
143
|
+
print(c)
|
|
144
|
+
```
|
|
145
|
+
#### Output
|
|
146
|
+
|
|
147
|
+
```
|
|
148
|
+
(-2,-1)U(-(2/3),-(1/2))
|
|
149
|
+
(-inf,0)U(2,3)U{0}
|
|
150
|
+
(2,4)
|
|
151
|
+
(-inf,-1)U(-(1/2),0)U(1/2,+inf)
|
|
152
|
+
{-4,-3,-(3/2)-(sqrt(57)/2)}
|
|
153
|
+
{-1,(5/2)-(sqrt(89)/2),(5/2)+(sqrt(41)/2)}
|
|
154
|
+
(-inf,-sqrt(2))U((2*sqrt(2))/2,+inf)
|
|
155
|
+
(-3,1)U(3,7)U{1,-3,7,3}
|
|
156
|
+
(5/3,8)U{5/3,8}
|
|
157
|
+
(-inf,-(7/3))
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
#### Example Demonstration 2
|
|
161
|
+
```python
|
|
162
|
+
from mathai import *
|
|
163
|
+
def nested_func(eq_node):
|
|
164
|
+
eq_node = fraction(eq_node)
|
|
165
|
+
eq_node = simplify(eq_node)
|
|
166
|
+
eq_node = trig1(eq_node)
|
|
167
|
+
eq_node = trig0(eq_node)
|
|
168
|
+
return eq_node
|
|
169
|
+
for item in ["(cosec(x)-cot(x))^2=(1-cos(x))/(1+cos(x))", "cos(x)/(1+sin(x)) + (1+sin(x))/cos(x) = 2*sec(x)",\
|
|
170
|
+
"tan(x)/(1-cot(x)) + cot(x)/(1-tan(x)) = 1 + sec(x)*cosec(x)", "(1+sec(x))/sec(x) = sin(x)^2/(1-cos(x))",\
|
|
171
|
+
"(cos(x)-sin(x)+1)/(cos(x)+sin(x)-1) = cosec(x)+cot(x)"]:
|
|
172
|
+
eq = logic0(dowhile(parse(item), nested_func))
|
|
173
|
+
print(eq)
|
|
174
|
+
```
|
|
175
|
+
#### Output
|
|
176
|
+
|
|
177
|
+
```
|
|
178
|
+
true
|
|
179
|
+
true
|
|
180
|
+
true
|
|
181
|
+
true
|
|
182
|
+
true
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
#### Example Demonstration 3
|
|
186
|
+
```python
|
|
187
|
+
from mathai import *
|
|
188
|
+
|
|
189
|
+
eq = simplify(parse("integrate(2*x/(x^2+1),x)"))
|
|
190
|
+
eq = integrate_const(eq)
|
|
191
|
+
eq = integrate_fraction(eq)
|
|
192
|
+
print(simplify(fraction(simplify(eq))))
|
|
193
|
+
|
|
194
|
+
eq = simplify(parse("integrate(sin(cos(x))*sin(x),x)"))
|
|
195
|
+
eq = integrate_subs(eq)
|
|
196
|
+
eq = integrate_const(eq)
|
|
197
|
+
eq = integrate_formula(eq)
|
|
198
|
+
eq = integrate_clean(eq)
|
|
199
|
+
print(simplify(eq))
|
|
200
|
+
|
|
201
|
+
eq = simplify(parse("integrate(x*sqrt(x+2),x)"))
|
|
202
|
+
eq = integrate_subs(eq)
|
|
203
|
+
eq = integrate_const(eq)
|
|
204
|
+
eq = integrate_formula(eq)
|
|
205
|
+
eq = expand(eq)
|
|
206
|
+
eq = integrate_const(eq)
|
|
207
|
+
eq = integrate_summation(eq)
|
|
208
|
+
eq = simplify(eq)
|
|
209
|
+
eq = integrate_const(eq)
|
|
210
|
+
eq = integrate_formula(eq)
|
|
211
|
+
eq = integrate_clean(eq)
|
|
212
|
+
print(simplify(fraction(simplify(eq))))
|
|
213
|
+
|
|
214
|
+
eq = simplify(parse("integrate(x/(e^(x^2)),x)"))
|
|
215
|
+
eq = integrate_subs(eq)
|
|
216
|
+
eq = integrate_const(eq)
|
|
217
|
+
eq = integrate_formula(eq)
|
|
218
|
+
eq = simplify(eq)
|
|
219
|
+
eq = integrate_formula(eq)
|
|
220
|
+
eq = integrate_clean(eq)
|
|
221
|
+
print(simplify(eq))
|
|
222
|
+
|
|
223
|
+
eq = fraction(trig0(trig1(simplify(parse("integrate(sin(x)^4,x)")))))
|
|
224
|
+
eq = integrate_const(eq)
|
|
225
|
+
eq = integrate_summation(eq)
|
|
226
|
+
eq = integrate_formula(eq)
|
|
227
|
+
eq = integrate_const(eq)
|
|
228
|
+
eq = integrate_formula(eq)
|
|
229
|
+
print(factor0(simplify(fraction(simplify(eq)))))
|
|
230
|
+
```
|
|
231
|
+
#### Output
|
|
232
|
+
|
|
233
|
+
```
|
|
234
|
+
log(abs((1+(x^2))))
|
|
235
|
+
cos(cos(x))
|
|
236
|
+
((6*((2+x)^(5/2)))-(20*((2+x)^(3/2))))/15
|
|
237
|
+
-((e^-(x^2))/2)
|
|
238
|
+
-(((8*sin((2*x)))-(12*x)-sin((4*x)))/32)
|
|
239
|
+
```
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
mathai/__init__.py,sha256=Mv0vNdV-FHKS6MzAsnHsE0eBtSkCUq0nc9tUgCWxbFo,1541
|
|
2
2
|
mathai/apart.py,sha256=VSS3khE9PNuxiRvdU5JDl4IN-KJBSIFjwR17pkhviXI,4197
|
|
3
|
-
mathai/base.py,sha256=
|
|
3
|
+
mathai/base.py,sha256=hRiJWS94asWl-t11eGrVCEhZqIub0T-8S_Eqmlun6mI,15819
|
|
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=RSTwlfeddvYXUDShCeRdcPjsmAS8Vf5OkYJAaUBPaiM,3060
|
|
7
|
-
mathai/expand.py,sha256=
|
|
7
|
+
mathai/expand.py,sha256=r2Ha6graDLgLOlx3ox4egUvJD5L_-4_n-FQs2wyWVKg,6284
|
|
8
8
|
mathai/factor.py,sha256=3wcmZOGUqMlLj4v2DA14ZLqEQ7khavOi7PjZJU6VX40,12494
|
|
9
9
|
mathai/fraction.py,sha256=88xvRpDGfFi8tbe1QIyejdSP91HcErrN4VS2MxzbhrY,4392
|
|
10
10
|
mathai/integrate.py,sha256=C_lqYgQN4UiriCb_LDkpwtKx7XJhp_K8T9skCkxWqas,17208
|
|
@@ -12,9 +12,9 @@ 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
|
-
mathai/matrix.py,sha256=
|
|
15
|
+
mathai/matrix.py,sha256=sIusSmZN0Y6k4TovI5L6Hepls9i7FPRjA3CZIU4X4_w,7276
|
|
16
16
|
mathai/ode.py,sha256=zxxTXAOpt7oSsfpgI4vHsCWKXevmM96ZOBZWWs-vj8Y,4801
|
|
17
|
-
mathai/parser.py,sha256=
|
|
17
|
+
mathai/parser.py,sha256=3cBl7DhqL275gqXszET5zC85O9v3XKxRPc2EaOigAns,7302
|
|
18
18
|
mathai/parsetab.py,sha256=TL-4jvRM_Tx6ipwet8CFJc2DkjR4tGsbrGF_r4IC8xI,9651
|
|
19
19
|
mathai/printeq.py,sha256=4UgLJo-vV_YlVw_3QUQY_jQMHrFnG-ZKAyVZsd7yD6o,1450
|
|
20
20
|
mathai/simplify.py,sha256=VsUw89U3FqSpD3mMUGM0pr0dZ__MDQOBD8maaB7MDBY,19973
|
|
@@ -22,7 +22,7 @@ mathai/structure.py,sha256=wrU7kqphSN7CqaVffyHHXD2-3t5My_Z_TtYFoUe_lTU,4099
|
|
|
22
22
|
mathai/tool.py,sha256=ozcXTXLbKUnyPM9r9kz9M43YA2CBcWezcqLZfEs8rpc,6051
|
|
23
23
|
mathai/trig.py,sha256=fnBbfiopcQzFg4ya1BoO5M0X_aCBnse2bjnKh1juw4I,11223
|
|
24
24
|
mathai/univariate_inequality.py,sha256=LPFdWgC1y5zBwnsy1wwZxj-yP_SbqFDhCmTTzhuwoiY,16469
|
|
25
|
-
mathai-0.
|
|
26
|
-
mathai-0.
|
|
27
|
-
mathai-0.
|
|
28
|
-
mathai-0.
|
|
25
|
+
mathai-0.7.1.dist-info/METADATA,sha256=n_NIEmTCflCFZpdeleCh5NQaV2lrITXa4es41rV4aSk,5887
|
|
26
|
+
mathai-0.7.1.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
27
|
+
mathai-0.7.1.dist-info/top_level.txt,sha256=ROP4l3OhGYw3ihkQGASr18xM9GsK4z3_6whV5AyXLwE,7
|
|
28
|
+
mathai-0.7.1.dist-info/RECORD,,
|
mathai-0.6.9.dist-info/METADATA
DELETED
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: mathai
|
|
3
|
-
Version: 0.6.9
|
|
4
|
-
Summary: Mathematics solving Ai tailored to NCERT
|
|
5
|
-
Home-page: https://github.com/infinity390/mathai4
|
|
6
|
-
Author: educated indians are having a low iq and are good for nothing
|
|
7
|
-
Requires-Python: >=3.7
|
|
8
|
-
Description-Content-Type: text/markdown
|
|
9
|
-
Requires-Dist: lark-parser
|
|
10
|
-
Dynamic: author
|
|
11
|
-
Dynamic: description
|
|
12
|
-
Dynamic: description-content-type
|
|
13
|
-
Dynamic: home-page
|
|
14
|
-
Dynamic: requires-dist
|
|
15
|
-
Dynamic: requires-python
|
|
16
|
-
Dynamic: summary
|
|
17
|
-
|
|
18
|
-
# Math AI Documentation
|
|
19
|
-
## Source
|
|
20
|
-
Github repository of the code
|
|
21
|
-
https://github.com/infinity390/mathai4
|
|
22
|
-
|
|
23
|
-
## Philosophy
|
|
24
|
-
I think it is a big realization in computer science and programming to realize that computers can solve mathematics.
|
|
25
|
-
This understanding should be made mainstream. It can help transform education, mathematical research, and computation of mathematical equations for work.
|
|
26
|
-
|
|
27
|
-
## Societal Implications Of Such A Computer Program And The Author's Comment On Universities Of India
|
|
28
|
-
I think mathematics is valued by society because of education. Schools and universities teach them.
|
|
29
|
-
So this kind of software, if made mainstream, could bring real change.
|
|
30
|
-
|
|
31
|
-
### The Author's Comments On The Universities In His Country
|
|
32
|
-
> Educated Indians are having a low IQ and are good for nothing.
|
|
33
|
-
> The Indian Institute of Technology (IITs) graduates are the leader of the fools.
|
|
34
|
-
> Every educated Indian is beneath me.
|
|
35
|
-
> Now learn how this Python library can solve the math questions of your exams.
|
|
36
|
-
|
|
37
|
-
## The Summary Of How Computer "Solves" Math
|
|
38
|
-
Math equations are a tree data structure (`TreeNode` class).
|
|
39
|
-
We can manipulate the math equations using various algorithms (functions provided by the `mathai` library).
|
|
40
|
-
We first parse the math equation strings to get the tree data structure (`parse` function in `mathai`).
|
|
41
|
-
|
|
42
|
-
## The Library
|
|
43
|
-
Import the library by doing:
|
|
44
|
-
|
|
45
|
-
```python
|
|
46
|
-
from mathai import *
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
### str_form
|
|
50
|
-
It is the string representation of a `TreeNode` math equation.
|
|
51
|
-
|
|
52
|
-
#### Example
|
|
53
|
-
```text
|
|
54
|
-
(cos(x)^2)+(sin(x)^2)
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
Is represented internally as:
|
|
58
|
-
|
|
59
|
-
```text
|
|
60
|
-
f_add
|
|
61
|
-
f_pow
|
|
62
|
-
f_cos
|
|
63
|
-
v_0
|
|
64
|
-
d_2
|
|
65
|
-
f_pow
|
|
66
|
-
f_sin
|
|
67
|
-
v_0
|
|
68
|
-
d_2
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
#### Leaf Nodes
|
|
72
|
-
|
|
73
|
-
**Variables** (start with a `v_` prefix):
|
|
74
|
-
|
|
75
|
-
- `v_0` -> x
|
|
76
|
-
- `v_1` -> y
|
|
77
|
-
- `v_2` -> z
|
|
78
|
-
- `v_3` -> a
|
|
79
|
-
|
|
80
|
-
**Numbers** (start with `d_` prefix; only integers):
|
|
81
|
-
|
|
82
|
-
- `d_-1` -> -1
|
|
83
|
-
- `d_0` -> 0
|
|
84
|
-
- `d_1` -> 1
|
|
85
|
-
- `d_2` -> 2
|
|
86
|
-
|
|
87
|
-
#### Branch Nodes
|
|
88
|
-
- `f_add` -> addition
|
|
89
|
-
- `f_mul` -> multiplication
|
|
90
|
-
- `f_pow` -> power
|
|
91
|
-
|
|
92
|
-
### parse
|
|
93
|
-
Takes a math equation string and outputs a `TreeNode` object.
|
|
94
|
-
|
|
95
|
-
```python
|
|
96
|
-
from mathai import *
|
|
97
|
-
|
|
98
|
-
equation = parse("sin(x)^2+cos(x)^2")
|
|
99
|
-
print(equation)
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
#### Output
|
|
103
|
-
```text
|
|
104
|
-
(cos(x)^2)+(sin(x)^2)
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
### printeq, printeq_str, printeq_log
|
|
108
|
-
Prints math equations in a more readable form than usual `print`.
|
|
109
|
-
|
|
110
|
-
```python
|
|
111
|
-
from mathai import *
|
|
112
|
-
|
|
113
|
-
equation = simplify(parse("(x+1)/x"))
|
|
114
|
-
print(equation)
|
|
115
|
-
printeq(equation)
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
#### Output
|
|
119
|
-
```text
|
|
120
|
-
(1+x)*(x^-1)
|
|
121
|
-
(1+x)/x
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
### solve, simplify
|
|
125
|
-
`simplify` performs what `solve` does and more.
|
|
126
|
-
It simplifies and cleans up a given math equation.
|
|
127
|
-
|
|
128
|
-
```python
|
|
129
|
-
from mathai import *
|
|
130
|
-
|
|
131
|
-
equation = simplify(parse("(x+x+x+x-1-1-1-1)*(4*x-4)*sin(sin(x+x+x)*sin(3*x))"))
|
|
132
|
-
printeq(equation)
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
#### Output
|
|
136
|
-
```text
|
|
137
|
-
((-4+(4*x))^2)*sin((sin((3*x))^2))
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
### Incomplete Documentation, Will be updated and completed later on
|
|
141
|
-
|
|
142
|
-
### Example Demonstration [limits questions can also be solved other than this these, try limit()]
|
|
143
|
-

|
|
144
|
-
```python
|
|
145
|
-
import sys, os, time
|
|
146
|
-
from mathai import *
|
|
147
|
-
|
|
148
|
-
sys.setrecursionlimit(10000)
|
|
149
|
-
|
|
150
|
-
def integration_byparts(item): return simplify(fraction(simplify(byparts(simplify(parse(item)))[0])))
|
|
151
|
-
def integration_apart(item): return simplify(fraction(integrate(apart(factor2(simplify(parse(item)))))[0]))
|
|
152
|
-
def integration_direct(item): return simplify(fraction(simplify(integrate(simplify(parse(item)))[0])))
|
|
153
|
-
def integration_trig(item): return simplify(trig0(integrate(trig1(simplify(parse(item))))[0]))
|
|
154
|
-
def algebra(item): return logic0(simplify(expand(simplify(parse(item)))))
|
|
155
|
-
def trig_basic(item): return logic0(simplify(expand(trig3(simplify(parse(item))))))
|
|
156
|
-
def trig_advanced(item): return logic0(simplify(trig0(trig1(trig4(simplify(fraction(trig0(simplify(parse(item))))))))))
|
|
157
|
-
|
|
158
|
-
all_tasks = [
|
|
159
|
-
*[(item, trig_advanced) for item in [
|
|
160
|
-
"cos(x)/(1+sin(x)) + (1+sin(x))/cos(x) = 2*sec(x)",
|
|
161
|
-
"(1+sec(x))/sec(x) = sin(x)^2/(1-cos(x))"]],
|
|
162
|
-
*[(item, integration_byparts) for item in ["sin(x)*x","x*sin(3*x)","x*log(abs(x))","arctan(x)"]],
|
|
163
|
-
*[(item, integration_apart) for item in ["x/((x+1)*(x+2))","1/(x^2-9)"]],
|
|
164
|
-
*[(item, integration_direct) for item in [
|
|
165
|
-
"x*sqrt(x+2)","sin(cos(x))*sin(x)","2*x/(1+x^2)","sqrt(a*x+b)","cos(sqrt(x))/sqrt(x)","e^(arctan(x))/(1+x^2)","sqrt(sin(2*x))*cos(2*x"]],
|
|
166
|
-
*[(item, integration_trig) for item in ["sin(2*x+5)^2","sin(x)^4","cos(2*x)^4"]],
|
|
167
|
-
*[(item, algebra) for item in ["(x+1)^2 = x^2+2*x+1","(x+1)*(x-1) = x^2-1"]],
|
|
168
|
-
*[(item, trig_basic) for item in ["2*sin(x)*cos(x)=sin(2*x)"]],
|
|
169
|
-
]
|
|
170
|
-
|
|
171
|
-
def run_task(task):
|
|
172
|
-
item, func = task
|
|
173
|
-
try: result = func(item)
|
|
174
|
-
except Exception as e: result = str(e)
|
|
175
|
-
return item, result
|
|
176
|
-
|
|
177
|
-
if __name__=="__main__":
|
|
178
|
-
print(f"Solving {len(all_tasks)} math questions...\n")
|
|
179
|
-
start_time = time.time()
|
|
180
|
-
for task in all_tasks:
|
|
181
|
-
item, result = run_task(task)
|
|
182
|
-
print(f"{item} => {result}\n")
|
|
183
|
-
print(f"All tasks completed in {time.time()-start_time:.2f} seconds")
|
|
184
|
-
```
|
|
185
|
-
### Output
|
|
186
|
-
|
|
187
|
-
```
|
|
188
|
-
Running 21 tasks asynchronously on 8 cores...
|
|
189
|
-
|
|
190
|
-
x*log(abs(x)) => ((-2*(x^2))+(4*log(abs(x))*(x^2)))*(8^-1)
|
|
191
|
-
|
|
192
|
-
arctan(x) => (log((abs((1+(x^2)))^-1))+(2*arctan(x)*x))*(2^-1)
|
|
193
|
-
|
|
194
|
-
sin(cos(x))*sin(x) => cos(cos(x))
|
|
195
|
-
|
|
196
|
-
1/(x^2-9) => (log(abs((-3+x)))+log((abs((3+x))^-1)))*(6^-1)
|
|
197
|
-
|
|
198
|
-
x/((x+1)*(x+2)) => log((abs((1+x))^-1))+log(((2+x)^2))
|
|
199
|
-
|
|
200
|
-
x*sin(3*x) => ((-9*cos((3*x))*x)+(3*sin((3*x))))*(27^-1)
|
|
201
|
-
|
|
202
|
-
(1+sec(x))/sec(x) = sin(x)^2/(1-cos(x)) => true
|
|
203
|
-
|
|
204
|
-
e^(arctan(x))/(1+x^2) => e^arctan(x)
|
|
205
|
-
|
|
206
|
-
cos(sqrt(x))/sqrt(x) => 2*sin((x^(2^-1)))
|
|
207
|
-
|
|
208
|
-
sqrt(a*x+b) => 2*(3^-1)*(((x*a)+b)^(3*(2^-1)))*(a^-1)
|
|
209
|
-
|
|
210
|
-
sin(x)*x => (-1*cos(x)*x)+sin(x)
|
|
211
|
-
|
|
212
|
-
(x+1)^2 = x^2+2*x+1 => true
|
|
213
|
-
|
|
214
|
-
(x+1)*(x-1) = x^2-1 => true
|
|
215
|
-
|
|
216
|
-
cos(x)/(1+sin(x)) + (1+sin(x))/cos(x) = 2*sec(x) => true
|
|
217
|
-
|
|
218
|
-
2*sin(x)*cos(x)=sin(2*x) => true
|
|
219
|
-
|
|
220
|
-
sqrt(sin(2*x))*cos(2*x) => (3^-1)*(sin((2*x))^(3*(2^-1)))
|
|
221
|
-
|
|
222
|
-
2*x/(1+x^2) => log(abs((1+(x^2))))
|
|
223
|
-
|
|
224
|
-
sin(2*x+5)^2 => ((-1*(4^-1)*sin((10+(4*x))))+x)*(2^-1)
|
|
225
|
-
|
|
226
|
-
cos(2*x)^4 => ((4^-1)*x)+((64^-1)*sin((8*x)))+((8^-1)*sin((4*x)))+((8^-1)*x)
|
|
227
|
-
|
|
228
|
-
x*sqrt(x+2) => ((-1*(4^-1)*((2+x)^(2+(2^-1))))+(-2*((2+x)^(2+(2^-1))))+(5*((2+x)^(1+(2^-1)))*x)+((2^-1)*((2+x)^(1+(2^-1)))*x)+((8^-1)*((2+x)^(1+(2^-1)))*x))*((1+(2^-1))^-3)*((2+(2^-1))^-1)
|
|
229
|
-
|
|
230
|
-
sin(x)^4 => (-1*(4^-1)*sin((2*x)))+((32^-1)*sin((4*x)))+((4^-1)*x)+((8^-1)*x)
|
|
231
|
-
|
|
232
|
-
All tasks completed in 129.78 seconds
|
|
233
|
-
```
|
|
234
|
-
|
|
File without changes
|