mathai 0.7.2__tar.gz → 0.7.4__tar.gz

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.
Files changed (35) hide show
  1. {mathai-0.7.2 → mathai-0.7.4}/PKG-INFO +2 -2
  2. {mathai-0.7.2 → mathai-0.7.4}/README.md +1 -1
  3. {mathai-0.7.2 → mathai-0.7.4}/mathai/__init__.py +2 -0
  4. {mathai-0.7.2 → mathai-0.7.4}/mathai/base.py +2 -29
  5. mathai-0.7.4/mathai/expand.py +75 -0
  6. {mathai-0.7.2 → mathai-0.7.4}/mathai/matrix.py +1 -4
  7. {mathai-0.7.2 → mathai-0.7.4}/mathai/parser.py +4 -9
  8. {mathai-0.7.2 → mathai-0.7.4}/mathai/simplify.py +0 -9
  9. mathai-0.7.4/mathai/statistics.py +23 -0
  10. {mathai-0.7.2 → mathai-0.7.4}/mathai.egg-info/PKG-INFO +2 -2
  11. {mathai-0.7.2 → mathai-0.7.4}/mathai.egg-info/SOURCES.txt +1 -0
  12. {mathai-0.7.2 → mathai-0.7.4}/setup.py +1 -1
  13. mathai-0.7.2/mathai/expand.py +0 -175
  14. {mathai-0.7.2 → mathai-0.7.4}/mathai/apart.py +0 -0
  15. {mathai-0.7.2 → mathai-0.7.4}/mathai/bivariate_inequality.py +0 -0
  16. {mathai-0.7.2 → mathai-0.7.4}/mathai/console.py +0 -0
  17. {mathai-0.7.2 → mathai-0.7.4}/mathai/diff.py +0 -0
  18. {mathai-0.7.2 → mathai-0.7.4}/mathai/factor.py +0 -0
  19. {mathai-0.7.2 → mathai-0.7.4}/mathai/fraction.py +0 -0
  20. {mathai-0.7.2 → mathai-0.7.4}/mathai/integrate.py +0 -0
  21. {mathai-0.7.2 → mathai-0.7.4}/mathai/inverse.py +0 -0
  22. {mathai-0.7.2 → mathai-0.7.4}/mathai/limit.py +0 -0
  23. {mathai-0.7.2 → mathai-0.7.4}/mathai/linear.py +0 -0
  24. {mathai-0.7.2 → mathai-0.7.4}/mathai/logic.py +0 -0
  25. {mathai-0.7.2 → mathai-0.7.4}/mathai/ode.py +0 -0
  26. {mathai-0.7.2 → mathai-0.7.4}/mathai/parsetab.py +0 -0
  27. {mathai-0.7.2 → mathai-0.7.4}/mathai/printeq.py +0 -0
  28. {mathai-0.7.2 → mathai-0.7.4}/mathai/structure.py +0 -0
  29. {mathai-0.7.2 → mathai-0.7.4}/mathai/tool.py +0 -0
  30. {mathai-0.7.2 → mathai-0.7.4}/mathai/trig.py +0 -0
  31. {mathai-0.7.2 → mathai-0.7.4}/mathai/univariate_inequality.py +0 -0
  32. {mathai-0.7.2 → mathai-0.7.4}/mathai.egg-info/dependency_links.txt +0 -0
  33. {mathai-0.7.2 → mathai-0.7.4}/mathai.egg-info/requires.txt +0 -0
  34. {mathai-0.7.2 → mathai-0.7.4}/mathai.egg-info/top_level.txt +0 -0
  35. {mathai-0.7.2 → mathai-0.7.4}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mathai
3
- Version: 0.7.2
3
+ Version: 0.7.4
4
4
  Summary: Mathematics solving Ai tailored to NCERT
5
5
  Home-page: https://github.com/infinity390/mathai4
6
6
  Requires-Python: >=3.7
@@ -96,7 +96,7 @@ print(equation)
96
96
  (cos(x)^2)+(sin(x)^2)
