Comment #9 on issue 2865 by [email protected]: str(Matrix(...)) should give "Matrix(...)"
http://code.google.com/p/sympy/issues/detail?id=2865

The copy of Chris's answer:

On Mon, Mar 26, 2012 at 12:11 PM, <[email protected]> wrote:


> Still, I do not understand why we must aplly this to str printer.
>
> sympy.printing.str.__doc__
> """
> A Printer for generating readable representation of most sympy classes.
> """
>
>

So perhaps the docstring should read: ...generates a representation of the
object which, when supplied to sympify will reconstruct the object.


> sympy.printing.repr.__doc__
> """
> A Printer for generating executable code.
>
> The most important function here is srepr that returns a string so that the
> relation eval(srepr(expr))=expr holds in an appropriate environment.
> """

The difference here is that the expression itself (not the string form)
should reconstruct the object. So you are right in that Integer(1) is not
needed for the srepr of Matrix but it would be needed for S(1):

>> srepr(S(1))
Integer(1)
>> srepr(Matrix([[1]]))
Matrix([[1]])

But _print_MatrixBase uses the printer to print the contents of the Matrix
and the printer doesn't know the context of what is being printed: it will
return 1/2 as Rational(1, 2) and 1 as Integer(1). What is needed, perhaps
is a way to know if the Rational needs to be printed in long form or
whether coercion can be relied upon to construct the object.

Similarly, srepr(x + 1) could be `Symbol('x') + 1` instead of
`Add(Symbol('x'), Integer(1))`, couldn't it?

/c


--
You received this message because you are subscribed to the Google Groups 
"sympy-issues" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy-issues?hl=en.

Reply via email to