On Tue, Feb 24, 2015 at 3:51 PM, John Peterson <[email protected]> wrote:
>
>
> On Tuesday, February 24, 2015 at 3:15:03 PM UTC-7, Aaron Meurer wrote:
>>
>> The problem is that assumptions on Function don't do anything
>> (https://github.com/sympy/sympy/issues/6494). If you want to create a
>> Function with assumptions, you'll need to subclass Function
>> explicitly, like
>>
>> class f(Function):
>>     is_real = True
>
>
> Thanks for pointing out the real issue!  I tried to implement your
> suggestion, but I'm not a particularly skillful python programmer, so my
> first attempt at subclassing Function in the way you described didn't
> work...
>
> Here's the code:
>
>> #!/usr/bin/env python
>> from sympy import *
>> class real_function(Function):
>>   is_real=True
>> X = Symbol('X', real=True)
>> f = real_function('f')(X)
>> g = real_function('g')(X)
>> print diff (abs(f-g), X)
>
>
> And the error message:
>
>> Traceback (most recent call last):
>>   File "testcase.py", line 10, in <module>
>>     f = real_function('f')(X)
>> TypeError: 'real_function' object is not callable
>
>
> which I don't understand how to fix.


Try this:

In [1]: class f(Function):
   ...:     is_real=True
   ...:

In [2]: class g(Function):
   ...:     is_real=True
   ...:

In [3]: X = Symbol('X', real=True)

In [4]: diff(abs(f(X)-g(X)), X)
Out[4]:
⎛d          d       ⎞
⎜──(f(X)) - ──(g(X))⎟⋅sign(f(X) - g(X))
⎝dX         dX      ⎠


Ondrej

>
> --
> 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 http://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/2952c170-688e-4c2d-a61a-3063e7866c0e%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 [email protected].
To post to this group, send email to [email protected].
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/CADDwiVDS0bXswhfmwjk0%3D00hnvdLJjD5GJkQZQA9EygDoZ9zDA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to