Beware that Function caches its input, so if you do

f1 = Function('f')
f2 = Function('f')
f1.is_real = True

then f2 will also be real.

Furthermore, if you disable the cache, "f1 is f2" won't be true, but
"f1 == f2" will be true, even if "f1.is_real != f2.is_real".

Aaron Meurer

On Thu, Feb 26, 2015 at 12:13 AM, Chris Smith <[email protected]> wrote:
> You could make a function "factory", right?
>
> def rfunc(name):
>   rv = Function(name)
>   rv.is_real = True
>   return rv
>
>>>> f = rfunc('f')
>>>> f(var('x')).is_real
> True
>
> On Tuesday, February 24, 2015 at 5:33:20 PM UTC-6, Aaron Meurer wrote:
>>
>> It looks like
>>
>> f = Function('f')
>> f.is_real = True
>>
>> also works, although I wouldn't use it unless you really don't know
>> the names of the functions you want to create until runtime.
>>
>> Aaron Meurer
>>
>>
>> On Tue, Feb 24, 2015 at 5:31 PM, Aaron Meurer <[email protected]> wrote:
>> > On Tue, Feb 24, 2015 at 4: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)
>> >
>> > It would just be real_function(X).
>> >
>> > "Function('f')" is (roughly) the same as "class f(Function): pass".
>> > That is, it creates a subclass of Function called f. You will need to
>> > create a new subclass for each function. Clearly, that's not super
>> > easy to do if you want to create them on the fly, which is why we
>> > should fix that issue.
>> >
>> > Aaron Meurer
>> >
>> >>
>> >>
>> >> 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.
>> >>
>> >> --
>> >> 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/89825575-1c89-448f-99a3-59718beb8117%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/CAKgW%3D6L7Z-7%2B4jwMgC%3DFkgDRk70K6VRJuTWY-tZS_h-6Z6Piww%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to