Skip to main content

Mathematics solving Ai tailored to NCERT

Project description

Math AI Documentation

Source

Github repository of the code https://github.com/infinity390/mathai4

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 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 -> x
  • v_1 -> y
  • v_2 -> z
  • v_3 -> a

Numbers (start with d_ prefix; only integers):

  • d_-1 -> -1
  • d_0 -> 0
  • d_1 -> 1
  • d_2 -> 2

Branch Nodes

  • f_add -> addition
  • f_mul -> multiplication
  • f_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)

solve, simplify

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

Demonstrations

Example Demonstration 1

from mathai import *
question_list_from_lecture = [
    "2*x/(2*x^2 + 5*x + 2) > 1/(x + 1)",
    "(x + 2)*(x + 3)/((x - 2)*(x - 3)) <= 1",
    "(5*x - 1) < (x + 1)^2 & (x + 1)^2 < 7*x - 3",
    "(2*x - 1)/(2*x^3 + 3*x^2 + x) > 0",
    "abs(x + 5)*x + 2*abs(x + 7) - 2 = 0",
    "x*abs(x) - 5*abs(x + 2) + 6 = 0",
    "x^2 - abs(x + 2) + x > 0",
    "abs(abs(x - 2) - 3) <= 2",
    "abs(3*x - 5) + abs(8 - x) = abs(3 + 2*x)",
    "abs(x^2 + 5*x + 9) < abs(x^2 + 2*x + 2) + abs(3*x + 7)"
]

for item in question_list_from_lecture:
  eq = simplify(parse(item))
  eq = dowhile(eq, absolute)
  eq = simplify(factor1(fraction(eq)))
  eq = prepare(eq)
  eq = factor2(eq)
  c = wavycurvy(eq & domain(eq)).fix()
  print(c)

Output

(-2,-1)U(-(2/3),-(1/2))
(-inf,0)U(2,3)U{0}
(2,4)
(-inf,-1)U(-(1/2),0)U(1/2,+inf)
{-4,-3,-(3/2)-(sqrt(57)/2)}
{-1,(5/2)-(sqrt(89)/2),(5/2)+(sqrt(41)/2)}
(-inf,-sqrt(2))U((2*sqrt(2))/2,+inf)
(-3,1)U(3,7)U{1,-3,7,3}
(5/3,8)U{5/3,8}
(-inf,-(7/3))

Example Demonstration 2

from mathai import *
def nested_func(eq_node):
    eq_node = fraction(eq_node)
    eq_node = simplify(eq_node)
    eq_node = trig1(eq_node)
    eq_node = trig0(eq_node)
    return eq_node
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)",\
             "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))",\
             "(cos(x)-sin(x)+1)/(cos(x)+sin(x)-1) = cosec(x)+cot(x)"]:
  eq = logic0(dowhile(parse(item), nested_func))
  print(eq)

Output

true
true
true
true
true

Example Demonstration 3

from mathai import *

eq = simplify(parse("integrate(2*x/(x^2+1),x)"))
eq = integrate_const(eq)
eq = integrate_fraction(eq)
print(simplify(fraction(simplify(eq))))

eq = simplify(parse("integrate(sin(cos(x))*sin(x),x)"))
eq = integrate_subs(eq)
eq = integrate_const(eq)
eq = integrate_formula(eq)
eq = integrate_clean(eq)
print(simplify(eq))

eq = simplify(parse("integrate(x*sqrt(x+2),x)"))
eq = integrate_subs(eq)
eq = integrate_const(eq)
eq = integrate_formula(eq)
eq = expand(eq)
eq = integrate_const(eq)
eq = integrate_summation(eq)
eq = simplify(eq)
eq = integrate_const(eq)
eq = integrate_formula(eq)
eq = integrate_clean(eq)
print(simplify(fraction(simplify(eq))))

eq = simplify(parse("integrate(x/(e^(x^2)),x)"))
eq = integrate_subs(eq)
eq = integrate_const(eq)
eq = integrate_formula(eq)
eq = simplify(eq)
eq = integrate_formula(eq)
eq = integrate_clean(eq)
print(simplify(eq))

eq = fraction(trig0(trig1(simplify(parse("integrate(sin(x)^4,x)")))))
eq = integrate_const(eq)
eq = integrate_summation(eq)
eq = integrate_formula(eq)
eq = integrate_const(eq)
eq = integrate_formula(eq)
print(factor0(simplify(fraction(simplify(eq)))))

Output

log(abs((1+(x^2))))
cos(cos(x))
((6*((2+x)^(5/2)))-(20*((2+x)^(3/2))))/15
-((e^-(x^2))/2)
-(((8*sin((2*x)))-(12*x)-sin((4*x)))/32)

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

mathai-0.7.1.tar.gz (44.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mathai-0.7.1-py3-none-any.whl (50.1 kB view details)

Uploaded Python 3

File details

Details for the file mathai-0.7.1.tar.gz.

File metadata

  • Download URL: mathai-0.7.1.tar.gz
  • Upload date:
  • Size: 44.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for mathai-0.7.1.tar.gz
Algorithm Hash digest
SHA256 94428b3574c68ec8742a4569d2292a10a892cdf15d74eaad805b9eeec7527f20
MD5 4f67d47ba5bbf07369876cb6494a3758
BLAKE2b-256 4c292f5c5f12f849aea663056602958c252808d67cf62e74004d917ca1d78f30

See more details on using hashes here.

File details

Details for the file mathai-0.7.1-py3-none-any.whl.

File metadata

  • Download URL: mathai-0.7.1-py3-none-any.whl
  • Upload date:
  • Size: 50.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for mathai-0.7.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ca9b3cca85080c147c192ba237ec347d28ba0c9f840d4439a8aebb3d9225147c
MD5 5f2ce5dc52a36f2929b1cd9768293665
BLAKE2b-256 5b2f0373b12c6b2c2ea936bed668e5e6f9dda040e45b90ce39bffbfcd45a42e7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page