mathai 0.4.5__py3-none-any.whl → 0.4.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
@@ -1,3 +1,6 @@
1
+ from .ode import diffsolve as ode_solve
2
+ from .ode import diffsolve_sep as ode_shift_term
3
+
1
4
  from .expand import expand
2
5
 
3
6
  from .parser import parse
@@ -20,6 +23,8 @@ from .diff import diff
20
23
 
21
24
  from .factor import factor as factor1
22
25
  from .factor import factor2
26
+ from .factor import rationalize_sqrt as rationalize
27
+ from .factor import merge_sqrt
23
28
  from .factor import factorconst as factor0
24
29
 
25
30
  from .fraction import fraction
mathai/base.py CHANGED
@@ -253,6 +253,7 @@ def num_dem(equation):
253
253
  else:
254
254
  num = num*item
255
255
  return [num, tree_form("d_1")/den]
256
+
256
257
  def summation(lst):
257
258
  if lst == []:
258
259
  return tree_form("d_0")
mathai/factor.py CHANGED
@@ -69,6 +69,93 @@ def _factorconst(eq):
69
69
  if n != 1:
70
70
  return tree_form("d_"+str(n))*eq
71
71
  return TreeNode(eq.name, [factorconst(child) for child in eq.children])
72
+
73
+ def _merge_sqrt(eq):
74
+ lst= []
75
+ eq2 = []
76
+ for child in factor_generation(eq):
77
+ if frac(child) is not None and frac(child).denominator==1:
78
+ if frac(child)>0:
79
+ eq2.append(child**2)
80
+ elif frac(child)!=-1:
81
+ eq2.append((-child)**2)
82
+ lst.append(tree_form("d_-1"))
83
+ else:
84
+ lst.append(tree_form("d_-1"))
85
+ elif child.name == "f_pow" and frac(child.children[1]) == Fraction(1,2):
86
+ eq2.append(child.children[0])
87
+ else:
88
+ lst.append(child)
89
+
90
+ if len(eq2)>1:
91
+ if lst == []:
92
+ lst= [tree_form("d_1")]
93
+ return simplify(product(eq2)**(tree_form("d_2")**-1)*product(lst))
94
+ return TreeNode(eq.name, [_merge_sqrt(child) for child in eq.children])
95
+ def sqrt_to_a_sqrt_b(n):
96
+ if n == 0:
97
+ return 0, 0
98
+ sign = 1
99
+ if n < 0:
100
+ sign = -1
101
+ m = -n
102
+ else:
103
+ m = n
104
+
105
+ a = 1
106
+ b = 1
107
+ p = 2
108
+ while p * p <= m:
109
+ exp = 0
110
+ while m % p == 0:
111
+ m //= p
112
+ exp += 1
113
+ if exp:
114
+ a *= p ** (exp // 2)
115
+ if exp % 2 == 1:
116
+ b *= p
117
+ p += 1 if p == 2 else 2
118
+
119
+ if m > 1:
120
+ b *= m
121
+
122
+ return sign * a, b
123
+ def merge_sqrt(eq):
124
+ def helper(eq):
125
+ if eq.name == "f_pow" and frac(eq.children[1]) == Fraction(1,2):
126
+ if eq.children[0].name[:2] == "d_":
127
+ n = int(eq.children[0].name[2:])
128
+ a, b =sqrt_to_a_sqrt_b(n)
129
+ return tree_form("d_"+str(b))**(tree_form("d_2")**-1)*tree_form("d_"+str(a))
130
+ return TreeNode(eq.name, [helper(child) for child in eq.children])
131
+ return helper(_merge_sqrt(eq))
132
+ def rationalize_sqrt(eq):
133
+ if eq.name== "f_pow" and frac(eq.children[1]) == Fraction(-1,2):
134
+ eq = eq.children[0]**(tree_form("d_2")**-1)/eq.children[0]
135
+ def term(eq):
136
+ if eq.name == "f_add":
137
+ output = []
138
+ for child in eq.children:
139
+ if any(child2.name == "f_pow" and frac(child2.children[1]) == Fraction(1,2) for child2 in factor_generation(child)):
140
+ output.append(simplify(-child))
141
+ else:
142
+ output.append(child)
143
+ return summation(output)
144
+ return None
145
+ n, d=num_dem(eq)
146
+ n,d=simplify(n), simplify(d)
147
+
148
+ if d != 1:
149
+ t = term(d)
150
+ if t is not None and t!=1:
151
+
152
+ n,d=simplify(expand(simplify(n*t))),simplify(expand(simplify(d*t)))
153
+ tmp= simplify(n/d)
154
+
155
+ tmp = _merge_sqrt(tmp)
156
+
157
+ return tmp
158
+ return TreeNode(eq.name, [rationalize_sqrt(child) for child in eq.children])
72
159
  def factorconst(eq):
73
160
  return simplify(_factorconst(eq))
74
161
  def factor_quad_formula_init():
@@ -77,6 +164,7 @@ def factor_quad_formula_init():
77
164
  formula_list = [[simplify(parse(y)) for y in x] for x in formula_list]
78
165
  expr = [[parse("A"), parse("1")], [parse("B"), parse("0"), parse("1")], [parse("C"), parse("0")]]
79
166
  return [formula_list, var, expr]
167
+
80
168
  def factor_quar_formula_init():
81
169
  var = ""
82
170
  formula_list = [(f"(A^4+B*A^2+C)", f"(A^2 + sqrt(2*sqrt(C) - B)*A + sqrt(C))*(A^2 - sqrt(2*sqrt(C) - B)*A + sqrt(C))")]
mathai/integrate.py CHANGED
@@ -367,7 +367,7 @@ def rm_const(equation):
367
367
  if equation.name == "f_ref":
368
368
  return equation
369
369
  eq2 = equation
370
- if eq2.name == "f_integrate":
370
+ if eq2.name == "f_integrate" and contain(eq2.children[0], eq2.children[1]):
371
371
  equation = eq2.children[0]
372
372
  wrt = eq2.children[1]
373
373
  lst = factor_generation(equation)
@@ -407,4 +407,3 @@ def integrate_formula(equation):
407
407
 
408
408
  return out
409
409
  return TreeNode(eq2.name, [integrate_formula(child) for child in eq2.children])
410
-
mathai/ode.py ADDED
@@ -0,0 +1,124 @@
1
+ from .factor import factor
2
+ from .expand import expand
3
+ from .base import *
4
+ from .fraction import fraction
5
+ from .simplify import simplify
6
+ import copy
7
+
8
+ def inversediff(lhs, rhs):
9
+ count = 4
10
+ while contain(rhs, tree_form("v_1")) or contain(lhs, tree_form("v_0")):
11
+ success = False
12
+ if rhs.name == "f_add":
13
+ for i in range(len(rhs.children)-1,-1,-1):
14
+ if not contain(rhs.children[i], tree_form("v_0")) or str_form(tree_form("v_1").fx("dif")) in [str_form(x) for x in factor_generation(rhs.children[i])]:
15
+ if contain(rhs.children[i], tree_form("v_0")) or contain(rhs.children[i], tree_form("v_1")):
16
+ success = True
17
+ lhs = lhs - rhs.children[i]
18
+ rhs.children.pop(i)
19
+ elif rhs.name == "f_mul":
20
+ for i in range(len(rhs.children)-1,-1,-1):
21
+ if not contain(rhs.children[i], tree_form("v_0")):
22
+ if contain(rhs.children[i], tree_form("v_0")) or contain(rhs.children[i], tree_form("v_1")):
23
+ success = True
24
+ lhs = lhs / rhs.children[i]
25
+ rhs.children.pop(i)
26
+ if len(rhs.children) == 1:
27
+ rhs = rhs.children[0]
28
+ rhs, lhs = copy.deepcopy([simplify(lhs), simplify(rhs)])
29
+ if rhs.name == "f_add":
30
+ for i in range(len(rhs.children)-1,-1,-1):
31
+ if not contain(rhs.children[i], tree_form("v_1")) or str_form(tree_form("v_0").fx("dif")) in [str_form(x) for x in factor_generation(rhs.children[i])]:
32
+ if contain(rhs.children[i], tree_form("v_0")) or contain(rhs.children[i], tree_form("v_1")):
33
+ success = True
34
+ lhs = lhs - rhs.children[i]
35
+ rhs.children.pop(i)
36
+ elif rhs.name == "f_mul":
37
+ for i in range(len(rhs.children)-1,-1,-1):
38
+ if not contain(rhs.children[i], tree_form("v_1")):
39
+ if contain(rhs.children[i], tree_form("v_0")) or contain(rhs.children[i], tree_form("v_1")):
40
+ success = True
41
+ lhs = lhs / rhs.children[i]
42
+ rhs.children.pop(i)
43
+ rhs, lhs = copy.deepcopy([simplify(lhs), simplify(rhs)])
44
+ if not success:
45
+ lhs, rhs = factor(lhs),factor(rhs)
46
+ count -= 1
47
+ if count == 0:
48
+ return simplify(e0(lhs-rhs))
49
+ return simplify(e0(lhs-rhs))
50
+
51
+ intconst = ["v_"+str(i) for i in range(101,150)]
52
+ def allocvar():
53
+ global intconst
54
+ return tree_form(intconst.pop(0))
55
+
56
+ def epowersplit(eq):
57
+ if eq.name == "f_pow" and eq.children[1].name == "f_add":
58
+ return product([eq.children[0]**child for child in eq.children[1].children])
59
+ return TreeNode(eq.name, [epowersplit(child) for child in eq.children])
60
+ def esolve(s):
61
+ if s.name == "f_add" and "f_log" in str_form(s):
62
+ return product([tree_form("s_e")**child for child in s.children]) - tree_form("d_1")
63
+ return TreeNode(s.name, [esolve(child) for child in s.children])
64
+ def diffsolve_sep2(eq):
65
+ global tab
66
+
67
+ s = []
68
+ eq = simplify(expand(eq))
69
+ eq = e1(eq)
70
+
71
+ def vlor1(eq):
72
+ if contain(eq, tree_form("v_0")) and not contain(eq, tree_form("v_1")):
73
+ return True
74
+ if contain(eq, tree_form("v_1")) and not contain(eq, tree_form("v_0")):
75
+ return True
76
+ return False
77
+ if eq.name == "f_add" and all(vlor1(child) and [str_form(x) for x in factor_generation(copy.deepcopy(child))].count(str_form(tree_form(vlist(child)[0]).fx("dif")))==1 for child in eq.children):
78
+ for child in eq.children:
79
+ v = vlist(child)[0]
80
+ v2 = tree_form(v).fx("dif")
81
+ child = replace(child, v2, tree_form("d_1"))
82
+ child = simplify(child)
83
+
84
+
85
+ tmp6 = TreeNode("f_integrate", [child, tree_form(v)])
86
+ s.append(tmp6)
87
+
88
+ if s[-1] is None:
89
+ return None
90
+ s.append(allocvar())
91
+ else:
92
+ return None
93
+ s = summation(s)
94
+ s = simplify(e0(s))
95
+
96
+ return groupe(s)
97
+ def e0(eq):
98
+ return TreeNode("f_eq", [eq, tree_form("d_0")])
99
+ def e1(eq):
100
+ if eq.name == "f_eq":
101
+ eq = eq.children[0]
102
+ return eq
103
+ def groupe(eq):
104
+ eq = esolve(eq)
105
+ eq = simplify(eq)
106
+ eq = fraction(eq)
107
+ eq = simplify(eq)
108
+ eq = epowersplit(eq)
109
+ return eq
110
+
111
+ def diffsolve_sep(eq):
112
+ eq = epowersplit(eq)
113
+
114
+ eq = inversediff(tree_form("d_0"), eq.children[0].copy_tree())
115
+ return eq
116
+
117
+ def diffsolve(eq):
118
+ orig = eq.copy_tree()
119
+
120
+
121
+ eq = diffsolve_sep2(eq)
122
+ if eq is None:
123
+ return orig
124
+ return eq
mathai/simplify.py CHANGED
@@ -384,3 +384,4 @@ def simplify(eq):
384
384
  if error:
385
385
  return None
386
386
  return solve(eq)
387
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mathai
3
- Version: 0.4.5
3
+ Version: 0.4.6
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
@@ -1,24 +1,25 @@
1
- mathai/__init__.py,sha256=hxMCrvwj98yE5ChWSzvkn0gMxqAQnh8oze3ZlImWyD0,1170
1
+ mathai/__init__.py,sha256=HiH4VCvWd5r4o5iNLSbKJlOnpRWDBW-Na_8TQRUggz8,1348
2
2
  mathai/apart.py,sha256=8IlJ8X6SKAjPunUPHVLmgNB5GuEi4_XpY0oLkQqrHKc,3770
3
- mathai/base.py,sha256=DBFHDBRSPeb8O2cH_YzTNG3h7vxrQzrEPSUpDIPCtPI,12724
3
+ mathai/base.py,sha256=Hy2y-Nc2aXOst2WoRTuWgnlppgKsKguG9slPQbenRGk,12726
4
4
  mathai/console.py,sha256=Sn58iwYE79MLEh67s8X3q6vZjw6g7f9XM1T8_dBBR2o,3048
5
5
  mathai/diff.py,sha256=YUBpRsz0qmBkq5vGxeGnvR4nMKjdOQiIXlNMxpij2ns,3051
6
6
  mathai/expand.py,sha256=SnBltkpIENMGkP0AYmbMlSc4H-CF5RslO2PcBEkn1BQ,3359
7
- mathai/factor.py,sha256=NPXxET52TacNExuvw6p1jbC6g3wY6_VOCdlGlexXZio,5916
7
+ mathai/factor.py,sha256=vuTxFZcjAdjXC-202QmDzDLsqEGOUyAG2rr_n2CgOZ8,8735
8
8
  mathai/fraction.py,sha256=Q2ztsh5Bpz6YhML2QU0tfufbAs0Q6J319AhlzKephIY,4396
9
- mathai/integrate.py,sha256=SN_LGBN9Vd19S1blbRlypaW4Ic9tjPmXf3jhQ55dOCA,15117
9
+ mathai/integrate.py,sha256=gWkSIA-4XoAfocdfBSL5dmuadPF0QRCEfaTjz6BXHv4,15161
10
10
  mathai/inverse.py,sha256=QCvDrzKquWsZv-BDAzZd9HnU0c3gZvcc44UztHVO5LQ,2919
11
11
  mathai/limit.py,sha256=RA8YAehgYCGVWv9qBc8uQ34BQ9mFthWl2OrVTwcHl2g,4920
12
12
  mathai/linear.py,sha256=BzSnm941Zlod_l6hON4Rs6J4pdAA3MGpRVqr6-66ZBk,5524
13
13
  mathai/logic.py,sha256=UvHzRmKcO9AD51tRzHmpNSEhgW5gmaf4XPaQKFjGfC4,9653
14
+ mathai/ode.py,sha256=zxxTXAOpt7oSsfpgI4vHsCWKXevmM96ZOBZWWs-vj8Y,4801
14
15
  mathai/parser.py,sha256=f7bemieFmp0sbup1NlraMLvZDVFvqKGFknEVtlFRMVk,6979
15
16
  mathai/printeq.py,sha256=gIes-pstFOa6FcnpVIVvkjVKuWdsVdo11LlEnmHhakU,1303
16
- mathai/simplify.py,sha256=aEvpkhaDowgyQWPSxHKshcVIMngZ4NBVc2yuiCYqOYI,16229
17
+ mathai/simplify.py,sha256=x9ac0CYZ6LrLwlUJZDDqV-QbTNwLAHkrWfarcTCZKM0,16231
17
18
  mathai/structure.py,sha256=4Ww2IAx62RcQSO7_17TZES-DjMWBpcFQtL939FBIHwY,4103
18
19
  mathai/tool.py,sha256=UyccamiJy_CkFPakfufyPzdhtlEO6v2D7qwbXQ9V7Rg,2000
19
20
  mathai/trig.py,sha256=1VLEo5QvBbfoQHPdtzJ_65c1BHklesk9H0bAlvNyT7A,10543
20
21
  mathai/univariate_inequality.py,sha256=_r-kkiS4Hr-jRN7f-EL_E4svAMFWJP1Ea50HJKKbjfk,14778
21
- mathai-0.4.5.dist-info/METADATA,sha256=oryIRWZw-NGvmk5Uu-F_5zAxp0RonwuxZ-HxExh1_hc,7021
22
- mathai-0.4.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
23
- mathai-0.4.5.dist-info/top_level.txt,sha256=ROP4l3OhGYw3ihkQGASr18xM9GsK4z3_6whV5AyXLwE,7
24
- mathai-0.4.5.dist-info/RECORD,,
22
+ mathai-0.4.6.dist-info/METADATA,sha256=2eERLHKi7slZrL2Tk21RX5tDXjtn6xkxCVJUngG8MN8,7021
23
+ mathai-0.4.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
24
+ mathai-0.4.6.dist-info/top_level.txt,sha256=ROP4l3OhGYw3ihkQGASr18xM9GsK4z3_6whV5AyXLwE,7
25
+ mathai-0.4.6.dist-info/RECORD,,
File without changes