Maybe just return printer._print(Function("Max")(*(self.args + (0,))),
that is, reuse the existing Function printer.

Aaron Meurer

On Mon, Apr 18, 2016 at 5:27 PM, Vladimir Perić <[email protected]> wrote:
> Hi all,
>
> I want to define some (simple) custom functions, so I could provide my
> own `_imp_` for lambdify and for other benefits. I managed to program
> the numerical evolution, but I'm struggling with pretty printing. I'm
> trying to emulate sympy/printing/pretty/pretty/_pretty_Function, but I
> barely understand the code and it feels like a hack. I'd be very much
> obliged if someone could give me a simple primer on how to accomplish
> what I want:
>
> Essentially, I have a hinge function, which is defined as `max(0,
> x-thr)` , where x is a vector and thr is a predefined scalar (and can
> be 0). This is the code I currently have:
>
>     def _pretty(self, printer, *args):
>         from sympy.printing.pretty.stringpict import prettyForm, stringPict
>         prettyFunc = printer._print('Max')
>         args = self.args + (0,)
>         prettyArgs = prettyForm(*printer._print_seq(args).parens())
>         pform = prettyForm(binding=prettyForm.FUNC,
> *stringPict.next(prettyFunc, prettyArgs))
>         return pform
>
> Which produces the results I want. However, I really don't understand
> what most of the code actually does. Is there a simpler way of writing
> this? It realls feels like there should be.
>
> Thanks in advance,
>
> --
> Vladimir Perić
>
> --
> 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 post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sympy/CAFu6gYZFQh41x%2BDgFOc51W7Vuu-ZAOXtQnV05tH_W1Yt9w%2Bt%3DQ%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAKgW%3D6L7Nd%3Dt4cBVGG57z98C8JMN6yO3cvP9M6b5Lr3B6uU4XQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to