mathai 0.7.1__py3-none-any.whl → 0.7.3__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 +2 -0
- mathai/base.py +2 -29
- mathai/expand.py +63 -160
- mathai/matrix.py +1 -4
- mathai/parser.py +4 -9
- mathai/simplify.py +0 -9
- mathai/statistics.py +23 -0
- {mathai-0.7.1.dist-info → mathai-0.7.3.dist-info}/METADATA +61 -7
- {mathai-0.7.1.dist-info → mathai-0.7.3.dist-info}/RECORD +11 -10
- {mathai-0.7.1.dist-info → mathai-0.7.3.dist-info}/WHEEL +0 -0
- {mathai-0.7.1.dist-info → mathai-0.7.3.dist-info}/top_level.txt +0 -0
mathai/__init__.py
CHANGED
mathai/base.py
CHANGED
|
@@ -24,36 +24,9 @@ class TreeNode:
|
|
|
24
24
|
children = copy.deepcopy(children)
|
|
25
25
|
self.name = name
|
|
26
26
|
|
|
27
|
-
if name == "f_add" or
|
|
27
|
+
if name == "f_add" or name == "f_mul" or name == "f_dot":
|
|
28
28
|
keyed = [(str_form(c), c) for c in children]
|
|
29
29
|
self.children = [c for _, c in sorted(keyed)]
|
|
30
|
-
|
|
31
|
-
elif name == "f_mul" and TreeNode.matmul == False:
|
|
32
|
-
sortable = []
|
|
33
|
-
fixed = []
|
|
34
|
-
for c in children:
|
|
35
|
-
if not contains_list_or_neg(c):
|
|
36
|
-
sortable.append(c)
|
|
37
|
-
else:
|
|
38
|
-
fixed.append(c)
|
|
39
|
-
|
|
40
|
-
if len(sortable) > 1:
|
|
41
|
-
sortable = TreeNode("f_dmul", list(sorted(sortable, key=lambda x: str_form(x))))
|
|
42
|
-
sortable.name = "f_mul"
|
|
43
|
-
|
|
44
|
-
elif len(sortable) == 1:
|
|
45
|
-
sortable = sortable[0]
|
|
46
|
-
|
|
47
|
-
if isinstance(sortable, TreeNode):
|
|
48
|
-
fixed.append(sortable)
|
|
49
|
-
if len(fixed) > 1:
|
|
50
|
-
self.name = "f_wmul"
|
|
51
|
-
elif len(fixed) == 1:
|
|
52
|
-
self.name = fixed[0].name
|
|
53
|
-
fixed = fixed[0].children
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
self.children = fixed
|
|
57
30
|
else:
|
|
58
31
|
self.children = children
|
|
59
32
|
|
|
@@ -432,7 +405,7 @@ def string_equation_helper(equation_tree):
|
|
|
432
405
|
s = "("
|
|
433
406
|
if len(equation_tree.children) == 1 or equation_tree.name[2:] in [chr(ord("A")+i) for i in range(26)]+["limitpinf", "subs", "try", "ref","limit", "integrate", "exist", "forall", "sum2", "int", "pdif", "dif", "A", "B", "C", "covariance", "sum"]:
|
|
434
407
|
s = equation_tree.name[2:] + s
|
|
435
|
-
sign = {"f_not":"~", "f_wadd":"+", "f_wmul":"
|
|
408
|
+
sign = {"f_not":"~", "f_wadd":"+", "f_wmul":"@", "f_intersection":"&", "f_union":"|", "f_sum2":",", "f_exist":",", "f_forall":",", "f_sum":",","f_covariance": ",", "f_B":",", "f_imply":"->", "f_ge":">=", "f_le":"<=", "f_gt":">", "f_lt":"<", "f_cosec":"?" , "f_equiv": "<->", "f_sec":"?", "f_cot": "?", "f_dot": ".", "f_circumcenter":"?", "f_transpose":"?", "f_exp":"?", "f_abs":"?", "f_log":"?", "f_and":"&", "f_or":"|", "f_sub":"-", "f_neg":"?", "f_inv":"?", "f_add": "+", "f_mul": "*", "f_pow": "^", "f_poly": ",", "f_div": "/", "f_sub": "-", "f_dif": ",", "f_sin": "?", "f_cos": "?", "f_tan": "?", "f_eq": "=", "f_sqrt": "?"}
|
|
436
409
|
arr = []
|
|
437
410
|
k = None
|
|
438
411
|
if equation_tree.name not in sign.keys():
|
mathai/expand.py
CHANGED
|
@@ -2,174 +2,77 @@ from .base import *
|
|
|
2
2
|
from .simplify import simplify
|
|
3
3
|
import itertools
|
|
4
4
|
|
|
5
|
-
def
|
|
6
|
-
if not node.children:
|
|
7
|
-
return node
|
|
8
|
-
|
|
9
|
-
node.children = [eliminate_powers(c) for c in node.children]
|
|
10
|
-
|
|
11
|
-
if node.name == "f_pow":
|
|
12
|
-
base, exp = node.children
|
|
13
|
-
n = frac(exp)
|
|
14
|
-
|
|
15
|
-
# Only expand positive integer powers
|
|
16
|
-
if not (n and n.denominator == 1 and n.numerator > 1):
|
|
17
|
-
return node
|
|
18
|
-
|
|
19
|
-
n = n.numerator
|
|
20
|
-
|
|
21
|
-
# ---- Multinomial expansion ----
|
|
22
|
-
if base.name == "f_add":
|
|
23
|
-
terms = []
|
|
24
|
-
for combo in itertools.product(base.children, repeat=n):
|
|
25
|
-
prod = combo[0]
|
|
26
|
-
for c in combo[1:]:
|
|
27
|
-
prod = prod * c
|
|
28
|
-
terms.append(prod)
|
|
29
|
-
return simplify(TreeNode("f_add", terms))
|
|
30
|
-
|
|
31
|
-
# ---- Fallback: simple power ----
|
|
32
|
-
return TreeNode("f_mul", [base] * n)
|
|
33
|
-
|
|
34
|
-
return node
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
# =====================================================
|
|
39
|
-
# Phase 2: Single distributive rewrite (DEEPEST FIRST)
|
|
40
|
-
# =====================================================
|
|
41
|
-
|
|
42
|
-
def expand_once(node):
|
|
5
|
+
def expand_nc(expr, label="f_mul"):
|
|
43
6
|
"""
|
|
44
|
-
|
|
45
|
-
|
|
7
|
+
Expand expression where:
|
|
8
|
+
- f_add is commutative
|
|
9
|
+
- label (@) is NON-commutative
|
|
46
10
|
"""
|
|
11
|
+
# --- base cases ---
|
|
12
|
+
if expr.name not in {"f_add", label, "f_pow"}:
|
|
13
|
+
return expr
|
|
14
|
+
|
|
15
|
+
# --- expand children first ---
|
|
16
|
+
expr.children = [expand_nc(c, label) for c in expr.children]
|
|
17
|
+
|
|
18
|
+
# ==========================================================
|
|
19
|
+
# POWER: (A + B)^n only if n is positive integer
|
|
20
|
+
# ==========================================================
|
|
21
|
+
if expr.name == "f_pow":
|
|
22
|
+
base, exp = expr.children
|
|
23
|
+
n = frac(exp)
|
|
24
|
+
if n and n.denominator == 1 and n.numerator > 1:
|
|
25
|
+
factors = [base] * n.numerator
|
|
26
|
+
return expand_nc(TreeNode(label, factors), label)
|
|
27
|
+
return expr
|
|
28
|
+
|
|
29
|
+
# ==========================================================
|
|
30
|
+
# ADDITION (commutative)
|
|
31
|
+
# ==========================================================
|
|
32
|
+
if expr.name == "f_add":
|
|
33
|
+
out = []
|
|
34
|
+
for c in expr.children:
|
|
35
|
+
if c.name == "f_add":
|
|
36
|
+
out.extend(c.children)
|
|
37
|
+
else:
|
|
38
|
+
out.append(c)
|
|
39
|
+
return TreeNode("f_add", out)
|
|
40
|
+
|
|
41
|
+
# ==========================================================
|
|
42
|
+
# NON-COMMUTATIVE MULTIPLICATION (@)
|
|
43
|
+
# ==========================================================
|
|
44
|
+
if expr.name == label:
|
|
45
|
+
factors = []
|
|
46
|
+
|
|
47
|
+
# flatten only (NO reordering)
|
|
48
|
+
for c in expr.children:
|
|
49
|
+
if c.name == label:
|
|
50
|
+
factors.extend(c.children)
|
|
51
|
+
else:
|
|
52
|
+
factors.append(c)
|
|
47
53
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return node, True
|
|
54
|
-
|
|
55
|
-
# ---- now try expanding at this node ----
|
|
56
|
-
if node.name == "f_mul":
|
|
57
|
-
for i, child in enumerate(node.children):
|
|
58
|
-
if child.name == "f_add":
|
|
59
|
-
left = node.children[:i]
|
|
60
|
-
right = node.children[i+1:]
|
|
54
|
+
# find first additive factor
|
|
55
|
+
for i, f in enumerate(factors):
|
|
56
|
+
if f.name == "f_add":
|
|
57
|
+
left = factors[:i]
|
|
58
|
+
right = factors[i+1:]
|
|
61
59
|
|
|
62
60
|
terms = []
|
|
63
|
-
for
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
prod = l * prod
|
|
69
|
-
terms.append(prod)
|
|
70
|
-
|
|
71
|
-
return TreeNode("f_add", terms), True
|
|
72
|
-
|
|
73
|
-
return node, False
|
|
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
|
|
61
|
+
for term in f.children:
|
|
62
|
+
new_factors = left + [term] + right
|
|
63
|
+
terms.append(
|
|
64
|
+
expand_nc(TreeNode(label, new_factors), label)
|
|
65
|
+
)
|
|
87
66
|
|
|
88
|
-
|
|
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
|
|
67
|
+
return TreeNode("f_add", terms)
|
|
146
68
|
|
|
147
|
-
|
|
148
|
-
|
|
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, []))
|
|
69
|
+
# no addition inside → return as-is
|
|
70
|
+
return TreeNode(label, factors)
|
|
153
71
|
|
|
154
|
-
# =====================================================
|
|
155
|
-
# Phase 3: Global fixed-point driver
|
|
156
|
-
# =====================================================
|
|
157
72
|
|
|
158
73
|
def expand(eq):
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
if TreeNode.matmul is not None:
|
|
164
|
-
TreeNode.matmul = True
|
|
165
|
-
eq = tree_form(str_form(eq).replace("f_wmul", "f_mul"))
|
|
166
|
-
eq = flatten_tree(eq)
|
|
167
|
-
eq = eliminate_powers(eq)
|
|
168
|
-
while True:
|
|
169
|
-
eq = flatten_tree(eq)
|
|
170
|
-
eq, changed = expand_once(eq)
|
|
171
|
-
if not changed:
|
|
172
|
-
break
|
|
173
|
-
eq =simplify(eq)
|
|
174
|
-
TreeNode.matmul = orig
|
|
74
|
+
s = str_form(eq)
|
|
75
|
+
for item in ["f_mul", "f_wmul", "f_dot", "f_cross"]:
|
|
76
|
+
if item in s:
|
|
77
|
+
eq = expand_nc(eq, item)
|
|
175
78
|
return eq
|
mathai/matrix.py
CHANGED
|
@@ -219,10 +219,7 @@ def flat(eq):
|
|
|
219
219
|
def use(eq):
|
|
220
220
|
return TreeNode(eq.name, [use(child) for child in eq.children])
|
|
221
221
|
def _matrix_solve(eq):
|
|
222
|
-
|
|
223
|
-
TreeNode.matmul = False
|
|
224
|
-
eq = dowhile(eq, lambda x: fold_wmul(use(flat(x))))
|
|
225
|
-
TreeNode.matmul = True
|
|
222
|
+
eq = dowhile(eq, lambda x: fold_wmul(flat(x)))
|
|
226
223
|
return eq
|
|
227
224
|
def matrix_solve(eq):
|
|
228
225
|
return _matrix_solve(eq)
|
mathai/parser.py
CHANGED
|
@@ -37,7 +37,8 @@ grammar = """
|
|
|
37
37
|
| arithmetic "-" term -> sub
|
|
38
38
|
| term
|
|
39
39
|
|
|
40
|
-
?term: term "*" power ->
|
|
40
|
+
?term: term "*" power -> mul
|
|
41
|
+
| term "@" power -> wmul
|
|
41
42
|
| term "/" power -> div
|
|
42
43
|
| term "." power -> dot
|
|
43
44
|
| power
|
|
@@ -59,7 +60,7 @@ grammar = """
|
|
|
59
60
|
| ESCAPED_STRING -> string
|
|
60
61
|
| CAPITAL_ID -> matrix
|
|
61
62
|
|
|
62
|
-
FUNC_NAME: "midpoint" | "ref" | "subs" | "try" | "limit" | "forall" | "limitpinf" | "imply" | "exist" | "len" | "sum" | "angle" | "line" | "sum2" | "charge" | "electricfield" | "perm" | "point" | "equationrhs" | "transpose" | "equationlhs" | "equation" | "error" | "covariance" | "variance" | "expect" | "mag" | "rad" | "laplace" | "diverge" | "pdif" | "gradient" | "curl" | "point1" | "point2" | "dot" | "point3" | "line1" | "line2" | "line3" | "sin" | "circumcenter" | "eqtri" | "linesegment" | "cos" | "tan" | "log" | "sqrt" | "integrate" | "dif" | "abs" | "cosec" | "sec" | "cot" | "arctan" | "arcsin" | "arccos" | "log10"
|
|
63
|
+
FUNC_NAME: "midpoint" | "ref" | "expect" | "covariance" | "variance" | "subs" | "try" | "limit" | "forall" | "limitpinf" | "imply" | "exist" | "len" | "sum" | "angle" | "line" | "sum2" | "charge" | "electricfield" | "perm" | "point" | "equationrhs" | "transpose" | "equationlhs" | "equation" | "error" | "covariance" | "variance" | "expect" | "mag" | "rad" | "laplace" | "diverge" | "pdif" | "gradient" | "curl" | "point1" | "point2" | "dot" | "point3" | "line1" | "line2" | "line3" | "sin" | "circumcenter" | "eqtri" | "linesegment" | "cos" | "tan" | "log" | "sqrt" | "integrate" | "dif" | "abs" | "cosec" | "sec" | "cot" | "arctan" | "arcsin" | "arccos" | "log10"
|
|
63
64
|
|
|
64
65
|
VARIABLE: /[a-z]/ | "nabla" | "pi" | "kc" | "hbar" | "em" | "ec" | "anot" | "false" | "true"
|
|
65
66
|
|
|
@@ -130,7 +131,7 @@ def parse(equation, funclist=None):
|
|
|
130
131
|
if tree_node.name == "pass_through":
|
|
131
132
|
return fxchange(tree_node.children[0])
|
|
132
133
|
return TreeNode(
|
|
133
|
-
"f_" + tree_node.name if tree_node.name in tmp3 + ["limitpinf", "limit", "try", "ref", "sqrt","imply","forall","exist","exclude","union","intersection","len","index","angle","charge","sum2","electricfield","line","point","sum","transpose","equationrhs","equationlhs","equation","covariance","variance","expect","error","laplace","dot","curl","pdif","diverge","gradient","rad","ge","le","gt","lt","eqtri","linesegment","midpoint","mag","point1","point2","point3","line1","line2","line3","log10","arcsin","arccos","arctan","list","cosec","sec","cot","equiv","or","not","and","circumcenter","eq","sub","add","sin","cos","tan","wmul","integrate","dif","pow","div","log","abs"] else "d_" + tree_node.name,
|
|
134
|
+
"f_" + tree_node.name if tree_node.name in tmp3 + ["limitpinf", "limit", "try", "ref", "sqrt","imply","forall","exist","exclude","union","intersection","len","index","angle","charge","sum2","electricfield","line","point","sum","transpose","equationrhs","equationlhs","equation","covariance","variance","expect","error","laplace","dot","curl","pdif","diverge","gradient","rad","ge","le","gt","lt","eqtri","linesegment","midpoint","mag","point1","point2","point3","line1","line2","line3","log10","arcsin","arccos","arctan","list","cosec","sec","cot","equiv","or","not","and","circumcenter","eq","sub","add","sin","cos","tan","mul", "cross", "wmul","integrate","dif","pow","div","log","abs"] else "d_" + tree_node.name,
|
|
134
135
|
[fxchange(child) for child in tree_node.children]
|
|
135
136
|
)
|
|
136
137
|
|
|
@@ -155,10 +156,4 @@ def parse(equation, funclist=None):
|
|
|
155
156
|
|
|
156
157
|
tree_node = rfx(tree_node)
|
|
157
158
|
tree_node = flatten_tree(tree_node)
|
|
158
|
-
if TreeNode.matmul == True:
|
|
159
|
-
TreeNode.matmul = False
|
|
160
|
-
tree_node = use(tree_form(str_form(tree_node).replace("f_w","f_")))
|
|
161
|
-
TreeNode.matmul = True
|
|
162
|
-
else:
|
|
163
|
-
tree_node = tree_form(str_form(tree_node).replace("f_w","f_"))
|
|
164
159
|
return tree_node
|
mathai/simplify.py
CHANGED
|
@@ -507,17 +507,10 @@ def solve3(eq):
|
|
|
507
507
|
def simplify(eq, basic=True):
|
|
508
508
|
if eq is None:
|
|
509
509
|
return None
|
|
510
|
-
orig = TreeNode.matmul
|
|
511
|
-
if TreeNode.matmul == True:
|
|
512
|
-
TreeNode.matmul = False
|
|
513
|
-
if TreeNode.matmul == False:
|
|
514
|
-
eq = use(tree_form(str_form(eq).replace("f_w","f_")))
|
|
515
|
-
|
|
516
510
|
if eq.name == "f_and" or eq.name == "f_not" or eq.name == "f_or":
|
|
517
511
|
new_children = []
|
|
518
512
|
for child in eq.children:
|
|
519
513
|
new_children.append(simplify(child))
|
|
520
|
-
TreeNode.matmul = orig
|
|
521
514
|
return TreeNode(eq.name, new_children)
|
|
522
515
|
if eq.name[2:] in "gt ge lt le eq".split(" "):
|
|
523
516
|
denom = eq.name != "f_eq"
|
|
@@ -530,11 +523,9 @@ def simplify(eq, basic=True):
|
|
|
530
523
|
value2 = {"ge":"le", "le":"ge", "gt":"lt", "lt":"gt", "eq":"eq"}[value2]
|
|
531
524
|
value2 = "f_"+value2
|
|
532
525
|
out = TreeNode(value2, [tmp, tree_form("d_0")])
|
|
533
|
-
TreeNode.matmul = orig
|
|
534
526
|
return out
|
|
535
527
|
eq = flatten_tree(eq)
|
|
536
528
|
if basic:
|
|
537
529
|
eq = convert_to_basic(eq)
|
|
538
530
|
eq = solve3(eq)
|
|
539
|
-
TreeNode.matmul = orig
|
|
540
531
|
return eq
|
mathai/statistics.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from .base import *
|
|
2
|
+
from .simplify import simplify
|
|
3
|
+
|
|
4
|
+
def expect(eq):
|
|
5
|
+
if eq.name == "f_expect":
|
|
6
|
+
if eq.children[0].name == "f_add":
|
|
7
|
+
eq = summation([item.fx("expect") for item in eq.children[0].children])
|
|
8
|
+
if eq.name == "f_expect":
|
|
9
|
+
out = []
|
|
10
|
+
keep = []
|
|
11
|
+
for child in eq.children:
|
|
12
|
+
if "v_-" in str_form(child) and child.name != "f_expect":
|
|
13
|
+
keep.append(child)
|
|
14
|
+
else:
|
|
15
|
+
out.append(child)
|
|
16
|
+
eq = simplify(product(out)*product(keep).fx("expect"))
|
|
17
|
+
if eq.name == "f_variance":
|
|
18
|
+
term = eq.children[0]
|
|
19
|
+
eq = (term**2).fx("expect") + term.fx("expect")**2
|
|
20
|
+
if eq.name == "f_covariance":
|
|
21
|
+
x, y = eq.children
|
|
22
|
+
eq = (x*y).fx("expect") - x.fx("expect")*y.fx("expect")
|
|
23
|
+
return TreeNode(eq.name, [expect(child) for child in eq.children])
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mathai
|
|
3
|
-
Version: 0.7.
|
|
3
|
+
Version: 0.7.3
|
|
4
4
|
Summary: Mathematics solving Ai tailored to NCERT
|
|
5
5
|
Home-page: https://github.com/infinity390/mathai4
|
|
6
|
-
Author: educated indians are having a low iq and are good for nothing
|
|
7
6
|
Requires-Python: >=3.7
|
|
8
7
|
Description-Content-Type: text/markdown
|
|
9
8
|
Requires-Dist: lark-parser
|
|
10
|
-
Dynamic: author
|
|
11
9
|
Dynamic: description
|
|
12
10
|
Dynamic: description-content-type
|
|
13
11
|
Dynamic: home-page
|
|
@@ -98,7 +96,7 @@ print(equation)
|
|
|
98
96
|
(cos(x)^2)+(sin(x)^2)
|
|
99
97
|
```
|
|
100
98
|
|
|
101
|
-
###
|
|
99
|
+
### simplify
|
|
102
100
|
It simplifies and cleans up a given math equation.
|
|
103
101
|
|
|
104
102
|
```python
|
|
@@ -117,7 +115,7 @@ printeq(equation)
|
|
|
117
115
|
|
|
118
116
|
### Demonstrations
|
|
119
117
|
|
|
120
|
-
#### Example Demonstration 1
|
|
118
|
+
#### Example Demonstration 1 (absolute value inequalities)
|
|
121
119
|
```python
|
|
122
120
|
from mathai import *
|
|
123
121
|
question_list_from_lecture = [
|
|
@@ -157,7 +155,7 @@ for item in question_list_from_lecture:
|
|
|
157
155
|
(-inf,-(7/3))
|
|
158
156
|
```
|
|
159
157
|
|
|
160
|
-
#### Example Demonstration 2
|
|
158
|
+
#### Example Demonstration 2 (trigonometry)
|
|
161
159
|
```python
|
|
162
160
|
from mathai import *
|
|
163
161
|
def nested_func(eq_node):
|
|
@@ -182,7 +180,7 @@ true
|
|
|
182
180
|
true
|
|
183
181
|
```
|
|
184
182
|
|
|
185
|
-
#### Example Demonstration 3
|
|
183
|
+
#### Example Demonstration 3 (integration)
|
|
186
184
|
```python
|
|
187
185
|
from mathai import *
|
|
188
186
|
|
|
@@ -237,3 +235,59 @@ cos(cos(x))
|
|
|
237
235
|
-((e^-(x^2))/2)
|
|
238
236
|
-(((8*sin((2*x)))-(12*x)-sin((4*x)))/32)
|
|
239
237
|
```
|
|
238
|
+
|
|
239
|
+
#### Example Demonstration 4 (derivation of hydrogen atom's ground state energy in electron volts using the variational principle in quantum physics)
|
|
240
|
+
```python
|
|
241
|
+
from mathai import *;
|
|
242
|
+
def auto_integration(eq):
|
|
243
|
+
for _ in range(3):
|
|
244
|
+
eq=dowhile(integrate_subs(eq),lambda x:integrate_summation(integrate_const(integrate_formula(simplify(expand(x))))));
|
|
245
|
+
out=integrate_clean(copy.deepcopy(eq));
|
|
246
|
+
if "f_integrate" not in str_form(out):return dowhile(out,lambda x:simplify(fraction(x)));
|
|
247
|
+
eq=integrate_byparts(eq);
|
|
248
|
+
return eq;
|
|
249
|
+
z,k,m,e1,hbar=map(lambda s:simplify(parse(s)),["1","8987551787","9109383701*10^(-40)","1602176634*10^(-28)","1054571817*10^(-43)"]);
|
|
250
|
+
pi,euler,r=tree_form("s_pi"),tree_form("s_e"),parse("r");a0=hbar**2/(k*e1**2*m);psi=((z**3/(pi*a0**3)).fx("sqrt"))*euler**(-(z/a0)*r);
|
|
251
|
+
laplace_psi=diff(r**2*diff(psi,r.name),r.name)/r**2;V=-(k*z*e1**2)/r;Hpsi=-hbar**2/(2*m)*laplace_psi+V*psi;
|
|
252
|
+
norm=lambda f:simplify(
|
|
253
|
+
limit3(limit2(expand(TreeNode("f_limitpinf",[auto_integration(TreeNode("f_integrate",[f*parse("4")*pi*r**2,r])),r]))))
|
|
254
|
+
-limit1(TreeNode("f_limit",[auto_integration(TreeNode("f_integrate",[f*parse("4")*pi*r**2,r])),r]))
|
|
255
|
+
);
|
|
256
|
+
print(compute(norm(psi*Hpsi)/(norm(psi**2)*e1)));
|
|
257
|
+
```
|
|
258
|
+
#### Output
|
|
259
|
+
|
|
260
|
+
```
|
|
261
|
+
-13.605693122882867
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
#### Example Demonstration 5 (boolean algebra)
|
|
265
|
+
```python
|
|
266
|
+
from mathai import *
|
|
267
|
+
print(logic_n(simplify(parse("~(p<->q)<->(~p<->q)"))))
|
|
268
|
+
print(logic_n(simplify(parse("(p->q)<->(~q->~p)"))))
|
|
269
|
+
```
|
|
270
|
+
#### Output
|
|
271
|
+
|
|
272
|
+
```
|
|
273
|
+
true
|
|
274
|
+
true
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
#### Example Demonstration 6 (limits)
|
|
278
|
+
```python
|
|
279
|
+
from mathai import *
|
|
280
|
+
limits = ["(e^(tan(x)) - 1 - tan(x)) / x^2", "sin(x)/x", "(1-cos(x))/x^2", "(sin(x)-x)/sin(x)^3"]
|
|
281
|
+
for q in limits:
|
|
282
|
+
q = fraction(simplify(TreeNode("f_limit",[parse(q),parse("x")])))
|
|
283
|
+
q = limit1(q)
|
|
284
|
+
print(q)
|
|
285
|
+
```
|
|
286
|
+
#### Output
|
|
287
|
+
|
|
288
|
+
```
|
|
289
|
+
1/2
|
|
290
|
+
1
|
|
291
|
+
1/2
|
|
292
|
+
-(1/6)
|
|
293
|
+
```
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
mathai/__init__.py,sha256=
|
|
1
|
+
mathai/__init__.py,sha256=elVGU1vjxbvzY3CQ8M5kzj5i6o8YyCsdb2vw-kSxTN0,1575
|
|
2
2
|
mathai/apart.py,sha256=VSS3khE9PNuxiRvdU5JDl4IN-KJBSIFjwR17pkhviXI,4197
|
|
3
|
-
mathai/base.py,sha256=
|
|
3
|
+
mathai/base.py,sha256=XNmXWADG7mA4AeyFbCUsjBvUzDnw8AzWscX0Cc3GjvA,14854
|
|
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=AEX-inLztL6i7VWSu0Zw1z9OVwhomrnoqGrQiDuoPQE,2502
|
|
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,17 +12,18 @@ 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=MFe6tUL4a3jYuP13fXWGwER_34AbqfoOK5kHwVHfsKk,7169
|
|
16
16
|
mathai/ode.py,sha256=zxxTXAOpt7oSsfpgI4vHsCWKXevmM96ZOBZWWs-vj8Y,4801
|
|
17
|
-
mathai/parser.py,sha256=
|
|
17
|
+
mathai/parser.py,sha256=FcjOTM_2-YFqPNS9EyZfo76pa4CedDJCbcs8wOXc_uU,7130
|
|
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
|
-
mathai/simplify.py,sha256=
|
|
20
|
+
mathai/simplify.py,sha256=bCtYyLyc3pY04hta-MU62ii5-O4zUwGHjs1Q4WBYEvY,19680
|
|
21
|
+
mathai/statistics.py,sha256=ifmaXFzRc6vIgPFWP-9EDfZZYmmMGw-WEKhoQZUaHXo,884
|
|
21
22
|
mathai/structure.py,sha256=wrU7kqphSN7CqaVffyHHXD2-3t5My_Z_TtYFoUe_lTU,4099
|
|
22
23
|
mathai/tool.py,sha256=ozcXTXLbKUnyPM9r9kz9M43YA2CBcWezcqLZfEs8rpc,6051
|
|
23
24
|
mathai/trig.py,sha256=fnBbfiopcQzFg4ya1BoO5M0X_aCBnse2bjnKh1juw4I,11223
|
|
24
25
|
mathai/univariate_inequality.py,sha256=LPFdWgC1y5zBwnsy1wwZxj-yP_SbqFDhCmTTzhuwoiY,16469
|
|
25
|
-
mathai-0.7.
|
|
26
|
-
mathai-0.7.
|
|
27
|
-
mathai-0.7.
|
|
28
|
-
mathai-0.7.
|
|
26
|
+
mathai-0.7.3.dist-info/METADATA,sha256=O-xwE15PJRC2oY1xe7-JWyBlDlvcIcCwSxlcDNwdk5s,7735
|
|
27
|
+
mathai-0.7.3.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
28
|
+
mathai-0.7.3.dist-info/top_level.txt,sha256=ROP4l3OhGYw3ihkQGASr18xM9GsK4z3_6whV5AyXLwE,7
|
|
29
|
+
mathai-0.7.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|