I think that you should take a look at the StrPrinter interface and
consider implementing a custom StrPrinter. You may need to implement a
method like _print_LinearDifferentialOperator.
While simple string concatenation or interpolation might work for basic
expressions, these approaches have significant limitations when dealing
with expressions that require proper handling of operator precedence and
parenthesizing.
On Sunday, February 23, 2025 at 7:09:27 PM UTC+1 brombo wrote:
> I am coding a str() function for a custom object. The object is a liner
> differential operator that consists of a linear combination of sympy
> expressions and partial derivatives (defined in a class I have defined
> and have their own str() function). The problem is to know when to
> represent a term in the linear differential operator str() with
>
> str(sympy expression)+str(partial derivative)
>
> or
>
> '('+str(sympy expression)+')'+str(partial derivative)
>
> that is does str(sympy expression) have low level instances of '+' or
> '-' in it as opposed to '+' or '-' being used in functions within the
> expression such as sin(x+y) or exp(-x)?
>
> Any suggestions would be appreciated before I resort to using grep on
> str(sympy expression).
>
>
--
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 [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/sympy/d8fb062f-67a6-4234-8a45-a594404acd7an%40googlegroups.com.