# How to define the following rule for all objects in a compact way?

Consider the following symbolic definitions:

{Fsymbol["f", x, a_] = f[x, a], Fsymbol["c", x, a_] = c[x, a],
Fsymbol["d", x, a_] = d[x, a]};
{dFsymbol["f", x, a_, b_] = df[x, a, b],
dFsymbol["c", x, a_, b_] = dc[x, a, b],
dFsymbol["d", x, a_, b_] = dd[x, a, b]};


I would like to define the following rules:

f /: D[f[x_, a_], f[x_, b_], OptionsPattern[]] :=
If[MemberQ[OptionValue[NonConstants], f], KroneckerDelta[a, b], 0]
df /: D[df[x_, a_, b_], f[x_, c_], OptionsPattern[]] :=
If[MemberQ[OptionValue[NonConstants], df],
I*p["f", a] KroneckerDelta[b, c], 0]
c /: D[c[x_, a_], c[x_, b_], OptionsPattern[]] :=
If[MemberQ[OptionValue[NonConstants], c], KroneckerDelta[a, b], 0]
dc /: D[dc[x_, a_, b_], c[x_, c_], OptionsPattern[]] :=
If[MemberQ[OptionValue[NonConstants], dc],
I*p["c", a] KroneckerDelta[b, c], 0]
d /: D[d[x_, a_], d[x_, b_], OptionsPattern[]] :=
If[MemberQ[OptionValue[NonConstants], d], KroneckerDelta[a, b], 0]
dd /: D[dd[x_, a_, b_], d[x_, c_], OptionsPattern[]] :=
If[MemberQ[OptionValue[NonConstants], dd],
I*p["d", a] KroneckerDelta[b, c], 0]

D[f[x, a]^3*df[x, a, b]^3 + k[l, m, o]*f[x, m]*df[x, l, o], f[x, c1],
NonConstants -> {f, df}]


3 I p(f,a) f(x,a)^3 Subscript[δ, b,c1] df(x,a,b)^2+3 Subscript[δ, a,c1] f(x,a)^2 df(x,a,b)^3+Subscript[δ, c1,m] df(x,l,o) k(l,m,o)+I Subscript[δ, c1,o] p(f,l) f(x,m) k(l,m,o)

The structure of these rules for each pair {c,dc}, {f,df}, {d,dd} is the same, so instead of manually typing 6 strings, I would like to type only two strings but iterate over the field symbols. Could you please tell me how to do this?

I don't understand why you still need all these conundrum with additional symbols and refering to fields with strings when I've shown you a much simpler and cleaner way. But if you insist on complicating your life and your code ...

fields = {"f", "c", "d"};
Table[
With[{field = field, fieldSymb = Symbol[field],
fieldDSymb = Symbol["d" <> field]},
Symbol[ToUpperCase[field] <> "symbol"][field, x, a_] =
fieldSymb[x, a];
Symbol["d" <> ToUpperCase[field] <> "symbol"][field, x, a_, b_] =
fieldDSymb[x, a, b];
fieldSymb /:
D[fieldSymb[x_, a_], fieldSymb[x_, b_], OptionsPattern[]] :=
If[MemberQ[OptionValue[NonConstants], fieldSymb],
KroneckerDelta[a, b], 0];
fieldDSymb /:
D[fieldDSymb[x_, a_, b_], fieldSymb[x_, c_], OptionsPattern[]] :=
If[MemberQ[OptionValue[NonConstants], fieldDSymb],
I*p[field, a] KroneckerDelta[b, c], 0]
]
, {field, fields}];