1
$\begingroup$

Consider the following symbolic expression:

expr = f[a,b]*g[c,d]KroneckerDelta[a,m]KroneckerDelta[d,k] + KroneckerDelta[a,p]f[x,a]+const

Could you please tell me how to replace this expression with the one where the Kroneckers are replaced with 1 and the indices in f, g, f by the values from the Kroneckers?

I.e.,

exprfinal=f[m,b]*g[c,k]+f[x,p]+const
$\endgroup$
2
  • $\begingroup$ Can you more explicitly explain how to generate the indices from the parameters of the KroneckerDelta expressions? I don't understand why e.g. f[a, b] * g[c, d] KroneckerDelta[a, m] KroneckerDelta[d, k] should have become f[m, b] * g[c, k]. $\endgroup$
    – MarcoB
    Aug 1, 2023 at 14:40
  • $\begingroup$ @MarcoB : in reality, there must be a sum Sum[f[a,b]*g[c,d],{a,...},{b,...},{c,...},{d,...}], but in my expressions it is assumed to be implicit. $\endgroup$ Aug 1, 2023 at 14:44

2 Answers 2

4
$\begingroup$
$Version

(* "13.3.0 for Mac OS X ARM (64-bit) (June 3, 2023)" *)

Clear["Global`*"]

expr = f[a, b]*g[c, d] KroneckerDelta[a, m] KroneckerDelta[d, k] + 
   KroneckerDelta[a, p] f[x, a] + const;

expr //. e_ *KroneckerDelta[x_, y_] :> (e /. x -> y)

(* const + f[x, p] + f[m, b] g[c, k] *)
$\endgroup$
4
$\begingroup$
rule = (func : (f | g))[s : OrderlessPatternSequence[a_, b_]] *
  KroneckerDelta[a_, c_] :> func[Sequence @@ ({s} /. a :> c)];

expr //. rule
(* const + f[x, p] + f[m, b] g[c, k] *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.