Question about best practices

47 views
Skip to first unread message

Pedro Xavier

unread,
Apr 2, 2023, 4:33:18 PM4/2/23
to sympy
I'm trying to close issue #12157 through the PR #25012.

In summary, the issue comes from the physics dyadic (sympy/physics/vector/dyadic.py) printing method not properly accounting for expressions with large width such as fractions and powers. However, as it was discussed in the issue, the printing routine for dyadic objects from the vector package (sympy/vector/dyadic.py) correctly handles the formatting. I should note that this routine is very similar to the non-working dedicated one for the physics dyadic

I've found two ways of solving the issue. One of them takes a hacky approach to reroute the printing routine for the physics dyadic so it can use the same routine as the vector's dyadic. This prevents copying code across files and is a much smaller change, but it involves writing hacky methods for the physics dyadic class so that the printing routine can work properly.

The other way updates the current dedicated printing method present in the physics dyadic class, which itself is very similar to the working printing routine and probably was the basis for it. It's a much longer change and based of off the currently working printing routine for the vector's dyadic.

since the physics dyadic and the vector's dyadic have very different implementations from what I've seen, those seem the best options to deal with the issue without completely rewriting the physics vector and physics dyadic classes. But I'm unsure which one is considered "best practices".

Aaron Meurer

unread,
Apr 3, 2023, 3:05:32 AM4/3/23
to sy...@googlegroups.com
If the two printers share a lot in common one of them could subclass
the other, or they could share a common superclass. If it's just this
one method, I would just copy the code.

It's hard to say without seeing the actual code. I will say that
usually this sort of thing is handled in the pretty printers by making
correct use of the prettyform class.

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/c9cc47fd-5a55-4838-8948-1d9b7289df01n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages