0

During use of sub-scripted variables, I came across the following issue

Dt[Subscript[x,0]]

gives

output

  1. Why is mathematica treating x and not x$_0$ as the variable?
  2. What is (1,0) Subscript$^{(1,0)}$ ?
  3. Later I wanted to TagSet Dt[x$_0$] to dx$_0$ (Dt[x$_0$] appears as part of some other expression). But because of the above, a tagset on x$_0$ doesn't work
lineage
  • 1,144
  • 4
  • 10

2 Answers2

1

You can modify the system options to exclude Subscript from being differentiated. The relevant option:

SystemOptions["DifferentiationOptions"->"ExcludedFunctions"]

{"DifferentiationOptions" -> {"ExcludedFunctions" -> {Hold, HoldComplete, Less, LessEqual, Greater, GreaterEqual, Inequality, Unequal, Nand, Nor, Xor, Not, Element, Exists, ForAll, Implies, Positive, Negative, NonPositive, NonNegative, Replace, ReplaceAll, ReplaceRepeated}}}

Adding Subscript:

With[
    {
    new = Append[Subscript] @ OptionValue[
        SystemOptions["DifferentiationOptions"->"ExcludedFunctions"],
        "DifferentiationOptions"->"ExcludedFunctions"
    ]
    },
    SetSystemOptions["DifferentiationOptions" -> "ExcludedFunctions" -> new]
];

Then, Dt will no longer try to differentiate your subscripted variable:

Dt[Subscript[x, 0]]

Dt[Subscript[x, 0]]

Carl Woll
  • 130,679
  • 6
  • 243
  • 355
  • Is this a responsible answer in your opinion Carl? If newcomers (who often tend to always use Subscript in the non-indended way) search and see this answer, don't you think you are doing them a disservice? – Marius Ladegård Meyer Aug 31 '19 at 12:39
  • Also, this answer does not in fact answer either questions 1 or 2. ("Question" 3 is not actually a question). – Marius Ladegård Meyer Aug 31 '19 at 12:40
0

The total differential Dt[f[x,0]] is Dt[x]f^(1,0)[x,0], or in InputForm,

Dt[x]*Derivative[1, 0][f][x, 0]

The two variable function Subscript[x,y] is being treated no differently to any other two variable function f[x,y]. In particular, the (1,0) superscript means 1st derivative w.r.t. first variable.

For a while I have been using the following to define subscripted (or other composite) variables that can be copy-pasted and entered in formatted form, but I'm not sure how robust this is:

FormatSymbol[var_, rep_String] := Module[{b, s1, s2},
  b = ToString[FullForm[Apply[MakeBoxes, MakeExpression[rep, StandardForm]]]];
  s1 = SymbolName[var] <> "/:MakeBoxes[" <> SymbolName[var] <> ",StandardForm]:=" <> b;
  ToExpression[s1];
  s2 = "MakeExpression[" <> b <> ",StandardForm]:=HoldComplete[" <> SymbolName[var] <> "]";
  ToExpression[s2];
  Column[{s1, s2}]
] 

Usage example:

FormatSymbol[ x0, "xsub0" ]; 

where xsub0 is supposed to be typed as x subscripted with 0 (i.e., x Ctrl_ 0 , but I can't type that here).

To clear the above formatting of symbol x0,

UnformatSymbol[ x0 ];

where

UnformatSymbol[var_] := Module[{b, s1, s2},
  b = ToString[FullForm[MakeBoxes[var // DisplayForm][[1]]]];
  s1 = SymbolName[var] <> "/:MakeBoxes[" <> SymbolName[var] <> ",StandardForm]=.";
  ToExpression[s1];
  s2 = "MakeExpression[" <> b <> ",StandardForm]=.";
  ToExpression[s2];
  Column[{s1, s2}]
]

The return values for the above functions are, of course, just to see what's going on.

Andrew Norton
  • 847
  • 4
  • 13
  • Why do you use strings? Just use something like fs[v_, d_]:=With[{boxes = MakeBoxes[d, StandardForm]}, v/:MakeBoxes[v, StandardForm]:=boxes; MakeExpression[boxes, StandardForm]:=HoldComplete[v] ] – Carl Woll Aug 28 '19 at 16:27