solve left parenthesis issue
This commit is contained in:
parent
67efaaee62
commit
0545d73751
@ -149,7 +149,8 @@ class Operator(str):
|
||||
""" Add parenthesis for left operand if necessary """
|
||||
ans = opl
|
||||
try:
|
||||
if opl.mainOp == op.sub1:
|
||||
# TODO: Je pige pas pourquoi quand on enlève .name ça marche plus... |lun. avril 27 19:07:24 CEST 2015
|
||||
if opl.mainOp.name == op.sub1.name:
|
||||
ans = opl
|
||||
elif opl.mainOp.priority < self.priority:
|
||||
ans = flatten_list(["(", opl, ")"])
|
||||
@ -163,7 +164,7 @@ class Operator(str):
|
||||
return ans
|
||||
|
||||
def r_parenthesis(self, op, str_join=False):
|
||||
""" Add parenthesis for left operand if necessary """
|
||||
""" Add parenthesis for rigth operand if necessary """
|
||||
# TODO: /!\ Parenthèses pour -2abc et l'opérateur * |lun. mars 9 19:02:32 CET 2015
|
||||
try:
|
||||
if op.mainOp.priority < self.priority:
|
||||
@ -212,6 +213,12 @@ def operatorize(fun):
|
||||
def mod_fun(self, *args):
|
||||
ans = fun(self, *args)
|
||||
|
||||
def _eq(op1, op2):
|
||||
""" op1 == op2 """
|
||||
return op1.name == op2.name == name and op1.arity == op2.arity
|
||||
|
||||
ans["__eq__"] = _eq
|
||||
|
||||
new_op = Operator(ans["operator"])
|
||||
for (attr, value) in ans.items():
|
||||
if hasattr(value, '__call__'):
|
||||
@ -603,18 +610,8 @@ if __name__ == '__main__':
|
||||
#print("\t op.can_be_operator('+') :" + str(op.can_be_operator('+')))
|
||||
#print("\t op.can_be_operator('t') :" + str(op.can_be_operator('t')))
|
||||
|
||||
from .render import tex
|
||||
print(tex([-2, 3, op.add ]))
|
||||
print("-----------------")
|
||||
print(tex([-2, 3, op.mul ]))
|
||||
print("-----------------")
|
||||
from .polynom import Polynom
|
||||
print(tex([Polynom([1,2,3]), 2, op.mul]))
|
||||
print("-----------------")
|
||||
from .fraction import Fraction
|
||||
print(tex([2, Fraction(1,2), op.mul]))
|
||||
print("-----------------")
|
||||
|
||||
print("op.sub.__dict__ -> ", op.sub.__dict__)
|
||||
print(op.sub == op.sub1)
|
||||
#import doctest
|
||||
#doctest.testmod()
|
||||
|
||||
|
@ -74,11 +74,16 @@ p2i = Render(p2i_render)
|
||||
|
||||
if __name__ == '__main__':
|
||||
from .operator import op
|
||||
exp = [ 2, 3, op.add, 4, op.mul]
|
||||
print(exp)
|
||||
print("txt(exp) :" + str(txt(exp)))
|
||||
print("tex(exp) :" + str(tex(exp)))
|
||||
print("p2i(exp) :" + str(p2i(exp)))
|
||||
from itertools import permutations
|
||||
from pymath import Polynom
|
||||
from pymath import Expression
|
||||
coefs_p = [[(i-2),(j-2)] for i,j in permutations(range(3),2)]
|
||||
coefs_q = [[2*(i-2),2*(j-2)] for i,j in permutations(range(3),2)]
|
||||
l_p = [Polynom(i) for i in coefs_p]
|
||||
l_q = [Polynom(i) for i in coefs_q]
|
||||
operations = [Expression([l_p[i],l_q[j],op.mul]) for i,j in permutations(range(len(coefs_p)),2)]
|
||||
for i in operations:
|
||||
print(i)
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user