Simplify sympy.KroneckerDelta

Viewed 596

Is there a way to "simplify" a sympy.KroneckerDelta? For example,

i, j = sympy.symbols('i j')
sympy.KroneckerDelta((i+1)/2, (j+1)/2)

could also be expressed more simply as

sympy.KroneckerDelta(i, j)
1 Answers

There is an internal function _simplify_delta that does this.

import sympy
from sympy.concrete.delta import _simplify_delta
i, j = sympy.symbols('i j')
expr = sympy.KroneckerDelta((i+1)/2, (j+1)/2)
print(_simplify_delta(expr))

prints KroneckerDelta(i, j). Remarks:

  1. _simplify_delta only works on a single instance of KroneckerDelta, not on expressions involving deltas.
  2. It is not used by simplify: the generic simplify does not know much, if anything, about special properties of Kronecker delta.
Related