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] 
> <javascript:>> wrote: 
> > On Tue, Feb 24, 2015 at 4:51 PM, John Peterson <[email protected] 
> <javascript:>> 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] <javascript:>. 
> >> To post to this group, send email to [email protected] 
> <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/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.

Reply via email to