make variables sympy Symbols + more general names

This commit is contained in:
Marcell Vazquez-Chanlatte 2016-07-08 20:40:53 -07:00
parent 7a73554525
commit fc6be7b80b
2 changed files with 6 additions and 4 deletions

2
stl.py
View file

@ -31,7 +31,7 @@ class LinEq(namedtuple("LinEquality", ["terms", "op", "const"])):
class Var(namedtuple("Var", ["kind", "id", "time"])): class Var(namedtuple("Var", ["kind", "id", "time"])):
def __repr__(self): def __repr__(self):
time_str = "[{}]".format(self.time) time_str = "[{}]".format(self.time)
return "{k}{i}{t}".format(k=self.kind.name, i=self.id, t=time_str) return "{i}{t}".format(k=self.kind.name, i=self.id, t=time_str)
class Term(namedtuple("Term", ["coeff", "var"])): class Term(namedtuple("Term", ["coeff", "var"])):

View file

@ -22,6 +22,8 @@ from funcy import flatten
import numpy as np import numpy as np
from lenses import lens from lenses import lens
from sympy import Symbol
from stl import stl from stl import stl
STL_GRAMMAR = Grammar(u''' STL_GRAMMAR = Grammar(u'''
@ -54,7 +56,7 @@ prime = "'"
pm = "+" / "-" pm = "+" / "-"
dt = "dt" dt = "dt"
unbound = "?" unbound = "?"
id = ("x" / "u" / "w") ~r"\d+" id = ("x" / "u" / "w") ~r"[a-zA-z\d]*"
const = ~r"[\+\-]?\d*(\.\d+)?" const = ~r"[\+\-]?\d*(\.\d+)?"
op = ">=" / "<=" / "<" / ">" / "=" op = ">=" / "<=" / "<" / ">" / "="
_ = ~r"\s"+ _ = ~r"\s"+
@ -109,8 +111,8 @@ class STLVisitor(NodeVisitor):
visit_and = partialmethod(binop_visitor, op=stl.And) visit_and = partialmethod(binop_visitor, op=stl.And)
def visit_id(self, name, _): def visit_id(self, name, _):
var_kind, *iden = name.text var_kind, *_ = name.text
return stl.str_to_varkind[var_kind] ,int("".join(iden)) return stl.str_to_varkind[var_kind] , Symbol(name.text)
def visit_var(self, _, children): def visit_var(self, _, children):
(var_kind, iden), time_node = children (var_kind, iden), time_node = children