A python function will just return whatever you tell it to return. If
you give it symbolic input, it will plug that in and return it.
A subclass of Function will work like
In [20]: class MyFunc(Function):
....: @classmethod
....: def eval(cls, arg):
....: if arg == 1:
....: return 0
....:
In [21]: MyFunc(x)
Out[21]: MyFunc(x)
In [22]: MyFunc(1)
Out[22]: 0
In other words, when given something that it doesn't know how to
evaluate, it remains unevaluated as a function. This is essentially
what Function('f') creates, except doing it this way lets you define
evaluation at specific points using the eval method.
Aaron Meurer
On Fri, Nov 30, 2012 at 9:28 AM, Rishabh Dixit <[email protected]> wrote:
> Hi,
>
> I guess other functions also work as the binomial functions you mentioned-
>
>>>> x=Symbol('x')
>>>> y=Symbol('y')
>>>> def add(x,y):
> ... return x+y
> ...
>>>> add(x,y)
> x + y
>>>> add(2,3)
> 5
>
>
> I am also a newbie to sympy so I might be missing something.
>
>
> On Fri, Nov 30, 2012 at 8:34 PM, Shriramana Sharma <[email protected]>
> wrote:
>>
>> On Fri, Nov 30, 2012 at 10:06 AM, Aaron Meurer <[email protected]> wrote:
>> > lambdify and implemented_function are best if you intend to evaluate
>> > these numerically. Otherwise, just use a regular Python function.
>>
>> Hi thanks. Please also clarify how I can make a function which accepts
>> a symbolic argument but does not resolve it until an operable (i.e.
>> numeric) value is specified, just like the binomial function's
>> behavious below:
>>
>> In [10]: var('n,i',integer=True)
>> Out[11]: (n, i)
>>
>> binomial(n,i)
>> Out[12]: binomial(n, i)
>>
>> binomial(5,2)
>> Out[13]: 10
>>
>> Thanks, and sorry again for the extreme noobness!
>>
>> --
>> Shriramana Sharma
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "sympy" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/sympy?hl=en.
>>
>
>
>
> --
> Regards,
> Rishabh Dixit
> BITS Pilani
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/sympy?hl=en.
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sympy?hl=en.