Function("P") is just syntactic sugar. As you can see from the
constructor, it's the same as UndefinedFunction("P"). If you want to
customize the behavior, you should subclass UndefinedFunction.

However, in this case, it looks like UndefinedFunction("P",
is_commutative=True) works.

Aaron Meurer


On Mon, Nov 23, 2015 at 2:32 PM, Duane Nykamp <dqnyk...@comcast.net> wrote:
> I'm trying to create a subclass of Symbol that returns a subclass of
> Function when called.   The only reason is to customize the is_commutative
> property so that an expression like P(A)/P(Eq(x,1)) will output with the
> P(x=1) in the denominator rather than as P^-1(x=1), which might confuse my
> students.
>
> However, if I create a unmodified Function subclass, the resulting function
> is not callable.
>
> In [7]: class Function2(Function):
>    ...:     pass
>    ...:
>
> In [8]: P=Function2('P')
>
> In [9]: P(x)
> ---------------------------------------------------------------------------
> TypeError                                 Traceback (most recent call last)
> <ipython-input-9-49600f79dd99> in <module>()
> ----> 1 P(x)
>
> TypeError: 'Function2' object is not callable
>
>
> The problem is due to __new__ of Function
>
>     def __new__(cls, *args, **options):
>         # Handle calls like Function('f')
>         if cls is Function:
>             return UndefinedFunction(*args, **options)
>
> but, I can't change the condition to issubclass(cls,Function), as that makes
> it always true and messes up the function of Function.
>
> Or, the specific question I'm actually struggling with is:
> Can I create a
> P=Function('P')
> so that
>
> In [4]: P(A)/P(Eq(x,1))
> Out[4]:
>       -1
> P(A)⋅P  (x = 1)
>
> outputs with latex with the P(x=1) in the denomiator.
>
> Thanks,
> Duane
>
> --
> 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+unsubscr...@googlegroups.com.
> To post to this group, send email to sympy@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/aa0c8473-f7f3-4e3e-bd87-9cc3757ad6d3%40googlegroups.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 sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAKgW%3D6JYSoE1dv1Kp9uiVBV1S9QGP33ZfiBkyd1hL4WUJcFx_A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to