Skip to main content
Correct a mistake. Now the output is fully editable.
Source Link
xzczd
  • 68.4k
  • 9
  • 174
  • 489

OK, though I've done this many times, given that coding this in Mathematica requires one to have a good enough understanding for the core language, let me do a favor:

Clear[myD, mySum]

myD[a_ b_, c_] := a myD[b, c] + b myD[a, c]
(* Add the rule for addition just in case: *)
myD[a_ + b_, c_] := myD[a, c] + myD[b, c]

myD[mySum[a_, b__], x_] := mySum[myD[a, x], b]

myD[(h_ /; Context[h] =!= "System`")[a__], x_] := 
 With[{l = Length@{a}}, 
  Total@MapThread[
    Derivative[Sequence @@ #][h][a] myD[#2, x] &, {IdentityMatrix@
      l, {a}}]]

myD[Subscript[a_, i___, j1_, k___], Subscript[a_, i___, j2_, k___]] :=
  KroneckerDelta[j1, j2]

myD[Subscript[a_, __], Subscript[b_, __]] := 0

mySum[KroneckerDelta@OrderlessPatternSequence[i_, j_] expr_, jL___, 
  j_, jR___] := mySum[expr /. j -> i, jL, jR]

mySum[a_] := a

MakeBoxes[mySum[a__], fmt_] ^:= 
 With[{arg = MakeBoxes[#, fmt] & /@ {a}}, 
  With[{funcbody = 
     MakeBoxes[Sum[a], fmt] /. Thread[{a}
      Thread[arg -> (Slot /@ Length@Range@Length@{a})]}, 
  TemplateBox[MakeBoxes[#, fmt] & /@ {a}TemplateBox[arg, "mySum", 
   DisplayFunction -> (funcbody &)]]]]]

Usage:

myD[mySum[Subscript[a, i, j] Subscript[x, j], j], Subscript[a, i, k]]

enter image description here

myD[Subscript[x, k] mySum[g[Subscript[a, i, j], 
                            Subscript[x, j]], i, j], Subscript[x, n]]

enter image description here

You can press Ctrl+Shift+t to transform the output to TraditionalForm, and Ctrl+Shift+n to transform the output to StandardForm.

OK, though I've done this many times, given that coding this in Mathematica requires one to have a good enough understanding for the core language, let me do a favor:

Clear[myD, mySum]

myD[a_ b_, c_] := a myD[b, c] + b myD[a, c]
(* Add the rule for addition just in case: *)
myD[a_ + b_, c_] := myD[a, c] + myD[b, c]

myD[mySum[a_, b__], x_] := mySum[myD[a, x], b]

myD[(h_ /; Context[h] =!= "System`")[a__], x_] := 
 With[{l = Length@{a}}, 
  Total@MapThread[
    Derivative[Sequence @@ #][h][a] myD[#2, x] &, {IdentityMatrix@
      l, {a}}]]

myD[Subscript[a_, i___, j1_, k___], Subscript[a_, i___, j2_, k___]] :=
  KroneckerDelta[j1, j2]

myD[Subscript[a_, __], Subscript[b_, __]] := 0

mySum[KroneckerDelta@OrderlessPatternSequence[i_, j_] expr_, jL___, 
  j_, jR___] := mySum[expr /. j -> i, jL, jR]

mySum[a_] := a

MakeBoxes[mySum[a__], fmt_] ^:= 
 With[{funcbody = 
    MakeBoxes[Sum[a], fmt] /. Thread[{a} -> (Slot /@ Length@{a})]}, 
  TemplateBox[MakeBoxes[#, fmt] & /@ {a}, "mySum", 
   DisplayFunction -> (funcbody &)]]

Usage:

myD[mySum[Subscript[a, i, j] Subscript[x, j], j], Subscript[a, i, k]]

enter image description here

myD[Subscript[x, k] mySum[g[Subscript[a, i, j], 
                            Subscript[x, j]], i, j], Subscript[x, n]]

enter image description here

You can press Ctrl+Shift+t to transform the output to TraditionalForm, and Ctrl+Shift+n to transform the output to StandardForm.

OK, though I've done this many times, given that coding this in Mathematica requires one to have a good enough understanding for the core language, let me do a favor:

Clear[myD, mySum]

myD[a_ b_, c_] := a myD[b, c] + b myD[a, c]
(* Add the rule for addition just in case: *)
myD[a_ + b_, c_] := myD[a, c] + myD[b, c]

myD[mySum[a_, b__], x_] := mySum[myD[a, x], b]

myD[(h_ /; Context[h] =!= "System`")[a__], x_] := 
 With[{l = Length@{a}}, 
  Total@MapThread[
    Derivative[Sequence @@ #][h][a] myD[#2, x] &, {IdentityMatrix@
      l, {a}}]]

myD[Subscript[a_, i___, j1_, k___], Subscript[a_, i___, j2_, k___]] :=
  KroneckerDelta[j1, j2]

myD[Subscript[a_, __], Subscript[b_, __]] := 0

mySum[KroneckerDelta@OrderlessPatternSequence[i_, j_] expr_, jL___, 
  j_, jR___] := mySum[expr /. j -> i, jL, jR]

mySum[a_] := a

MakeBoxes[mySum[a__], fmt_] ^:= 
 With[{arg = MakeBoxes[#, fmt] & /@ {a}}, 
  With[{funcbody = 
     MakeBoxes[Sum[a], fmt] /. 
      Thread[arg -> (Slot /@ Range@Length@{a})]}, 
   TemplateBox[arg, "mySum", DisplayFunction -> (funcbody &)]]]

Usage:

myD[mySum[Subscript[a, i, j] Subscript[x, j], j], Subscript[a, i, k]]

enter image description here

myD[Subscript[x, k] mySum[g[Subscript[a, i, j], 
                            Subscript[x, j]], i, j], Subscript[x, n]]

enter image description here

You can press Ctrl+Shift+t to transform the output to TraditionalForm, and Ctrl+Shift+n to transform the output to StandardForm.

Remove redundant code
Source Link
xzczd
  • 68.4k
  • 9
  • 174
  • 489

OK, though I've done this many times, given that coding this in Mathematica requires one to have a good enough understanding for the core language, let me do a favor:

Clear[myD, mySum]

myD[a_ b_, c_] := a myD[b, c] + b myD[a, c]
(* Add the rule for addition just in case: *)
myD[a_ + b_, c_] := myD[a, c] + myD[b, c]

myD[mySum[a_, b__], x_] := mySum[myD[a, x], b]

myD[(h_ /; Context[h] =!= "System`")[a__], x_] := 
 With[{l = Length@{a}}, 
  Total@MapThread[
    Derivative[Sequence @@ #][h][a] myD[#2, x] &, {IdentityMatrix@
      l, {a}}]]

myD[Subscript[a_, i___, j1_, k___], Subscript[a_, i___, j2_, k___]] :=
  KroneckerDelta[j1, j2]

myD[Subscript[a_, __], Subscript[b_, __]] := 0

mySum[KroneckerDelta@OrderlessPatternSequence[i_, j_] expr_, jL___, 
  j_, jR___] := mySum[expr /. j -> i, jL, jR]

mySum[a_] := a

FormatValues@mySum = {};

MakeBoxes[mySum[a__], fmt_] ^:= 
 With[{funcbody = 
    MakeBoxes[Sum[a], fmt] /. Thread[{a} -> (Slot /@ Length@{a})]}, 
  TemplateBox[MakeBoxes[#, fmt] & /@ {a}, "mySum", 
   DisplayFunction -> (funcbody &)]]

Usage:

myD[mySum[Subscript[a, i, j] Subscript[x, j], j], Subscript[a, i, k]]

enter image description here

myD[Subscript[x, k] mySum[g[Subscript[a, i, j], 
                            Subscript[x, j]], i, j], Subscript[x, n]]

enter image description here

You can press Ctrl+Shift+t to transform the output to TraditionalForm, and Ctrl+Shift+n to transform the output to StandardForm.

OK, though I've done this many times, given that coding this in Mathematica requires one to have a good enough understanding for the core language, let me do a favor:

Clear[myD, mySum]

myD[a_ b_, c_] := a myD[b, c] + b myD[a, c]
(* Add the rule for addition just in case: *)
myD[a_ + b_, c_] := myD[a, c] + myD[b, c]

myD[mySum[a_, b__], x_] := mySum[myD[a, x], b]

myD[(h_ /; Context[h] =!= "System`")[a__], x_] := 
 With[{l = Length@{a}}, 
  Total@MapThread[
    Derivative[Sequence @@ #][h][a] myD[#2, x] &, {IdentityMatrix@
      l, {a}}]]

myD[Subscript[a_, i___, j1_, k___], Subscript[a_, i___, j2_, k___]] :=
  KroneckerDelta[j1, j2]

myD[Subscript[a_, __], Subscript[b_, __]] := 0

mySum[KroneckerDelta@OrderlessPatternSequence[i_, j_] expr_, jL___, 
  j_, jR___] := mySum[expr /. j -> i, jL, jR]

mySum[a_] := a

FormatValues@mySum = {};

MakeBoxes[mySum[a__], fmt_] ^:= 
 With[{funcbody = 
    MakeBoxes[Sum[a], fmt] /. Thread[{a} -> (Slot /@ Length@{a})]}, 
  TemplateBox[MakeBoxes[#, fmt] & /@ {a}, "mySum", 
   DisplayFunction -> (funcbody &)]]

Usage:

myD[mySum[Subscript[a, i, j] Subscript[x, j], j], Subscript[a, i, k]]

enter image description here

myD[Subscript[x, k] mySum[g[Subscript[a, i, j], 
                            Subscript[x, j]], i, j], Subscript[x, n]]

enter image description here

You can press Ctrl+Shift+t to transform the output to TraditionalForm.

OK, though I've done this many times, given that coding this in Mathematica requires one to have a good enough understanding for the core language, let me do a favor:

Clear[myD, mySum]

myD[a_ b_, c_] := a myD[b, c] + b myD[a, c]
(* Add the rule for addition just in case: *)
myD[a_ + b_, c_] := myD[a, c] + myD[b, c]

myD[mySum[a_, b__], x_] := mySum[myD[a, x], b]

myD[(h_ /; Context[h] =!= "System`")[a__], x_] := 
 With[{l = Length@{a}}, 
  Total@MapThread[
    Derivative[Sequence @@ #][h][a] myD[#2, x] &, {IdentityMatrix@
      l, {a}}]]

myD[Subscript[a_, i___, j1_, k___], Subscript[a_, i___, j2_, k___]] :=
  KroneckerDelta[j1, j2]

myD[Subscript[a_, __], Subscript[b_, __]] := 0

mySum[KroneckerDelta@OrderlessPatternSequence[i_, j_] expr_, jL___, 
  j_, jR___] := mySum[expr /. j -> i, jL, jR]

mySum[a_] := a

MakeBoxes[mySum[a__], fmt_] ^:= 
 With[{funcbody = 
    MakeBoxes[Sum[a], fmt] /. Thread[{a} -> (Slot /@ Length@{a})]}, 
  TemplateBox[MakeBoxes[#, fmt] & /@ {a}, "mySum", 
   DisplayFunction -> (funcbody &)]]

Usage:

myD[mySum[Subscript[a, i, j] Subscript[x, j], j], Subscript[a, i, k]]

enter image description here

myD[Subscript[x, k] mySum[g[Subscript[a, i, j], 
                            Subscript[x, j]], i, j], Subscript[x, n]]

enter image description here

You can press Ctrl+Shift+t to transform the output to TraditionalForm, and Ctrl+Shift+n to transform the output to StandardForm.

added 98 characters in body
Source Link
xzczd
  • 68.4k
  • 9
  • 174
  • 489

OK, though I've done this many times, given that coding this in Mathematica requires one to have a good enough understanding for the core language, let me do a favor:

Clear[myD, mySum]

myD[a_ b_, c_] := a myD[b, c] + b myD[a, c]
(* Add the rule for addition just in case: *)
myD[a_ + b_, c_] := myD[a, c] + myD[b, c]

myD[mySum[a_, b__], x_] := mySum[myD[a, x], b]

myD[(h_ /; Context[h] =!= "System`")[a__], x_] := 
 With[{l = Length@{a}}, 
  Total@MapThread[
    Derivative[Sequence @@ #][h][a] myD[#2, x] &, {IdentityMatrix@
      l, {a}}]]

myD[Subscript[a_, i___, j1_, k___], Subscript[a_, i___, j2_, k___]] :=
  KroneckerDelta[j1, j2]

myD[Subscript[a_, __], Subscript[b_, __]] := 0

mySum[KroneckerDelta@OrderlessPatternSequence[i_, j_] expr_, jL___, 
  j_, jR___] := mySum[expr /. j -> i, jL, jR]

mySum[a_] := a

FormatValues@mySum = {};

MakeBoxes[mySum[a__], fmt_] ^:= 
 With[{funcbody = 
    MakeBoxes[Sum[a], fmt] /. Thread[{a} -> (Slot /@ Length@{a})]}, 
  TemplateBox[MakeBoxes[#, fmt] & /@ {a}, "mySum", 
   DisplayFunction -> (funcbody &)]]

Usage:

myD[mySum[Subscript[a, i, j] Subscript[x, j], j], Subscript[a, i, k]]

enter image description here

myD[Subscript[x, k] mySum[g[Subscript[a, i, j], 
                            Subscript[x, j]], i, j], Subscript[x, n]]

enter image description here

You can press Ctrl+Shift+t to transform the output to TraditionalForm.

OK, though I've done this many times, given that coding this in Mathematica requires one to have a good enough understanding for the core language, let me do a favor:

Clear[myD, mySum]

myD[a_ b_, c_] := a myD[b, c] + b myD[a, c]

myD[mySum[a_, b__], x_] := mySum[myD[a, x], b]

myD[(h_ /; Context[h] =!= "System`")[a__], x_] := 
 With[{l = Length@{a}}, 
  Total@MapThread[
    Derivative[Sequence @@ #][h][a] myD[#2, x] &, {IdentityMatrix@
      l, {a}}]]

myD[Subscript[a_, i___, j1_, k___], Subscript[a_, i___, j2_, k___]] :=
  KroneckerDelta[j1, j2]

myD[Subscript[a_, __], Subscript[b_, __]] := 0

mySum[KroneckerDelta@OrderlessPatternSequence[i_, j_] expr_, jL___, 
  j_, jR___] := mySum[expr /. j -> i, jL, jR]

mySum[a_] := a

FormatValues@mySum = {};

MakeBoxes[mySum[a__], fmt_] ^:= 
 With[{funcbody = 
    MakeBoxes[Sum[a], fmt] /. Thread[{a} -> (Slot /@ Length@{a})]}, 
  TemplateBox[MakeBoxes[#, fmt] & /@ {a}, "mySum", 
   DisplayFunction -> (funcbody &)]]

Usage:

myD[mySum[Subscript[a, i, j] Subscript[x, j], j], Subscript[a, i, k]]

enter image description here

myD[Subscript[x, k] mySum[g[Subscript[a, i, j], 
                            Subscript[x, j]], i, j], Subscript[x, n]]

enter image description here

You can press Ctrl+Shift+t to transform the output to TraditionalForm.

OK, though I've done this many times, given that coding this in Mathematica requires one to have a good enough understanding for the core language, let me do a favor:

Clear[myD, mySum]

myD[a_ b_, c_] := a myD[b, c] + b myD[a, c]
(* Add the rule for addition just in case: *)
myD[a_ + b_, c_] := myD[a, c] + myD[b, c]

myD[mySum[a_, b__], x_] := mySum[myD[a, x], b]

myD[(h_ /; Context[h] =!= "System`")[a__], x_] := 
 With[{l = Length@{a}}, 
  Total@MapThread[
    Derivative[Sequence @@ #][h][a] myD[#2, x] &, {IdentityMatrix@
      l, {a}}]]

myD[Subscript[a_, i___, j1_, k___], Subscript[a_, i___, j2_, k___]] :=
  KroneckerDelta[j1, j2]

myD[Subscript[a_, __], Subscript[b_, __]] := 0

mySum[KroneckerDelta@OrderlessPatternSequence[i_, j_] expr_, jL___, 
  j_, jR___] := mySum[expr /. j -> i, jL, jR]

mySum[a_] := a

FormatValues@mySum = {};

MakeBoxes[mySum[a__], fmt_] ^:= 
 With[{funcbody = 
    MakeBoxes[Sum[a], fmt] /. Thread[{a} -> (Slot /@ Length@{a})]}, 
  TemplateBox[MakeBoxes[#, fmt] & /@ {a}, "mySum", 
   DisplayFunction -> (funcbody &)]]

Usage:

myD[mySum[Subscript[a, i, j] Subscript[x, j], j], Subscript[a, i, k]]

enter image description here

myD[Subscript[x, k] mySum[g[Subscript[a, i, j], 
                            Subscript[x, j]], i, j], Subscript[x, n]]

enter image description here

You can press Ctrl+Shift+t to transform the output to TraditionalForm.

Source Link
xzczd
  • 68.4k
  • 9
  • 174
  • 489
Loading