Skip to content

Commit

Permalink
handling any Expr not just Sym
Browse files Browse the repository at this point in the history
  • Loading branch information
jtauber committed Feb 3, 2014
1 parent 47c0ad3 commit f5dbe2d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
11 changes: 11 additions & 0 deletions symbolic_tuples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,14 @@ up(2, 4)

>>> r(s=up(1, 2), t=up(3, 4))
up(up(3, 6), up(4, 8))

>>> u = Sym("v") * (Sym("w") + Sym("x"))

>>> u(w=up(1, 2))
(v * (up(1, 2) + x))

>>> u(w=up(1, 2), x=up(3, 4))
(v * up(4, 6))

>>> u(v=down(2, 3))(w=up(1, 2), x=up(3, 4))
26
8 changes: 4 additions & 4 deletions tuples.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
see ``tuples.rst`` for an explanation.
"""

from symbolic import Sym, Expr, Add, Sub, Mul
from symbolic import Expr, Add, Sub, Mul


class Tuple(Expr):
Expand Down Expand Up @@ -33,7 +33,7 @@ def __add__(self, other):
*(s + o for (s, o) in zip(
self._components, other._components))
)
elif isinstance(other, Sym):
elif isinstance(other, Expr):
return Add(self, other)
else:
raise TypeError("addend must be tuple or symbol")
Expand All @@ -47,7 +47,7 @@ def __sub__(self, other):
*(s - o for (s, o) in zip(
self._components, other._components))
)
elif isinstance(other, Sym):
elif isinstance(other, Expr):
return Sub(self, other)
else:
raise TypeError("subtrahend must be tuple or symbol")
Expand All @@ -61,7 +61,7 @@ def __mul__(self, other):
s * o for (s, o) in zip(
self._components, other._components)
)
elif isinstance(other, Sym):
elif isinstance(other, Expr):
return Mul(self, other)
else:
return other * self # defer to __rmul__
Expand Down

0 comments on commit f5dbe2d

Please sign in to comment.