Comment #2 on issue 2695 by [email protected]: Pretty print of -x/y
http://code.google.com/p/sympy/issues/detail?id=2695
I may have a solution for this, to implement the first option (same width
fraction, but center slightly to the right instead of the default of
slightly to the left). I added this line to the __div__ in prettyForm just
before the return statement:
if num.binding==prettyForm.NEG and num.width() % 2 == 0 and
num.width() > den.width(): den = den.left(" ")[0]
The key times when we want to shift the denominator to the right are when:
- We have a negative (otherwise we make pretty_print(x**2/y) ugly in the
opposite direction)
- The numerator is an even width (otherwise the denominator is just
centered already, as in pretty_print(-x**2/y) and similar cases)
- The numerator is wider than the denominator (otherwise we're centering
off the denominator and we don't want to shift the denominator)
Thanks to sympy itself working, we should never need to worry about a
negative denominator since negative numerator and negative denominator gets
simplified to no negative, and negative denominator gets simplified to
negative numerator, so this should (hopefully) handle every case.
The output for some simple test cases is as follows:
pretty_print(-x/y)
-x
──
y
pretty_print(-x*z/y)
-x⋅z
────
y
pretty_print(x**2/y)
2
x
──
y
pretty_print(-x**2/y)
2
-x
───
y
pretty_print(-x/(y*z))
-x
───
y⋅z
I've attached an amended version of stringpict.py modified from a version
pulled via git at 18:24 UTC today. Not sure on the correct way to submit
this change for consideration via git.
Attachments:
stringpict.py 17.3 KB
--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings
--
You received this message because you are subscribed to the Google Groups
"sympy-issues" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy-issues?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.