Repository: sympy/sympy

Issue:
KroneckerDelta(p, 0) raises IndexError
To reproduce

```
>>> p = Symbol('p', prime=True)
>>> KroneckerDelta(p, 0)
IndexError                                Traceback (most recent call last)
<ipython-input-2-7104d3bd4b37> in <module>()
----> 1 KroneckerDelta(p, 0)

/home/leosartaj/projects/sympy/sympy/core/cache.pyc in wrapper(*args, **kwargs)
     89             def wrapper(*args, **kwargs):
     90                 try:
---> 91                     retval = cfunc(*args, **kwargs)
     92                 except TypeError:
     93                     retval = func(*args, **kwargs)

/home/leosartaj/projects/sympy/sympy/core/compatibility.pyc in wrapper(*args, **kwds)
    878                         stats[HITS] += 1
    879                         return result
--> 880                 result = user_function(*args, **kwds)
    881                 with lock:
    882                     root, = nonlocal_root

/home/leosartaj/projects/sympy/sympy/core/function.pyc in __new__(cls, *args, **options)
    374 
    375         evaluate = options.get('evaluate', global_evaluate[0])
--> 376         result = super(Function, cls).__new__(cls, *args, **options)
    377         if not evaluate or not isinstance(result, cls):
    378             return result

/home/leosartaj/projects/sympy/sympy/core/cache.pyc in wrapper(*args, **kwargs)
     89             def wrapper(*args, **kwargs):
     90                 try:
---> 91                     retval = cfunc(*args, **kwargs)
     92                 except TypeError:
     93                     retval = func(*args, **kwargs)

/home/leosartaj/projects/sympy/sympy/core/compatibility.pyc in wrapper(*args, **kwds)
    878                         stats[HITS] += 1
    879                         return result
--> 880                 result = user_function(*args, **kwds)
    881                 with lock:
    882                     root, = nonlocal_root

/home/leosartaj/projects/sympy/sympy/core/function.pyc in __new__(cls, *args, **options)
    198 
    199         if evaluate:
--> 200             evaluated = cls.eval(*args)
    201             if evaluated is not None:
    202                 return evaluated

/home/leosartaj/projects/sympy/sympy/functions/special/tensor_functions.py in eval(cls, i, j)
    165             return S.Zero
    166         elif i != 0 and diff.is_nonzero:
--> 167             return cls(0, diff.args[0])
    168 
    169         if i.assumptions0.get("below_fermi") and \

IndexError: tuple index out of range
```

This is because in this case `args` is an empty `Tuple`, hence the `IndexError`. I will send a PR to fix the issue.

Discussion:

Patch:
diff --git a/AUTHORS b/AUTHORS
index 30a642d10e..c7a5d1ab54 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -230,6 +230,7 @@ Niklas Thörne <notrupertthorne@gmail.com>
 Huijun Mai <m.maihuijun@gmail.com>
 Marek Šuppa <mr@shu.io>
 Prasoon Shukla <prasoon92.iitr@gmail.com>
+Sergey B Kirpichev <skirpichev@gmail.com>
 Stefen Yin <zqyin@ucdavis.edu>
 Thomas Hisch <t.hisch@gmail.com>
 Matthew Hoff <mhoff14@gmail.com>
diff --git a/bin/mailmap_update.py b/bin/mailmap_update.py
index 7764192502..7f258c1b5c 100755
--- a/bin/mailmap_update.py
+++ b/bin/mailmap_update.py
@@ -52,7 +52,7 @@
 authors = AUTHORS[AUTHORS.find(firstauthor):].strip().split('\n')
 
 # People who don't want to be listed in AUTHORS
-authors_skip = ["Kirill Smelkov <kirr@landau.phys.spbu.ru>", "Sergey B Kirpichev <skirpichev@gmail.com>"]
+authors_skip = ["Kirill Smelkov <kirr@landau.phys.spbu.ru>"]
 
 predate_git = 0
 
diff --git a/doc/src/aboutus.rst b/doc/src/aboutus.rst
index cf03181293..28b76c667f 100644
--- a/doc/src/aboutus.rst
+++ b/doc/src/aboutus.rst
@@ -235,6 +235,7 @@ want to be mentioned here, so see our repository history for a full list).
 #. Huijun Mai: Chinese translation of the tutorial
 #. Marek Šuppa: Improvements to symbols, tests
 #. Prasoon Shukla: Bug fixes
+#. Sergey B Kirpichev: Bug fixes
 #. Stefen Yin: Fixes to the mechanics module
 #. Thomas Hisch: Improvements to the printing module
 #. Matthew Hoff: Addition to quantum module
diff --git a/sympy/abc.py b/sympy/abc.py
index 709ffc4ce5..b751a61d15 100644
--- a/sympy/abc.py
+++ b/sympy/abc.py
@@ -2,36 +2,10 @@
 
 import string
 
-from .core import Symbol, symbols
+from .core import Symbol
 from .core.alphabets import greeks
 from .core.compatibility import exec_
 
-##### Symbol definitions #####
-
-# Implementation note: The easiest way to avoid typos in the symbols()
-# parameter is to copy it from the left-hand side of the assignment.
-
-a, b, c, d, e, f, g, h, i, j = symbols('a, b, c, d, e, f, g, h, i, j')
-k, l, m, n, o, p, q, r, s, t = symbols('k, l, m, n, o, p, q, r, s, t')
-u, v, w, x, y, z = symbols('u, v, w, x, y, z')
-
-A, B, C, D, E, F, G, H, I, J = symbols('A, B, C, D, E, F, G, H, I, J')
-K, L, M, N, O, P, Q, R, S, T = symbols('K, L, M, N, O, P, Q, R, S, T')
-U, V, W, X, Y, Z = symbols('U, V, W, X, Y, Z')
-
-alpha, beta, gamma, delta = symbols('alpha, beta, gamma, delta')
-epsilon, zeta, eta, theta = symbols('epsilon, zeta, eta, theta')
-iota, kappa, lamda, mu = symbols('iota, kappa, lamda, mu')
-nu, xi, omicron, pi = symbols('nu, xi, omicron, pi')
-rho, sigma, tau, upsilon = symbols('rho, sigma, tau, upsilon')
-phi, chi, psi, omega = symbols('phi, chi, psi, omega')
-
-
-##### Clashing-symbols diagnostics #####
-
-# We want to know which names in SymPy collide with those in here.
-# This is mostly for diagnosing SymPy's namespace during SymPy development.
-
 _latin = list(string.ascii_letters)
 # OSINEQ should not be imported as they clash; gamma, pi and zeta clash, too
 _greek = list(greeks) # make a copy, so we can mutate it
@@ -39,6 +13,9 @@
 _greek.remove("lambda")
 _greek.append("lamda")
 
+for _s in _latin + _greek:
+    exec_("%s = Symbol('%s')" % (_s, _s))
+
 def clashing():
     """Return the clashing-symbols dictionaries.
 
@@ -85,4 +62,4 @@ def clashing():
 
 _clash1, _clash2, _clash = clashing()
 
-del _latin, _greek, clashing, Symbol
+del _latin, _greek, _s, clashing, Symbol
diff --git a/sympy/functions/special/tensor_functions.py b/sympy/functions/special/tensor_functions.py
index a4ed440c61..ba3edd114f 100644
--- a/sympy/functions/special/tensor_functions.py
+++ b/sympy/functions/special/tensor_functions.py
@@ -155,16 +155,11 @@ def eval(cls, i, j):
         # indirect doctest
 
         """
-        if (i > j) is True:
-            return cls(j, i)
-
-        diff = Abs(i - j)
-        if diff == 0:
+        diff = i - j
+        if diff.is_zero:
             return S.One
-        elif diff.is_number:
+        elif diff.is_nonzero:
             return S.Zero
-        elif i != 0 and diff.is_nonzero:
-            return cls(0, diff.args[0])
 
         if i.assumptions0.get("below_fermi") and \
                 j.assumptions0.get("above_fermi"):


Test patch:
diff --git a/sympy/functions/special/tests/test_tensor_functions.py b/sympy/functions/special/tests/test_tensor_functions.py
index 888d879721..dcc69c8a02 100644
--- a/sympy/functions/special/tests/test_tensor_functions.py
+++ b/sympy/functions/special/tests/test_tensor_functions.py
@@ -34,13 +34,14 @@ def test_kronecker_delta():
     k = Symbol('k', nonzero=True)
     assert KroneckerDelta(1, 1) == 1
     assert KroneckerDelta(1, 2) == 0
+    assert KroneckerDelta(k, 0) == 0
     assert KroneckerDelta(x, x) == 1
     assert KroneckerDelta(x**2 - y**2, x**2 - y**2) == 1
     assert KroneckerDelta(i, i) == 1
     assert KroneckerDelta(i, i + 1) == 0
     assert KroneckerDelta(0, 0) == 1
     assert KroneckerDelta(0, 1) == 0
-    assert KroneckerDelta(i + k, i) == KroneckerDelta(0, k)
+    assert KroneckerDelta(i + k, i) == 0
     assert KroneckerDelta(i + k, i + k) == 1
     assert KroneckerDelta(i + k, i + 1 + k) == 0
     assert KroneckerDelta(i, j).subs(dict(i=1, j=0)) == 0