Yeah, I was stuck in a rut so that it took me until I stepped away for a bit to realize the same conclusion!
I didn't realize I could just add the is_commutative flag to UndefinedFunction, so I like your solution better than mine, where I had ended up subclassing AppliedUndef (as that is the subclass of Function that has the is_commutative property). Since I'm unlikely to deal with non-commutative symbols, your solution should serve me fine. Thanks! Duane On Monday, November 23, 2015 at 3:29:41 PM UTC-6, Aaron Meurer wrote: > > 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 <dqny...@comcast.net > <javascript:>> 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+un...@googlegroups.com <javascript:>. > > To post to this group, send email to sy...@googlegroups.com > <javascript:>. > > 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/2d3cb97b-4d7a-40c4-904f-df865786f41e%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.