Permalink
Browse files

Amend the string representation of composition of morphisms.

The initial version did not comply with the requirement that the
represented object be able to be reconstructed from the string
representation.
  • Loading branch information...
scolobb committed Jun 2, 2012
1 parent 1ee252d commit bab67eac53d5e874b97617b861449f7c3564a62a
Showing with 8 additions and 10 deletions.
  1. +6 −8 sympy/printing/str.py
  2. +2 −2 sympy/printing/tests/test_str.py
View
@@ -530,14 +530,12 @@ def _print_Object(self, object):
return 'Object("%s")' % object.name
def _print_Morphism(self, morphism):
- if len(morphism.components) == 1:
- return 'Morphism(%s, %s, "%s")' % \
- (morphism.domain, morphism.codomain, morphism.name)
- else:
- names = ""
- for component in morphism.components:
- names += str(component) + ", "
- return "[%s]" % names[:-2]
+ result = ""
+ for component in reversed(morphism.components):
+ result += 'Morphism(%s, %s, "%s") * ' % \
+ (component.domain, component.codomain, component.name)
+ return result[:-3]
+
def sstr(expr, **settings):
"""Returns the expression as a string.
@@ -484,5 +484,5 @@ def test_categories():
assert str(A) == 'Object("A")'
assert str(f) == 'Morphism(Object("A"), Object("B"), "f")'
- assert str(g * f) == '[Morphism(Object("A"), Object("B"), "f"), \
-Morphism(Object("B"), Object("C"), "g")]'
+ assert str(g * f) == 'Morphism(Object("B"), Object("C"), "g") * \
+Morphism(Object("A"), Object("B"), "f")'

0 comments on commit bab67ea

Please sign in to comment.