Mathematics solving Ai tailored to NCERT
Project description
Math AI Documentation
Philosophy
I think it is a big realization in computer science and programming to realize that computers can solve mathematics.
This understanding should be made mainstream. It can help transform education, mathematical research, and computation of mathematical equations for work.
Societal Implications Of Such A Computer Program And The Author's Comment On Universities Of India
I think mathematics is valued by society because of education. Schools and universities teach them.
So this kind of software, if made mainstream, could bring real change.
The Author's Comments On The Universities In His Country
Educated Indians are having a low IQ and are good for nothing.
The Indian Institute of Technology (IITs) graduates are the leader of the fools.
Every educated Indian is beneath me.
Now learn how this Python library can solve the math questions of your exams.
The Summary Of How Computer "Solves" Math
Math equations are a tree data structure (TreeNode class).
We can manipulate the math equations using various algorithms (functions provided by the mathai library).
We first parse the math equation strings to get the tree data structure (parse function in mathai).
The Library
Import the library by doing:
from mathai import *
str_form
It is the string representation of a TreeNode math equation.
Example
(cos(x)^2)+(sin(x)^2)
Is represented internally as:
f_add
f_pow
f_cos
v_0
d_2
f_pow
f_sin
v_0
d_2
Leaf Nodes
Variables (start with a v_ prefix):
v_0-> xv_1-> yv_2-> zv_3-> a
Numbers (start with d_ prefix; only integers):
d_-1-> -1d_0-> 0d_1-> 1d_2-> 2
Branch Nodes
f_add-> additionf_mul-> multiplicationf_pow-> power
parse
Takes a math equation string and outputs a TreeNode object.
from mathai import *
equation = parse("sin(x)^2+cos(x)^2")
print(equation)
Output
(cos(x)^2)+(sin(x)^2)
printeq, printeq_str, printeq_log
Prints math equations in a more readable form than usual print.
from mathai import *
equation = simplify(parse("(x+1)/x"))
print(equation)
printeq(equation)
Output
(1+x)*(x^-1)
(1+x)/x
solve, simplify
simplify performs what solve does and more.
It simplifies and cleans up a given math equation.
from mathai import *
equation = simplify(parse("(x+x+x+x-1-1-1-1)*(4*x-4)*sin(sin(x+x+x)*sin(3*x))"))
printeq(equation)
Output
((-4+(4*x))^2)*sin((sin((3*x))^2))
Incomplete Documentation, Will be updated and completed later on
Example Demonstration [limits questions can also be solved other than this these, try limit()]
import sys, os, time
from mathai import *
sys.setrecursionlimit(10000)
def integration_byparts(item): return simplify(fraction(simplify(byparts(simplify(parse(item)))[0])))
def integration_apart(item): return simplify(fraction(integrate(apart(factor2(simplify(parse(item)))))[0]))
def integration_direct(item): return simplify(fraction(simplify(integrate(simplify(parse(item)))[0])))
def integration_trig(item): return simplify(trig0(integrate(trig1(simplify(parse(item))))[0]))
def algebra(item): return logic0(simplify(expand(simplify(parse(item)))))
def trig_basic(item): return logic0(simplify(expand(trig3(simplify(parse(item))))))
def trig_advanced(item): return logic0(simplify(trig0(trig1(trig4(simplify(fraction(trig0(simplify(parse(item))))))))))
all_tasks = [
*[(item, trig_advanced) for item in [
"cos(x)/(1+sin(x)) + (1+sin(x))/cos(x) = 2*sec(x)",
"(1+sec(x))/sec(x) = sin(x)^2/(1-cos(x))"]],
*[(item, integration_byparts) for item in ["sin(x)*x","x*sin(3*x)","x*log(abs(x))","arctan(x)"]],
*[(item, integration_apart) for item in ["x/((x+1)*(x+2))","1/(x^2-9)"]],
*[(item, integration_direct) for item in [
"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"]],
*[(item, integration_trig) for item in ["sin(2*x+5)^2","sin(x)^4","cos(2*x)^4"]],
*[(item, algebra) for item in ["(x+1)^2 = x^2+2*x+1","(x+1)*(x-1) = x^2-1"]],
*[(item, trig_basic) for item in ["2*sin(x)*cos(x)=sin(2*x)"]],
]
def run_task(task):
item, func = task
try: result = func(item)
except Exception as e: result = str(e)
return item, result
if __name__=="__main__":
print(f"Solving {len(all_tasks)} math questions...\n")
start_time = time.time()
for task in all_tasks:
item, result = run_task(task)
print(f"{item} => {result}\n")
print(f"All tasks completed in {time.time()-start_time:.2f} seconds")
Output
Running 21 tasks asynchronously on 8 cores...
x*log(abs(x)) => ((-2*(x^2))+(4*log(abs(x))*(x^2)))*(8^-1)
arctan(x) => (log((abs((1+(x^2)))^-1))+(2*arctan(x)*x))*(2^-1)
sin(cos(x))*sin(x) => cos(cos(x))
1/(x^2-9) => (log(abs((-3+x)))+log((abs((3+x))^-1)))*(6^-1)
x/((x+1)*(x+2)) => log((abs((1+x))^-1))+log(((2+x)^2))
x*sin(3*x) => ((-9*cos((3*x))*x)+(3*sin((3*x))))*(27^-1)
(1+sec(x))/sec(x) = sin(x)^2/(1-cos(x)) => true
e^(arctan(x))/(1+x^2) => e^arctan(x)
cos(sqrt(x))/sqrt(x) => 2*sin((x^(2^-1)))
sqrt(a*x+b) => 2*(3^-1)*(((x*a)+b)^(3*(2^-1)))*(a^-1)
sin(x)*x => (-1*cos(x)*x)+sin(x)
(x+1)^2 = x^2+2*x+1 => true
(x+1)*(x-1) = x^2-1 => true
cos(x)/(1+sin(x)) + (1+sin(x))/cos(x) = 2*sec(x) => true
2*sin(x)*cos(x)=sin(2*x) => true
sqrt(sin(2*x))*cos(2*x) => (3^-1)*(sin((2*x))^(3*(2^-1)))
2*x/(1+x^2) => log(abs((1+(x^2))))
sin(2*x+5)^2 => ((-1*(4^-1)*sin((10+(4*x))))+x)*(2^-1)
cos(2*x)^4 => ((4^-1)*x)+((64^-1)*sin((8*x)))+((8^-1)*sin((4*x)))+((8^-1)*x)
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)
sin(x)^4 => (-1*(4^-1)*sin((2*x)))+((32^-1)*sin((4*x)))+((4^-1)*x)+((8^-1)*x)
All tasks completed in 129.78 seconds
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mathai-0.4.4.tar.gz.
File metadata
- Download URL: mathai-0.4.4.tar.gz
- Upload date:
- Size: 32.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac6264e037b4470136b4d309e6c98892a984c5fa4a2d1ca16737b03a5980cc45
|
|
| MD5 |
61cb64fdff3b0f69c74f3cfb8030894c
|
|
| BLAKE2b-256 |
6f3b5ad7c1c848c0a0e95588c8c994954a32d4713d978623b01cf5711402e55e
|
File details
Details for the file mathai-0.4.4-py3-none-any.whl.
File metadata
- Download URL: mathai-0.4.4-py3-none-any.whl
- Upload date:
- Size: 36.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
84db462b55cb7551d9bdb511a9f9df04e271e73d072732fa748d3e7aa0d2552b
|
|
| MD5 |
17ed34146d540d514a3e263dd2cb8918
|
|
| BLAKE2b-256 |
edd2ad8a53f99dcf904579dea6970043f744459f551ae31c15c6373dd001ccc5
|