-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compact printing and more legible output #21
Comments
I've addressed 2, 3, 4, 5, 8 1 -- I'm waiting to see how showcompact changes shake out. In general, you should be able to reconstruct the object from the output. |
1 -- Sounds good. That's probably the best plan. I fetched your update to play around with, and found some bugs, mainly in how complex numbers were handled, and if the first coefficient was -1. I reworked the logic, and ended up splitting the functions into two methods - one for Real, and one for ComplexPair. Manually tested it for everything I could conceive of, and it seems to handle nicely. No tests have been added to the test.jl file, as I'm not sure the best way to automate printing tests. Perhaps sprint, and compare to a string? |
i think all of the major points have been addressed. open a new issue for anything else |
Julia's show functions appear to be in the process of an overhaul (see this issue), but at this point it doesn't appear there is any way to set the global printing precision in the REPL. With floating point coefficients (i.e. 1/3 = 0.3333333333....) the default printing precision can make the output difficult to read. At least that's my opinion. However, showing the full output is also desirable.
The ideal way is to define a
show
function that provides the full output, and ashowcompact
function that limits the output. However, my use case requires using the polynomials in a composite data type, where printing "poly(...)" would be not ideal. At the same time,show
andshowcompact
by convention provide type information like this. Andprint
andstring
by convention output the default precision as well.What I'm looking for is a clean way to provide both full and compact output with & without type info (i.e. "Poly(x^2 + 1)" and "x^2 + 1"). Possible solutions:
show
andshowcompact
as normal. I thensprint(showcompact, p)
and strip the "Poly( )" from the string when I need the compact format. This keeps the library itself cleaner, but puts a larger burden on anyone who wants a compactPoly
representation without the type information.print
orstring
method to output the compact form. This would look something like this:Regardless of which method above is chosen, here's my vision for the prettier output:
These changes would:
im
term, don't display# + 0im
, just show that it's real# - #
instead of# + -#
x
instead ofx^1
These last 4 (or at least 3) could also be added to the regular show command, as they deal more with formatting than full output.
Thoughts?
The text was updated successfully, but these errors were encountered: