On Tuesday, 5 March 2013 18:05:18 UTC-5, Bi Ge wrote:
>
> I wasn't trying to rewrite the eval function. My original plan is in 
> eval() when two symbolic values are not in order,
> I will return KroneckerDelta(j, i), is this method more preferred? 
>
>
Yes, except you should use cls(j, i). This way, if somebody subclasses 
KroneckerDelta, your code will correctly return an instance of that 
subclass.
 

> If not, I'm trying to swap inputs inside of eval() if inputs are not in 
> order but having trouble with accessing cls._args
>
>
Well, cls isn't an instance here (see Stefan's mail for what this means), 
so you can't do that.

Cheers,
Julien
 

> Bi Ge
>
> On Tuesday, March 5, 2013 5:50:52 PM UTC-5, Julien Rioux wrote:
>>
>> What Stefan writes is good advice for designing classes in general but in 
>> this particular case, KroneckerDelta being a subclass of Function, we don't 
>> need to overwrite __new__ since the eval method is meant exactly for this. 
>> From sympy/core/function.py:
>>
>>     def eval(cls, *args):
>>         """
>>         Returns a canonical form of cls applied to arguments args.
>>
>>         The eval() method is called when the class cls is about to be
>>         instantiated and it should return either some simplified instance
>>         (possible of some other class), or if the class cls should be
>>         unmodified, return None.
>>
>>         [...]
>>         """
>>
>> In the eval method of KroneckerDelta we can already see that the first 
>> few lines is an attempt to order the args:
>>
>>     def eval(cls, i, j):
>>         # ...
>>         if (i > j) is True:
>>             return cls(j, i)
>>
>> The problem is that comparison with i > j only works for numerical 
>> values, not for symbolic value.
>>
>> Cheers,
>> Julien
>>
>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to