absorb coefficients into sympy expr

This commit is contained in:
Marcell Vazquez-Chanlatte 2016-07-08 20:59:56 -07:00
parent fc6be7b80b
commit 619c2c6524
2 changed files with 5 additions and 18 deletions

15
stl.py
View file

@ -17,12 +17,9 @@ t_sym = Symbol('t', positive=True)
class LinEq(namedtuple("LinEquality", ["terms", "op", "const"])):
def __repr__(self):
n = len(self.terms)
rep = "{}"
if n > 1:
rep += " + {}"*(n - 1)
rep += " {op} {c}"
return rep.format(*self.terms, op=self.op, c=self.const)
rep = "{lhs} {op} {c}"
lhs = sum(t.id for t in self.terms)
return rep.format(lhs=lhs, op=self.op, c=self.const)
def children(self):
return []
@ -34,12 +31,6 @@ class Var(namedtuple("Var", ["kind", "id", "time"])):
return "{i}{t}".format(k=self.kind.name, i=self.id, t=time_str)
class Term(namedtuple("Term", ["coeff", "var"])):
def __repr__(self):
coeff = str(self.coeff) + "*" if self.coeff != 1 else ""
return "{c}{v}".format(c=coeff, v=self.var)
class Interval(namedtuple('I', ['lower', 'upper'])):
def __repr__(self):
return "[{},{}]".format(self.lower, self.upper)