[sympy] Issue 3479 "KroneckerDelta should canonicalize"

2013-03-03 Thread Bi Ge
Hi Sympy community, I've been looking at issue3479 and trying to fix it by using minlex. Right now I just put the following at the end of def eval(cls, i, j): sort_args = minlex( ( i , j ) ) i = sort_args[0] j = sor

Re: [sympy] Issue 3479 "KroneckerDelta should canonicalize"

2013-03-03 Thread Stefan Krastanov
I do not think that the problem here is with your understanding of sympy but rather with the way that pythonic variables work. for instance: L = [1,2] a = L[0] # 'a' points to the object int(1) a = 5 # 'L' does not change but 'a' points to the object int(5) I used the verb "points" but it wo

Re: [sympy] Issue 3479 "KroneckerDelta should canonicalize"

2013-03-03 Thread Bi Ge
OK after some reading let's see if my understanding is correct. Python variables are actually "identifiers" that sort of point to objects. In my example, i and j bind with the 2 inputs (symbol or integer) of KroneckerDelta. Even though I reassign i and j to different values, the actual inputs st

Re: [sympy] Issue 3479 "KroneckerDelta should canonicalize"

2013-03-04 Thread Stefan Krastanov
Just look where the inputs go/get saved. That will usually be enough. However, there might be some nasty magic involved because of the way we create mathematical objects in sympy (subclasses of Basic). All subclasses of Basic have a "private" attribute _args, that is used when comparing objects,

Re: [sympy] Issue 3479 "KroneckerDelta should canonicalize"

2013-03-05 Thread Bi Ge
Here's the pull request discussion https://github.com/sympy/sympy/pull/1869. Since rewite __eq__ and hash functions is a bad idea, I tried to just swap inputs when they are not in order and change the test cases. I've read the Basic class and have some questions. I can access the inputs using "

Re: [sympy] Issue 3479 "KroneckerDelta should canonicalize"

2013-03-05 Thread Stefan Krastanov
Is there a reason not to use the following? `self._args = sorting_function(self._args)` I think it is used in some other places which need similar treatment. I did not understand the question about `eval`. Why do you need to define an `eval` method? -- You received this message because you are

Re: [sympy] Issue 3479 "KroneckerDelta should canonicalize"

2013-03-05 Thread Bi Ge
Sorry I was confused by the cls. The original eval method has 3 inputs(cls, i, j). To use ._args I just need to do `cls._args` right? If so, right now even I reassign it to some other value the class stays unchanged. type(cls._args) gives `` and `print cls._args` gives `` On Tuesday, March

Re: [sympy] Issue 3479 "KroneckerDelta should canonicalize"

2013-03-05 Thread Stefan Krastanov
I guess that the problem is that you are changing the class attribute instead of the instance_of_the_class attribute. If you are working within a __new__ method it is a bit confusing to sort them out, but in most methods you usually work with the instance attributes through the `self` variable. I

Re: [sympy] Issue 3479 "KroneckerDelta should canonicalize"

2013-03-05 Thread Julien Rioux
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): """

Re: [sympy] Issue 3479 "KroneckerDelta should canonicalize"

2013-03-05 Thread Bi Ge
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? If not, I'm trying to swap inputs inside of eval() if inputs are not in order but having trouble with accessi

Re: [sympy] Issue 3479 "KroneckerDelta should canonicalize"

2013-03-05 Thread Julien Rioux
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 wa