97
97
  ```
98
98
 
99
- ### solve, simplify
99
+ ### simplify
100
100
  It simplifies and cleans up a given math equation.
101
101
 
102
102
  ```python
@@ -81,7 +81,7 @@ print(equation)
81
81
  (cos(x)^2)+(sin(x)^2)
82
82
  ```
83
83
 
84
- ### solve, simplify
84
+ ### simplify
85
85
  It simplifies and cleans up a given math equation.
86
86
 
87
87
  ```python
@@ -51,3 +51,5 @@ from .base import *
51
51
  from .tool import enclose_const
52
52
  from .tool import poly_simplify
53
53
  from .tool import longdiv
54
+
55
+ from .statistics import expect
@@ -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 (name == "f_mul" and TreeNode.matmul is None):
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":"*", "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": "?"}
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():
@@ -0,0 +1,75 @@
1
+ from .base import *
2
+ from .simplify import simplify
3
+ import itertools
4
+
5
+ def expand_nc(expr, label="f_mul"):
6
+ """
7
+ Expand expression where:
8
+ - f_add is commutative
9
+ - label (@) is NON-commutative
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)
53
+
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:]
59
+
60
+ terms = []
61
+ for term in f.children:
62
+ new_factors = left + [term] + right
63
+ terms.append(
64
+ expand_nc(TreeNode(label, new_factors), label)
65
+ )
66
+
67
+ return TreeNode("f_add", terms)
68
+
69
+ # no addition inside → return as-is
70
+ return TreeNode(label, factors)
71
+
72
+
73
+ def expand(eq, over="*"):
74
+ over = {"@": "f_wmul", ".":"f_dot", "*":"f_mul"}[over]
75
+ return expand_nc(eq, over)
@@ -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
- if TreeNode.matmul == True:
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)
@@ -37,7 +37,8 @@ grammar = """
37
37
  | arithmetic "-" term -> sub
38
38
  | term
39
39
 
40
- ?term: term "*" power -> wmul
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
@@ -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
@@ -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,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mathai
3
- Version: 0.7.2
3
+ Version: 0.7.4
4
4
  Summary: Mathematics solving Ai tailored to NCERT
5
5
  Home-page: https://github.com/infinity390/mathai4
6
6
  Requires-Python: >=3.7
@@ -96,7 +96,7 @@ print(equation)
96
96
  (cos(x)^2)+(sin(x)^2)
97
97
  ```
98
98
 
99
- ### solve, simplify
99
+ ### simplify
100
100
  It simplifies and cleans up a given math equation.
101
101
 
102
102
  ```python
@@ -20,6 +20,7 @@ mathai/parser.py
20
20
  mathai/parsetab.py
21
21
  mathai/printeq.py
22
22
  mathai/simplify.py
23
+ mathai/statistics.py
23
24
  mathai/structure.py
24
25
  mathai/tool.py
25
26
  mathai/trig.py
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="mathai",
5
- version="0.7.2",
5
+ version="0.7.4",
6
6
  description="Mathematics solving Ai tailored to NCERT",
7
7
  long_description=open("README.md").read(),
8
8
  long_description_content_type="text/markdown",
@@ -1,175 +0,0 @@
1
- from .base import *
2
- from .simplify import simplify
3
- import itertools
4
-
5
- def eliminate_powers(node):
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):
43
- """
44
- Performs exactly ONE distributive expansion.
45
- Deepest-first (post-order).
46
- """
47
-
48
- # ---- recurse FIRST (this is the fix) ----
49
- for i, c in enumerate(node.children):
50
- new, changed = expand_once(c)
51
- if changed:
52
- node.children[i] = new
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:]
61
-
62
- terms = []
63
- for t in child.children:
64
- prod = t
65
- for r in right:
66
- prod = prod * r
67
- for l in reversed(left):
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
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, []))
153
-
154
- # =====================================================
155
- # Phase 3: Global fixed-point driver
156
- # =====================================================
157
-
158
- def expand(eq):
159
- orig = TreeNode.matmul
160
- if TreeNode.matmul is None:
161
- return _expand2(eq)
162
- eq = simplify(eq)
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
175
- return eq
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes