mathai 0.4.8__py3-none-any.whl → 0.7.2__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 +9 -8
- mathai/base.py +132 -34
- mathai/bivariate_inequality.py +317 -0
- mathai/diff.py +3 -3
- mathai/expand.py +159 -80
- mathai/factor.py +45 -21
- mathai/fraction.py +2 -2
- mathai/integrate.py +38 -19
- mathai/inverse.py +4 -4
- mathai/limit.py +94 -70
- mathai/linear.py +90 -81
- mathai/logic.py +7 -1
- mathai/matrix.py +228 -0
- mathai/parser.py +13 -7
- mathai/parsetab.py +61 -0
- mathai/printeq.py +12 -9
- mathai/simplify.py +511 -369
- mathai/structure.py +2 -2
- mathai/tool.py +2 -2
- mathai/trig.py +42 -25
- mathai/univariate_inequality.py +78 -30
- mathai-0.7.2.dist-info/METADATA +293 -0
- mathai-0.7.2.dist-info/RECORD +28 -0
- {mathai-0.4.8.dist-info → mathai-0.7.2.dist-info}/WHEEL +1 -1
- mathai-0.4.8.dist-info/METADATA +0 -234
- mathai-0.4.8.dist-info/RECORD +0 -25
- {mathai-0.4.8.dist-info → mathai-0.7.2.dist-info}/top_level.txt +0 -0
mathai/parser.py
CHANGED
|
@@ -37,7 +37,7 @@ grammar = """
|
|
|
37
37
|
| arithmetic "-" term -> sub
|
|
38
38
|
| term
|
|
39
39
|
|
|
40
|
-
?term: term "*" power ->
|
|
40
|
+
?term: term "*" power -> wmul
|
|
41
41
|
| term "/" power -> div
|
|
42
42
|
| term "." power -> dot
|
|
43
43
|
| power
|
|
@@ -59,7 +59,7 @@ grammar = """
|
|
|
59
59
|
| ESCAPED_STRING -> string
|
|
60
60
|
| CAPITAL_ID -> matrix
|
|
61
61
|
|
|
62
|
-
FUNC_NAME: "midpoint" | "ref" | "subs" | "try" | "forall" | "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"
|
|
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
63
|
|
|
64
64
|
VARIABLE: /[a-z]/ | "nabla" | "pi" | "kc" | "hbar" | "em" | "ec" | "anot" | "false" | "true"
|
|
65
65
|
|
|
@@ -85,7 +85,7 @@ def parse(equation, funclist=None):
|
|
|
85
85
|
|
|
86
86
|
parser_main = Lark(grammar2, start='start', parser='lalr')
|
|
87
87
|
parse_tree = parser_main.parse(equation)
|
|
88
|
-
|
|
88
|
+
|
|
89
89
|
# Convert Lark tree to TreeNode
|
|
90
90
|
def convert_to_treenode(parse_tree):
|
|
91
91
|
if isinstance(parse_tree, Tree):
|
|
@@ -130,7 +130,7 @@ def parse(equation, funclist=None):
|
|
|
130
130
|
if tree_node.name == "pass_through":
|
|
131
131
|
return fxchange(tree_node.children[0])
|
|
132
132
|
return TreeNode(
|
|
133
|
-
"f_" + tree_node.name if tree_node.name in tmp3 + ["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","
|
|
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
134
|
[fxchange(child) for child in tree_node.children]
|
|
135
135
|
)
|
|
136
136
|
|
|
@@ -146,13 +146,19 @@ def parse(equation, funclist=None):
|
|
|
146
146
|
for i, c in enumerate([chr(x+ord("A")) for x in range(0,26)]):
|
|
147
147
|
tree_node = replace(tree_node, tree_form("d_"+c), tree_form("v_-"+str(i+1)))
|
|
148
148
|
tree_node = replace(tree_node, tree_form("f_"+c), tree_form("v_-"+str(i+1)))
|
|
149
|
-
|
|
150
|
-
# Final recursive replacements
|
|
149
|
+
|
|
151
150
|
def rfx(tree_node):
|
|
152
151
|
if tree_node.name[:3] == "d_c":
|
|
153
152
|
return tree_form("v_" + str(int(tree_node.name[3:])+100))
|
|
154
153
|
tree_node.children = [rfx(child) for child in tree_node.children]
|
|
155
154
|
return tree_node
|
|
156
|
-
|
|
155
|
+
|
|
157
156
|
tree_node = rfx(tree_node)
|
|
157
|
+
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_"))
|
|
158
164
|
return tree_node
|
mathai/parsetab.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
|
|
2
|
+
# parsetab.py
|
|
3
|
+
# This file is automatically generated. Do not edit.
|
|
4
|
+
# pylint: disable=W,C,R
|
|
5
|
+
_tabversion = '3.10'
|
|
6
|
+
|
|
7
|
+
_lr_method = 'LALR'
|
|
8
|
+
|
|
9
|
+
_lr_signature = 'leftEQUIVleftIMPLYleftORleftANDleftEQLTGTLEGEleftPLUSMINUSleftTIMESDIVDOTrightPOWrightNOTUMINUSUPLUSAND CAPITAL_ID CNUMBER COMMA DIV DOT EQ EQUIV GE GT IMPLY LBRACK LE LPAREN LT MINUS NOT NUMBER OR PLUS POW RBRACK RPAREN STRING TIMES VARIABLEstart : exprexpr : expr EQUIV exprexpr : expr IMPLY exprexpr : expr OR exprexpr : expr AND exprexpr : NOT exprexpr : expr EQ expr\n | expr LT expr\n | expr GT expr\n | expr LE expr\n | expr GE exprexpr : expr PLUS expr\n | expr MINUS exprexpr : expr TIMES expr\n | expr DIV expr\n | expr DOT exprexpr : expr POW exprexpr : MINUS expr %prec UMINUSexpr : PLUS expr %prec UPLUSexpr : atomexpr : LPAREN expr RPARENexpr : LBRACK expr_list RBRACKexpr : LBRACK RBRACKexpr_list : expr_list COMMA exprexpr_list : exprexpr : VARIABLE LPAREN expr_list RPARENatom : VARIABLE\n | CAPITAL_ID\n | NUMBER\n | CNUMBER\n | STRING'
|
|
10
|
+
|
|
11
|
+
_lr_action_items = {'NOT':([0,3,4,5,7,8,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,36,54,],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,]),'MINUS':([0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,56,57,],[5,24,5,5,5,-20,5,5,-27,-28,-29,-30,-31,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,-6,-19,-18,24,-23,24,5,24,24,24,24,24,24,24,24,24,-12,-13,-14,-15,-16,-17,-21,-22,5,24,-26,]),'PLUS':([0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,56,57,],[4,23,4,4,4,-20,4,4,-27,-28,-29,-30,-31,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,-6,-19,-18,23,-23,23,4,23,23,23,23,23,23,23,23,23,-12,-13,-14,-15,-16,-17,-21,-22,4,23,-26,]),'LPAREN':([0,3,4,5,7,8,9,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,36,54,],[7,7,7,7,7,7,36,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,]),'LBRACK':([0,3,4,5,7,8,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,36,54,],[8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,]),'VARIABLE':([0,3,4,5,7,8,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,36,54,],[9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,]),'CAPITAL_ID':([0,3,4,5,7,8,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,36,54,],[10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,]),'NUMBER':([0,3,4,5,7,8,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,36,54,],[11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,]),'CNUMBER':([0,3,4,5,7,8,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,36,54,],[12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,]),'STRING':([0,3,4,5,7,8,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,36,54,],[13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,]),'$end':([1,2,6,9,10,11,12,13,29,30,31,34,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,57,],[0,-1,-20,-27,-28,-29,-30,-31,-6,-19,-18,-23,-2,-3,-4,-5,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-21,-22,-26,]),'EQUIV':([2,6,9,10,11,12,13,29,30,31,32,34,35,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,56,57,],[14,-20,-27,-28,-29,-30,-31,-6,-19,-18,14,-23,14,-2,-3,-4,-5,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-21,-22,14,-26,]),'IMPLY':([2,6,9,10,11,12,13,29,30,31,32,34,35,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,56,57,],[15,-20,-27,-28,-29,-30,-31,-6,-19,-18,15,-23,15,15,-3,-4,-5,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-21,-22,15,-26,]),'OR':([2,6,9,10,11,12,13,29,30,31,32,34,35,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,56,57,],[16,-20,-27,-28,-29,-30,-31,-6,-19,-18,16,-23,16,16,16,-4,-5,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-21,-22,16,-26,]),'AND':([2,6,9,10,11,12,13,29,30,31,32,34,35,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,56,57,],[17,-20,-27,-28,-29,-30,-31,-6,-19,-18,17,-23,17,17,17,17,-5,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-21,-22,17,-26,]),'EQ':([2,6,9,10,11,12,13,29,30,31,32,34,35,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,56,57,],[18,-20,-27,-28,-29,-30,-31,-6,-19,-18,18,-23,18,18,18,18,18,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-21,-22,18,-26,]),'LT':([2,6,9,10,11,12,13,29,30,31,32,34,35,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,56,57,],[19,-20,-27,-28,-29,-30,-31,-6,-19,-18,19,-23,19,19,19,19,19,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-21,-22,19,-26,]),'GT':([2,6,9,10,11,12,13,29,30,31,32,34,35,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,56,57,],[20,-20,-27,-28,-29,-30,-31,-6,-19,-18,20,-23,20,20,20,20,20,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-21,-22,20,-26,]),'LE':([2,6,9,10,11,12,13,29,30,31,32,34,35,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,56,57,],[21,-20,-27,-28,-29,-30,-31,-6,-19,-18,21,-23,21,21,21,21,21,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-21,-22,21,-26,]),'GE':([2,6,9,10,11,12,13,29,30,31,32,34,35,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,56,57,],[22,-20,-27,-28,-29,-30,-31,-6,-19,-18,22,-23,22,22,22,22,22,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-21,-22,22,-26,]),'TIMES':([2,6,9,10,11,12,13,29,30,31,32,34,35,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,56,57,],[25,-20,-27,-28,-29,-30,-31,-6,-19,-18,25,-23,25,25,25,25,25,25,25,25,25,25,25,25,-14,-15,-16,-17,-21,-22,25,-26,]),'DIV':([2,6,9,10,11,12,13,29,30,31,32,34,35,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,56,57,],[26,-20,-27,-28,-29,-30,-31,-6,-19,-18,26,-23,26,26,26,26,26,26,26,26,26,26,26,26,-14,-15,-16,-17,-21,-22,26,-26,]),'DOT':([2,6,9,10,11,12,13,29,30,31,32,34,35,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,56,57,],[27,-20,-27,-28,-29,-30,-31,-6,-19,-18,27,-23,27,27,27,27,27,27,27,27,27,27,27,27,-14,-15,-16,-17,-21,-22,27,-26,]),'POW':([2,6,9,10,11,12,13,29,30,31,32,34,35,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,56,57,],[28,-20,-27,-28,-29,-30,-31,-6,-19,-18,28,-23,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,-21,-22,28,-26,]),'RPAREN':([6,9,10,11,12,13,29,30,31,32,34,35,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,55,56,57,],[-20,-27,-28,-29,-30,-31,-6,-19,-18,52,-23,-25,-2,-3,-4,-5,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-21,-22,57,-24,-26,]),'RBRACK':([6,8,9,10,11,12,13,29,30,31,33,34,35,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,56,57,],[-20,34,-27,-28,-29,-30,-31,-6,-19,-18,53,-23,-25,-2,-3,-4,-5,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-21,-22,-24,-26,]),'COMMA':([6,9,10,11,12,13,29,30,31,33,34,35,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,55,56,57,],[-20,-27,-28,-29,-30,-31,-6,-19,-18,54,-23,-25,-2,-3,-4,-5,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-21,-22,54,-24,-26,]),}
|
|
12
|
+
|
|
13
|
+
_lr_action = {}
|
|
14
|
+
for _k, _v in _lr_action_items.items():
|
|
15
|
+
for _x,_y in zip(_v[0],_v[1]):
|
|
16
|
+
if not _x in _lr_action: _lr_action[_x] = {}
|
|
17
|
+
_lr_action[_x][_k] = _y
|
|
18
|
+
del _lr_action_items
|
|
19
|
+
|
|
20
|
+
_lr_goto_items = {'start':([0,],[1,]),'expr':([0,3,4,5,7,8,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,36,54,],[2,29,30,31,32,35,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,35,56,]),'atom':([0,3,4,5,7,8,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,36,54,],[6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,]),'expr_list':([8,36,],[33,55,]),}
|
|
21
|
+
|
|
22
|
+
_lr_goto = {}
|
|
23
|
+
for _k, _v in _lr_goto_items.items():
|
|
24
|
+
for _x, _y in zip(_v[0], _v[1]):
|
|
25
|
+
if not _x in _lr_goto: _lr_goto[_x] = {}
|
|
26
|
+
_lr_goto[_x][_k] = _y
|
|
27
|
+
del _lr_goto_items
|
|
28
|
+
_lr_productions = [
|
|
29
|
+
("S' -> start","S'",1,None,None,None),
|
|
30
|
+
('start -> expr','start',1,'p_start','parser.py',98),
|
|
31
|
+
('expr -> expr EQUIV expr','expr',3,'p_expr_equiv','parser.py',105),
|
|
32
|
+
('expr -> expr IMPLY expr','expr',3,'p_expr_imply','parser.py',109),
|
|
33
|
+
('expr -> expr OR expr','expr',3,'p_expr_or','parser.py',113),
|
|
34
|
+
('expr -> expr AND expr','expr',3,'p_expr_and','parser.py',117),
|
|
35
|
+
('expr -> NOT expr','expr',2,'p_expr_not','parser.py',121),
|
|
36
|
+
('expr -> expr EQ expr','expr',3,'p_expr_cmp','parser.py',128),
|
|
37
|
+
('expr -> expr LT expr','expr',3,'p_expr_cmp','parser.py',129),
|
|
38
|
+
('expr -> expr GT expr','expr',3,'p_expr_cmp','parser.py',130),
|
|
39
|
+
('expr -> expr LE expr','expr',3,'p_expr_cmp','parser.py',131),
|
|
40
|
+
('expr -> expr GE expr','expr',3,'p_expr_cmp','parser.py',132),
|
|
41
|
+
('expr -> expr PLUS expr','expr',3,'p_expr_add','parser.py',146),
|
|
42
|
+
('expr -> expr MINUS expr','expr',3,'p_expr_add','parser.py',147),
|
|
43
|
+
('expr -> expr TIMES expr','expr',3,'p_expr_mul','parser.py',154),
|
|
44
|
+
('expr -> expr DIV expr','expr',3,'p_expr_mul','parser.py',155),
|
|
45
|
+
('expr -> expr DOT expr','expr',3,'p_expr_mul','parser.py',156),
|
|
46
|
+
('expr -> expr POW expr','expr',3,'p_expr_pow','parser.py',165),
|
|
47
|
+
('expr -> MINUS expr','expr',2,'p_expr_uminus','parser.py',172),
|
|
48
|
+
('expr -> PLUS expr','expr',2,'p_expr_uplus','parser.py',176),
|
|
49
|
+
('expr -> atom','expr',1,'p_expr_atom','parser.py',183),
|
|
50
|
+
('expr -> LPAREN expr RPAREN','expr',3,'p_expr_paren','parser.py',187),
|
|
51
|
+
('expr -> LBRACK expr_list RBRACK','expr',3,'p_expr_list','parser.py',191),
|
|
52
|
+
('expr -> LBRACK RBRACK','expr',2,'p_expr_list_single','parser.py',195),
|
|
53
|
+
('expr_list -> expr_list COMMA expr','expr_list',3,'p_expr_list_list','parser.py',199),
|
|
54
|
+
('expr_list -> expr','expr_list',1,'p_expr_list_item','parser.py',203),
|
|
55
|
+
('expr -> VARIABLE LPAREN expr_list RPAREN','expr',4,'p_expr_func','parser.py',207),
|
|
56
|
+
('atom -> VARIABLE','atom',1,'p_atom_var','parser.py',214),
|
|
57
|
+
('atom -> CAPITAL_ID','atom',1,'p_atom_var','parser.py',215),
|
|
58
|
+
('atom -> NUMBER','atom',1,'p_atom_var','parser.py',216),
|
|
59
|
+
('atom -> CNUMBER','atom',1,'p_atom_var','parser.py',217),
|
|
60
|
+
('atom -> STRING','atom',1,'p_atom_var','parser.py',218),
|
|
61
|
+
]
|
mathai/printeq.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from .base import *
|
|
2
|
-
from .
|
|
2
|
+
from .factor import merge_sqrt
|
|
3
|
+
from .simplify import simplify
|
|
3
4
|
import copy
|
|
4
5
|
from fractions import Fraction
|
|
5
6
|
def abstractexpr(eq):
|
|
@@ -11,24 +12,26 @@ def abstractexpr(eq):
|
|
|
11
12
|
|
|
12
13
|
lst = factor_generation(eq)
|
|
13
14
|
deno = [item.children[0]**int(item.children[1].name[3:]) for item in lst if item.name == "f_pow" and item.children[1].name[:3] == "d_-"]
|
|
14
|
-
if eq.name == "f_mul" and any(item
|
|
15
|
-
return
|
|
15
|
+
if eq.name == "f_mul" and any(frac(item) is not None and frac(item) < 0 for item in lst):
|
|
16
|
+
return simplify(-eq, False).fx("neg")
|
|
16
17
|
if deno != []:
|
|
17
18
|
|
|
18
19
|
num = [item for item in lst if item.name != "f_pow" or item.children[1].name[:3] != "d_-"]
|
|
19
20
|
if num == []:
|
|
20
21
|
num = [tree_form("d_1")]
|
|
21
|
-
return TreeNode("f_div", [
|
|
22
|
+
return TreeNode("f_div", [simplify(product(num), False), simplify(product(deno), False)])
|
|
22
23
|
|
|
23
24
|
|
|
24
25
|
return TreeNode(eq.name, [abstractexpr(child) for child in eq.children])
|
|
25
26
|
|
|
26
27
|
def printeq_str(eq):
|
|
27
|
-
|
|
28
|
+
if eq is None:
|
|
29
|
+
return None
|
|
30
|
+
eq = merge_sqrt(eq)
|
|
31
|
+
return string_equation(str_form(dowhile(eq, abstractexpr)))
|
|
32
|
+
def printeq_obj(self):
|
|
33
|
+
return printeq_str(self)
|
|
28
34
|
|
|
29
35
|
def printeq(eq):
|
|
30
36
|
print(printeq_str(eq))
|
|
31
|
-
|
|
32
|
-
def printeq_log(lst):
|
|
33
|
-
for item in lst:
|
|
34
|
-
print(" "*item[0] + item[1])
|
|
37
|
+
TreeNode.__repr__ = printeq_obj
|