Commit e5f853e4 authored by Sean Leavey's avatar Sean Leavey

Attempt to fix symbol display infinite loop

parent 3f857e61
......@@ -104,7 +104,9 @@ def display(a):
elif hasattr(a, "name"): # Anything with a name attribute just display that
return str(a)
# Fall back to repr for symbols that don't provide an op or name. Note we can't use str(a)
# here because a.__str__ itself calls this function.
return repr(a)
def evaluate(x):
......@@ -183,9 +185,6 @@ class Symbol(abc.ABC):
def __str__(self):
return display(self)
def __repr__(self):
return display(self)
def is_changing(self):
......@@ -272,9 +271,9 @@ class Variable(Symbol):
y = Variable('y')
z = 4*x**2 - np.cos(y)
print(f"{z} = {z.eval(subs={x:2, y:3})} : x={2}, y={3}")
>>>> (4*x**2-y) = 13 : x=2, y=3
value : float, int
......@@ -289,12 +288,12 @@ class Variable(Symbol):
def __str__(self):
return self.__name
def eval(self, subs=None, **kwargs):
if subs:
if self in subs:
return subs[self]
return self
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment